Exemplo n.º 1
0
 /// <summary>
 /// Clear shared object.
 /// </summary>
 public void Clear()
 {
     _events.Clear();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Send update notification over data channel of RTMP connection
        /// </summary>
		private void SendUpdates() 
		{
            int currentVersion = _version.Value;
            bool persist = this.IsPersistentObject;
            //Get read-only version of events
            ConcurrentLinkedQueue<ISharedObjectEvent> events = new ConcurrentLinkedQueue<ISharedObjectEvent>(_ownerMessage.Events);
            //clear out previous events
            _ownerMessage.Events.Clear();

            if (events.Count != 0) 
			{
                //Send update to "owner" of this update request
				if(_source != null) 
				{
                    RtmpConnection connection = _source as RtmpConnection;
					// Only send updates when issued through RTMP request
                    RtmpChannel channel = connection.GetChannel((byte)3);

                    // Send update to "owner" of this update request
                    SharedObjectMessage syncOwner;
                    if (connection.ObjectEncoding == ObjectEncoding.AMF0)
                        syncOwner = new SharedObjectMessage(null, _name, currentVersion, persist);
                    else
                        syncOwner = new FlexSharedObjectMessage(null, _name, currentVersion, persist);
                    syncOwner.AddEvents(events);

					if(channel != null) 
					{
						channel.Write(syncOwner);
					} 
					else 
					{
						log.Warn(__Res.GetString(__Res.Channel_NotFound));
					}
				}
			}
            //Clear owner events
            events.Clear();
            //Get read-only version of sync events
            events.AddRange(_syncEvents);
            //Clear out previous events
            _syncEvents.Clear();
            if (events.Count != 0) 
			{
				// Synchronize updates with all registered clients of this shared
				foreach(IEventListener listener in _listeners) 
				{
					if(listener == _source) 
					{
						// Don't re-send update to active client
						continue;
					}
					if(!(listener is RtmpConnection))
					{
						log.Warn(__Res.GetString(__Res.SharedObject_SyncConnError));
						continue;
					}
					// Create a new sync message for every client to avoid
					// concurrent access through multiple threads
					// TODO: perhaps we could cache the generated message
                    RtmpConnection connection = listener as RtmpConnection;
                    SharedObjectMessage syncMessage;
                    if (connection.ObjectEncoding == ObjectEncoding.AMF0)
                        syncMessage = new SharedObjectMessage(null, _name, currentVersion, persist);
                    else
                        syncMessage = new FlexSharedObjectMessage(null, _name, currentVersion, persist);
                    syncMessage.AddEvents(events);

                    RtmpChannel channel = connection.GetChannel((byte)3);
					log.Debug(__Res.GetString(__Res.SharedObject_Sync, channel));
					channel.Write(syncMessage);
				}
			}
		}
Exemplo n.º 3
0
        /// <summary>
        /// Send update notification over data channel of RTMP connection
        /// </summary>
        private void SendUpdates()
        {
            int  currentVersion = _version.Value;
            bool persist        = this.IsPersistentObject;
            //Get read-only version of events
            ConcurrentLinkedQueue <ISharedObjectEvent> events = new ConcurrentLinkedQueue <ISharedObjectEvent>(_ownerMessage.Events);

            //clear out previous events
            _ownerMessage.Events.Clear();

            if (events.Count != 0)
            {
                //Send update to "owner" of this update request
                if (_source != null)
                {
                    RtmpConnection connection = _source as RtmpConnection;
                    // Only send updates when issued through RTMP request
                    RtmpChannel channel = connection.GetChannel((byte)3);

                    // Send update to "owner" of this update request
                    SharedObjectMessage syncOwner;
                    if (connection.ObjectEncoding == ObjectEncoding.AMF0)
                    {
                        syncOwner = new SharedObjectMessage(null, _name, currentVersion, persist);
                    }
                    else
                    {
                        syncOwner = new FlexSharedObjectMessage(null, _name, currentVersion, persist);
                    }
                    syncOwner.AddEvents(events);

                    if (channel != null)
                    {
                        channel.Write(syncOwner);
                    }
                    else
                    {
                        log.Warn(__Res.GetString(__Res.Channel_NotFound));
                    }
                }
            }
            //Clear owner events
            events.Clear();
            //Get read-only version of sync events
            events.AddRange(_syncEvents);
            //Clear out previous events
            _syncEvents.Clear();
            if (events.Count != 0)
            {
                // Synchronize updates with all registered clients of this shared
                foreach (IEventListener listener in _listeners)
                {
                    if (listener == _source)
                    {
                        // Don't re-send update to active client
                        continue;
                    }
                    if (!(listener is RtmpConnection))
                    {
                        log.Warn(__Res.GetString(__Res.SharedObject_SyncConnError));
                        continue;
                    }
                    // Create a new sync message for every client to avoid
                    // concurrent access through multiple threads
                    // TODO: perhaps we could cache the generated message
                    RtmpConnection      connection = listener as RtmpConnection;
                    SharedObjectMessage syncMessage;
                    if (connection.ObjectEncoding == ObjectEncoding.AMF0)
                    {
                        syncMessage = new SharedObjectMessage(null, _name, currentVersion, persist);
                    }
                    else
                    {
                        syncMessage = new FlexSharedObjectMessage(null, _name, currentVersion, persist);
                    }
                    syncMessage.AddEvents(events);

                    RtmpChannel channel = connection.GetChannel((byte)3);
                    log.Debug(__Res.GetString(__Res.SharedObject_Sync, channel));
                    channel.Write(syncMessage);
                }
            }
        }
Exemplo n.º 4
0
 public static void clear(this ConcurrentLinkedQueue queue)
 {
     queue.Clear();
 }
Exemplo n.º 5
0
 public static void Clear()
 {
     pool.Clear();
 }
Exemplo n.º 6
0
 public void Reset()
 {
     _messages.Clear();
 }