Beispiel #1
0
            public RoomReference AddReference(PeerBase ownerPeer)
            {
                var reference = new RoomReference(_roomFactory, Room, ownerPeer);

                _references.Add(reference.Id, reference);

                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat(
                        "Created room instance reference: roomName={0}, referenceCount={1}",
                        Room.Name,
                        ReferenceCount);
                }

                if (_logQueue.Log.IsDebugEnabled)
                {
                    _logQueue.Add(
                        new LogEntry(
                            "AddReference",
                            string.Format(
                                "RoomName={0}, ReferenceCount={1}, OwnerPeer={2}",
                                Room.Name,
                                ReferenceCount,
                                ownerPeer)));
                }

                return(reference);
            }
Beispiel #2
0
        public bool TryGetRoomReference(string roomId, PeerBase ownerPeer, out RoomReference roomReference)
        {
            lock (SyncRoot)
            {
                RoomInstance roomInstance;
                if (!RoomInstances.TryGetValue(roomId, out roomInstance))
                {
                    roomReference = null;
                    return(false);
                }

                roomReference = roomInstance.AddReference(ownerPeer);
                return(true);
            }
        }
Beispiel #3
0
        public void ReleaseRoomReference(RoomReference roomReference)
        {
            Room room;

            lock (SyncRoot)
            {
                RoomInstance roomInstance;
                if (!RoomInstances.TryGetValue(roomReference.Room.Name, out roomInstance))
                {
                    return;
                }

                roomInstance.ReleaseReference(roomReference);

                // if there are still references to the room left
                // the room stays into the cache
                if (roomInstance.ReferenceCount > 0)
                {
                    return;
                }

                // ask the room implementation if the room should be
                // removed automaticly from the cache
                var shouldRemoveRoom = roomInstance.Room.BeforeRemoveFromCache();
                if (shouldRemoveRoom == false)
                {
                    return;
                }

                RoomInstances.Remove(roomInstance.Room.Name);
                room = roomInstance.Room;
            }

            if (room == null)
            {
                // the room hast not been removed from the cache
                return;
            }

            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("Removed room instance: roomId={0}", room.Name);
            }

            room.Dispose();
            OnRoomRemoved(room);
        }
Beispiel #4
0
        public bool TryCreateRoom(
            string roomName,
            PeerBase ownerPeer,
            out RoomReference roomReference,
            params object[] args)
        {
            lock (SyncRoot)
            {
                if (RoomInstances.ContainsKey(roomName))
                {
                    roomReference = null;
                    return(false);
                }

                var room         = CreateRoom(roomName, args);
                var roomInstance = new RoomInstance(this, room);
                RoomInstances.Add(roomName, roomInstance);
                roomReference = roomInstance.AddReference(ownerPeer);
                return(true);
            }
        }
Beispiel #5
0
            public void ReleaseReference(RoomReference reference)
            {
                _references.Remove(reference.Id);

                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat(
                        "Removed room instance reference: roomName={0}, referenceCount={1}",
                        Room.Name,
                        ReferenceCount);
                }

                if (_logQueue.Log.IsDebugEnabled)
                {
                    _logQueue.Add(
                        new LogEntry(
                            "ReleaseReference",
                            string.Format(
                                "RoomName={0}, ReferenceCount={1}, OwnerPeer={2}",
                                Room.Name,
                                ReferenceCount,
                                reference.OwnerPeer)));
                }
            }