Photon Server API
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Properties | List of all members
Photon.Hive.Room Class Reference

A room has Actors, can have properties, and provides an ExecutionFiber with a few wrapper methods to solve otherwise complicated threading issues: All actions enqueued to the ExecutionFiber are executed in a serial order. Operations of all Actors in a room are handled via ExecutionFiber. More...

Inheritance diagram for Photon.Hive.Room:
Photon.Hive.HiveGame Photon.Hive.HiveHostGame Photon.Hive.Tests.TestGame Photon.LoadBalancing.GameServer.Game Photon.LoadBalancing.UnitTests.UnifiedServer.OfflineExtra.TestGame

Classes

class  DefaultGameStateFactory
 

Public Member Functions

 Room (string name, RoomCacheBase roomCache=null, IGameStateFactory gameStateFactory=null, int maxEmptyRoomTTL=0, ExtendedPoolFiber executionFiber=null)
 Initializes a new instance of the Room class without a room name. More...
 
override string ToString ()
 
virtual bool BeforeRemoveFromCache ()
 Called by the RoomCacheBase if the room is about to be removed from the cache. More...
 
void EnqueueMessage (IMessage message)
 Enqueues an IMessage to the end of the execution queue. More...
 
void EnqueueOperation (HivePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
 Enqueues an OperationRequest to the end of the execution queue. More...
 
IDisposable ScheduleMessage (IMessage message, long timeMs)
 Schedules a message to be processed after a specified time. More...
 
void Dispose ()
 Releases resources used by this instance. More...
 
virtual void OnClose ()
 
void Release ()
 

Protected Types

enum  RemoveState {
  RemoveState.Alive, RemoveState.TryRemoveRoomFromCacheCalled, RemoveState.RoomRemoved, RemoveState.TryRemoveRoomFromCacheCalledRoomNotRemoved,
  RemoveState.ProcessCloseGameCalled, RemoveState.TriggerPluginOnCloseCalled, RemoveState.AliveGotNewPlayer, RemoveState.ScheduleTriggerPluginOnCloseCalled,
  RemoveState.ProcessBeforeCloseGameCalled, RemoveState.ProcessBeforeCloseGameCalledEmptyRoomLiveTimeLECalled, RemoveState.BeforeRemoveFromCacheCalled, RemoveState.BeforeRemoveFromCacheActionCalled,
  RemoveState.GameDisposeCalled
}
 

Protected Member Functions

 Room (string name, ExtendedPoolFiber executionFiber, RoomCacheBase roomCache, IGameStateFactory gameStateFactory=null, int maxEmptyRoomTTL=0)
 Initializes a new instance of the Room class. More...
 
virtual void Dispose (bool dispose)
 Releases unmanaged and - optionally - managed resources More...
 
virtual void ExecuteOperation (HivePeer peer, OperationRequest operation, SendParameters sendParameters)
 This method is invoked sequentially for each operation request enqueued in the ExecutionFiber using the EnqueueOperation method. More...
 
virtual void ProcessMessage (IMessage message)
 This method is invoked sequentially for each message enqueued by the EnqueueMessage or ScheduleMessage method. More...
 
void PublishEvent (HiveEventBase e, Actor actor, SendParameters sendParameters)
 Publishes an event to a single actor on a specified channel. More...
 
void PublishEvent (HiveEventBase e, IEnumerable< Actor > actorList, SendParameters sendParameters)
 Publishes an event to a list of actors on a specified channel. More...
 
void PublishEvent (EventData e, IEnumerable< Actor > actorList, SendParameters sendParameters)
 Publishes an event to a list of actors on a specified channel. More...
 
void ScheduleRoomRemoval (int roomLiveTime)
 Schedules the removal of the room instance from the cache. The room will be removed after the specified time if there are no room references left. More...
 
void TryRemoveRoomFromCache ()
 Removes the room instance from the cache if there are no references to the instance left. More...
 

Protected Attributes

readonly RoomCacheBase roomCache
 
readonly IGameStateFactory gameStateFactory
 
string RemoveRoomPathString
 
GameState roomState
 

Properties

RemoveState RemoveRoomPath [get, set]
 
ExtendedPoolFiber ExecutionFiber [get]
 Gets a PoolFiber instance used to synchronize access to this instance. More...
 
bool IsDisposed [get]
 Gets a value indicating whether IsDisposed. More...
 
string Name [get]
 Gets the name (id) of the room. More...
 
int EmptyRoomLiveTime [get, protected set]
 Gets or sets a value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room. More...
 
int MaxEmptyRoomTTL [get]
 
IDisposable RemoveTimer [get, set]
 Timer for removing room More...
 
PropertyBag< object > Properties [get]
 Gets a PropertyBag instance used to store custom room properties. More...
 

Detailed Description

A room has Actors, can have properties, and provides an ExecutionFiber with a few wrapper methods to solve otherwise complicated threading issues: All actions enqueued to the ExecutionFiber are executed in a serial order. Operations of all Actors in a room are handled via ExecutionFiber.

Member Enumeration Documentation

enum Photon.Hive.Room.RemoveState
strongprotected
Enumerator
Alive 
TryRemoveRoomFromCacheCalled 
RoomRemoved 
TryRemoveRoomFromCacheCalledRoomNotRemoved 
ProcessCloseGameCalled 
TriggerPluginOnCloseCalled 
AliveGotNewPlayer 
ScheduleTriggerPluginOnCloseCalled 
ProcessBeforeCloseGameCalled 
ProcessBeforeCloseGameCalledEmptyRoomLiveTimeLECalled 
BeforeRemoveFromCacheCalled 
BeforeRemoveFromCacheActionCalled 
GameDisposeCalled 

Constructor & Destructor Documentation

Photon.Hive.Room.Room ( string  name,
RoomCacheBase  roomCache = null,
IGameStateFactory  gameStateFactory = null,
int  maxEmptyRoomTTL = 0,
ExtendedPoolFiber  executionFiber = null 
)
inline

Initializes a new instance of the Room class without a room name.

Parameters
nameThe room name.
roomCacheThe RoomCacheBase instance to which the room belongs.
gameStateFactoryFatory for game state
maxEmptyRoomTTLA value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room.
executionFiberFiber which will execute rooms actions
Photon.Hive.Room.Room ( string  name,
ExtendedPoolFiber  executionFiber,
RoomCacheBase  roomCache,
IGameStateFactory  gameStateFactory = null,
int  maxEmptyRoomTTL = 0 
)
inlineprotected

Initializes a new instance of the Room class.

Parameters
nameThe room name.
executionFiberThe execution fiber used to synchronize access to this instance.
roomCacheThe RoomCacheBase instance to which the room belongs.
gameStateFactoryFatory for game state
maxEmptyRoomTTLA value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room.

Member Function Documentation

virtual bool Photon.Hive.Room.BeforeRemoveFromCache ( )
inlinevirtual

Called by the RoomCacheBase if the room is about to be removed from the cache.

Returns
True if the room should be automaticly by removed by the RoomCacheBase. False if the room has an custom remove implementation and will remove itself from the cache.

The default implementation checks if the EmptyRoomLiveTime value is set to a value greater zero. If it's set the method will return false to indicate that the cache should not remove this instance automaticly. The removal of the room is then scheduled using the ExecutionFiber.

Reimplemented in Photon.Hive.HiveHostGame.

void Photon.Hive.Room.Dispose ( )
inline

Releases resources used by this instance.

virtual void Photon.Hive.Room.Dispose ( bool  dispose)
inlineprotectedvirtual

Releases unmanaged and - optionally - managed resources

Parameters
disposetrue to release both managed and unmanaged resources; false to release only unmanaged resources.

Reimplemented in Photon.Hive.Tests.TestGame, and Photon.LoadBalancing.GameServer.Game.

void Photon.Hive.Room.EnqueueMessage ( IMessage  message)
inline

Enqueues an IMessage to the end of the execution queue.

Parameters
messageThe message to enqueue.

ProcessMessage is called sequentially for each operation request stored in the execution queue. Using an execution queue ensures that messages are processed in order and sequentially to prevent object synchronization (multi threading).

void Photon.Hive.Room.EnqueueOperation ( HivePeer  peer,
OperationRequest  operationRequest,
SendParameters  sendParameters 
)
inline

Enqueues an OperationRequest to the end of the execution queue.

Parameters
peerThe peer.
operationRequestThe operation request to enqueue.
sendParametersThe send Parameters.

ExecuteOperation is called sequentially for each operation request stored in the execution queue. Using an execution queue ensures that operation request are processed in order and sequentially to prevent object synchronization (multi threading).

virtual void Photon.Hive.Room.ExecuteOperation ( HivePeer  peer,
OperationRequest  operation,
SendParameters  sendParameters 
)
inlineprotectedvirtual

This method is invoked sequentially for each operation request enqueued in the ExecutionFiber using the EnqueueOperation method.

Parameters
peerThe peer.
operationThe operation request.
sendParametersThe send Parameters.

Reimplemented in Photon.Hive.HiveGame, and Photon.LoadBalancing.GameServer.Game.

virtual void Photon.Hive.Room.OnClose ( )
inlinevirtual
virtual void Photon.Hive.Room.ProcessMessage ( IMessage  message)
inlineprotectedvirtual

This method is invoked sequentially for each message enqueued by the EnqueueMessage or ScheduleMessage method.

Parameters
messageThe message to process.

Reimplemented in Photon.Hive.HiveGame.

void Photon.Hive.Room.PublishEvent ( HiveEventBase  e,
Actor  actor,
SendParameters  sendParameters 
)
inlineprotected

Publishes an event to a single actor on a specified channel.

Parameters
eThe event to publish.
actorThe Actor who should receive the event.
sendParametersThe send Parameters.
void Photon.Hive.Room.PublishEvent ( HiveEventBase  e,
IEnumerable< Actor actorList,
SendParameters  sendParameters 
)
inlineprotected

Publishes an event to a list of actors on a specified channel.

Parameters
eThe event to publish.
actorListA list of Actor who should receive the event.
sendParametersThe send Parameters.
void Photon.Hive.Room.PublishEvent ( EventData  e,
IEnumerable< Actor actorList,
SendParameters  sendParameters 
)
inlineprotected

Publishes an event to a list of actors on a specified channel.

Parameters
eThe event to publish.
actorListA list of Actor who should receive the event.
sendParametersThe send Parameters.
void Photon.Hive.Room.Release ( )
inline
IDisposable Photon.Hive.Room.ScheduleMessage ( IMessage  message,
long  timeMs 
)
inline

Schedules a message to be processed after a specified time.

Parameters
messageThe message to schedule.
timeMsThe time in milliseconds to wait before the message will be processed.
Returns
an IDisposable
void Photon.Hive.Room.ScheduleRoomRemoval ( int  roomLiveTime)
inlineprotected

Schedules the removal of the room instance from the cache. The room will be removed after the specified time if there are no room references left.

Parameters
roomLiveTimeThe time to remove the room in milliseconds.
override string Photon.Hive.Room.ToString ( )
inline
void Photon.Hive.Room.TryRemoveRoomFromCache ( )
inlineprotected

Removes the room instance from the cache if there are no references to the instance left.

Member Data Documentation

readonly IGameStateFactory Photon.Hive.Room.gameStateFactory
protected
string Photon.Hive.Room.RemoveRoomPathString
protected
readonly RoomCacheBase Photon.Hive.Room.roomCache
protected
GameState Photon.Hive.Room.roomState
protected

Property Documentation

int Photon.Hive.Room.EmptyRoomLiveTime
getprotected set

Gets or sets a value indicating how long the room instance will be keeped alive in the room cache after all peers have left the room.

ExtendedPoolFiber Photon.Hive.Room.ExecutionFiber
get

Gets a PoolFiber instance used to synchronize access to this instance.

A PoolFiber instance.

bool Photon.Hive.Room.IsDisposed
get

Gets a value indicating whether IsDisposed.

int Photon.Hive.Room.MaxEmptyRoomTTL
get
string Photon.Hive.Room.Name
get

Gets the name (id) of the room.

PropertyBag<object> Photon.Hive.Room.Properties
get

Gets a PropertyBag instance used to store custom room properties.

RemoveState Photon.Hive.Room.RemoveRoomPath
getsetprotected
IDisposable Photon.Hive.Room.RemoveTimer
getsetprotected

Timer for removing room