Ejemplo n.º 1
0
        /// <summary>
        /// Removes scope from the children scope list.
        /// </summary>
        /// <param name="scope">Removes the specified scope.</param>
        public void RemoveChildScope(IBasicScope scope)
        {
            //Synchronize retrieval of the child scope (with removal)
            Monitor.Enter(SyncRoot);
            try
            {
                // Don't remove if reference if we have another one
                if (HasChildScope(scope.Name) && GetScope(scope.Name) != scope)
                {
#if !SILVERLIGHT
                    log.Warn(string.Format("Being asked to remove wrong scope reference child scope is {0} not {1}", GetScope(scope.Name), scope));
#endif
                    return;
                }
#if !SILVERLIGHT
                if (log != null && log.IsDebugEnabled)
                {
                    log.Debug(string.Format("Remove child scope: {0} path: {1}", scope, scope.Path));
                }
#endif
                if (scope is IScope)
                {
                    if (HasHandler)
                    {
                        Handler.Stop((IScope)scope);
                    }
                    _subscopeStats.Decrement();
                }
                string child = scope.Type + Separator + scope.Name;
                if (_children.ContainsKey(child))
                {
                    _children.Remove(child);
                }
            }
            finally
            {
                Monitor.Exit(SyncRoot);
            }

            if (HasHandler)
            {
#if !SILVERLIGHT
                if (log != null && log.IsDebugEnabled)
                {
                    log.Debug("Remove child scope");
                }
#endif
                Handler.RemoveChildScope(scope);
            }
            if (scope is Scope)
            {
                //Chain service containers
                (scope as Scope).ServiceContainer.Container = null;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Pipe connection event handler.
        /// </summary>
        /// <param name="evt">Pipe connection event.</param>
        public void OnPipeConnectionEvent(PipeConnectionEvent evt)
        {
            switch (evt.Type)
            {
            case PipeConnectionEvent.PROVIDER_CONNECT_PUSH:
                if (evt.Provider == this && evt.Source != _connMsgOut && (evt.ParameterMap == null || !evt.ParameterMap.ContainsKey("record")))
                {
                    _livePipe = evt.Source as IPipe;
                    foreach (IConsumer consumer in _livePipe.GetConsumers())
                    {
                        _subscriberStats.Increment();
                    }
                }
                break;

            case PipeConnectionEvent.PROVIDER_DISCONNECT:
                if (_livePipe == evt.Source)
                {
                    _livePipe = null;
                }
                break;

            case PipeConnectionEvent.CONSUMER_CONNECT_PUSH:
                if (_livePipe == evt.Source)
                {
                    NotifyChunkSize();
                }
                _subscriberStats.Increment();
                break;

            case PipeConnectionEvent.CONSUMER_DISCONNECT:
                _subscriberStats.Decrement();
                break;

            default:
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Disconnects the specified connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        public void Disconnect(IConnection connection)
        {
            // We call the disconnect handlers in reverse order they were called during connection, i.e. roomDisconnect is called before appDisconnect.
            IClient client = connection.Client;

            if (client == null)
            {
                // Early bail out
                RemoveEventListener(connection);
                _connectionStats.Decrement();
                if (HasParent)
                {
                    Parent.Disconnect(connection);
                }
                return;
            }

            if (_clients.ContainsKey(client))
            {
                CopyOnWriteArraySet <IConnection> connections = _clients[client];
                connections.Remove(connection);
                IScopeHandler handler = null;
                if (HasHandler)
                {
                    handler = Handler;
                    try
                    {
                        handler.Disconnect(connection, this);
                    }
                    catch (Exception ex)
                    {
#if !SILVERLIGHT
                        if (log != null && log.IsErrorEnabled)
                        {
                            log.Error("Error while executing \"disconnect\" for connection " + connection + " on handler " + handler, ex);
                        }
#endif
                    }
                }

                if (connections.Count == 0)
                {
                    _clients.Remove(client);
                    _clientStats.Decrement();
                    if (handler != null)
                    {
                        try
                        {
                            // there may be a timeout here ?
                            handler.Leave(client, this);
                        }
                        catch (Exception ex)
                        {
#if !SILVERLIGHT
                            if (log != null && log.IsErrorEnabled)
                            {
                                log.Error("Error while executing \"leave\" for client " + client + " on handler " + handler, ex);
                            }
#endif
                        }
                    }
                }
                RemoveEventListener(connection);
                _connectionStats.Decrement();
            }
            if (HasParent)
            {
                Parent.Disconnect(connection);
            }
        }