Photon Server API Documentation v5.0RC1

Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Photon.Hive.Caching.RoomCacheBase Class Referenceabstract

Base class for room caches. More...

Inheritance diagram for Photon.Hive.Caching.RoomCacheBase:
Photon.Hive.Caching.HiveGameCache Photon.LoadBalancing.GameServer.GameCache

Classes

class  RoomInstance
 Used to track references for a room instance. More...
 

Public Member Functions

bool TryGetRoomWithoutReference (string roomId, out Room room)
 Tries to get room reference for a room with the specified id, without holding a reference to that room. More...
 
RoomReference GetRoomReference (string roomName, PeerBase ownerPeer, params object[] args)
 Gets a room reference for a room with a specified id. If the room with the specified id does not exist, a new room will be created. More...
 
List< string > GetRoomNames ()
 Returns the names of all rooms that are currently cached in this RoomCacheBase. More...
 
int GetCount ()
 Returns amount games in cache More...
 
virtual string GetDebugString (string roomName)
 Gathers debug information about the specified room (actors, peers, references etc.). More...
 
bool TryCreateRoom (string roomName, PeerBase ownerPeer, out RoomReference roomReference, params object[] args)
 Tries to create a new room. More...
 
bool TryGetRoomReference (string roomId, PeerBase ownerPeer, out RoomReference roomReference)
 Tries to get room reference for a room with the specified id. More...
 
void ReleaseRoomReference (RoomReference roomReference)
 Releases a room reference. The related room instance will be removed from the cache if no more references to the room exists. More...
 
bool TryRemoveRoomInstance (Room room)
 Tries to remove a room instance from the room cache. The room will only be removed if there are no references to the room instance left. More...
 

Protected Member Functions

abstract Room CreateRoom (string roomId, params object[] args)
 Must be implemented by inheritors to create new room instances. This method is called when a room reference is requested for a room that does not exist in the cache. More...
 
virtual void OnRoomRemoved (Room room)
 Invoked if the last reference for a room is released and the room was removed from the cache. Can be overloaded by inheritors to provide a custom cleanup logic after a room has been disposed. More...
 

Protected Attributes

readonly Dictionary< string, RoomInstanceRoomInstances = new Dictionary<string, RoomInstance>()
 A Dictionary used to store room instances. More...
 
readonly object SyncRoot = new object()
 used to synchronize access to the cache. More...
 

Detailed Description

Base class for room caches.

Member Function Documentation

◆ CreateRoom()

abstract Room Photon.Hive.Caching.RoomCacheBase.CreateRoom ( string  roomId,
params object[]  args 
)
protectedpure virtual

Must be implemented by inheritors to create new room instances. This method is called when a room reference is requested for a room that does not exist in the cache.

Parameters
roomIdThe room id.
argsOptionally arguments used for room creation.
Returns
a new room

Implemented in Photon.Hive.Caching.HiveGameCache, and Photon.LoadBalancing.GameServer.GameCache.

◆ GetCount()

int Photon.Hive.Caching.RoomCacheBase.GetCount ( )
inline

Returns amount games in cache

Returns

◆ GetDebugString()

virtual string Photon.Hive.Caching.RoomCacheBase.GetDebugString ( string  roomName)
inlinevirtual

Gathers debug information about the specified room (actors, peers, references etc.).

Parameters
roomNameThe room name.
Returns
A string with debug information.

◆ GetRoomNames()

List<string> Photon.Hive.Caching.RoomCacheBase.GetRoomNames ( )
inline

Returns the names of all rooms that are currently cached in this RoomCacheBase.

Returns
The list of room names.

◆ GetRoomReference()

RoomReference Photon.Hive.Caching.RoomCacheBase.GetRoomReference ( string  roomName,
PeerBase  ownerPeer,
params object[]  args 
)
inline

Gets a room reference for a room with a specified id. If the room with the specified id does not exist, a new room will be created.

Parameters
roomNameThe room id.
ownerPeerThe peer that holds this reference.
argsOptionally arguments used for room creation.
Returns
a RoomReference

◆ OnRoomRemoved()

virtual void Photon.Hive.Caching.RoomCacheBase.OnRoomRemoved ( Room  room)
inlineprotectedvirtual

Invoked if the last reference for a room is released and the room was removed from the cache. Can be overloaded by inheritors to provide a custom cleanup logic after a room has been disposed.

Parameters
roomThe Room that was removed from the cache.

◆ ReleaseRoomReference()

void Photon.Hive.Caching.RoomCacheBase.ReleaseRoomReference ( RoomReference  roomReference)
inline

Releases a room reference. The related room instance will be removed from the cache if no more references to the room exists.

Parameters
roomReferenceThe room reference to release.

◆ TryCreateRoom()

bool Photon.Hive.Caching.RoomCacheBase.TryCreateRoom ( string  roomName,
PeerBase  ownerPeer,
out RoomReference  roomReference,
params object[]  args 
)
inline

Tries to create a new room.

Parameters
roomNameThe room id.
ownerPeerThe peer that holds this reference.
roomReferenceWhen this method returns true, contains a new RoomReference for the room with the specified room id; otherwise, set to null.
argsOptionally arguments used for room creation.
Returns
False if the cache contains a room with the specified room id; otherwise, true.

◆ TryGetRoomReference()

bool Photon.Hive.Caching.RoomCacheBase.TryGetRoomReference ( string  roomId,
PeerBase  ownerPeer,
out RoomReference  roomReference 
)
inline

Tries to get room reference for a room with the specified id.

Parameters
roomIdThe room id.
ownerPeerThe peer that holds this reference.
roomReferenceWhen this method returns true, contains a new RoomReference for the room with the specified room id; otherwise, set to null.
Returns
True if the cache contains a room with the specified room id; otherwise, false.

◆ TryGetRoomWithoutReference()

bool Photon.Hive.Caching.RoomCacheBase.TryGetRoomWithoutReference ( string  roomId,
out Room  room 
)
inline

Tries to get room reference for a room with the specified id, without holding a reference to that room.

Parameters
roomIdThe room id.
roomThe room, in case it exists.
Returns
True if the cache contains a room with the specified room id; otherwise, false.

◆ TryRemoveRoomInstance()

bool Photon.Hive.Caching.RoomCacheBase.TryRemoveRoomInstance ( Room  room)
inline

Tries to remove a room instance from the room cache. The room will only be removed if there are no references to the room instance left.

Parameters
roomThe room to remove.
Returns
Returns true if the room was removed from the cache; otherwise false.

Member Data Documentation

◆ RoomInstances

readonly Dictionary<string, RoomInstance> Photon.Hive.Caching.RoomCacheBase.RoomInstances = new Dictionary<string, RoomInstance>()
protected

A Dictionary used to store room instances.

◆ SyncRoot

readonly object Photon.Hive.Caching.RoomCacheBase.SyncRoot = new object()
protected

used to synchronize access to the cache.