예제 #1
0
 public void Disconnect(NamedConnection namedConnection)
 {
     NamedConnection old;
     if (_allConnections.TryRemove(namedConnection.ClientId, out old))
     {
         old.Connection.Disconnect();
     }
 }
예제 #2
0
        public void Disconnect(NamedConnection namedConnection)
        {
            NamedConnection old;

            if (_allConnections.TryRemove(namedConnection.ClientId, out old))
            {
                old.Connection.Disconnect();
            }
        }
예제 #3
0
 private void QueueReadCommand(NamedConnection connection)
 {
     lock (_lock)
     {
         _runningCommands.Add(Task.Factory.StartNew <CommandRead>(() =>
         {
             ICommandReader reader = new CommandReader();
             MqttCommand cmd       = reader.Read(connection.Connection);
             return(new CommandRead(cmd, connection));
         }, TaskCreationOptions.LongRunning));
     }
 }
예제 #4
0
        void IActiveConnectionManager.Register(NamedConnection connection)
        {
            lock (_lock)
            {
                connection.Manager = this;

                // maybe an existing known connection
                Disconnect(connection);

                // maybe still in new connections queue
                NamedConnection existing = _newConnections.Where(c => c.ClientId == connection.ClientId).FirstOrDefault();
                if (existing != null)
                {
                    Disconnect(existing);
                }

                _newConnections.Add(connection);
                _allConnections.AddOrUpdate(connection.ClientId, connection, (id, old) => connection);

                _itemAdded.Set();
            }
        }
예제 #5
0
        protected Task WaitFor(NamedConnection connection, ushort messageId, CommandMessage mustBeType)
        {
            ManualResetEvent available = new ManualResetEvent(false);

            Action<MqttCommand> ready = (cmd) =>
                {
                    if (cmd.CommandMessage != mustBeType)
                    {
                        throw new ProtocolException(
                            string.Format("ERROR: Expected {0} for message ID {1} but received {2}",
                            mustBeType, messageId, cmd.CommandMessage));
                    }

                    available.Set();
                };

            return Task.Factory.StartNew(() =>
                {
                    connection.Desire(messageId, ready);
                    available.WaitOne();
                }, TaskCreationOptions.LongRunning);
        }
예제 #6
0
        void IActiveConnectionManager.Register(NamedConnection connection)
        {
            lock (_lock)
            {
                connection.Manager = this;

                // maybe an existing known connection
                Disconnect(connection);

                // maybe still in new connections queue
                NamedConnection existing = _newConnections.Where(c => c.ClientId == connection.ClientId).FirstOrDefault();
                if (existing != null)
                {
                    Disconnect(existing);
                }

                _newConnections.Add(connection);
                _allConnections.AddOrUpdate(connection.ClientId, connection, (id, old) => connection);

                _itemAdded.Set();
            }
        }
예제 #7
0
 public CommandRead(MqttCommand command, NamedConnection connection)
 {
     Command = command;
     Connection = connection;
 }
예제 #8
0
 private void QueueReadCommand(NamedConnection connection)
 {
     lock (_lock)
     {
         _runningCommands.Add(Task.Factory.StartNew<CommandRead>(() =>
                 {
                     ICommandReader reader = new CommandReader();
                     MqttCommand cmd = reader.Read(connection.Connection);
                     return new CommandRead(cmd, connection);
                 }, TaskCreationOptions.LongRunning));
     }
 }
예제 #9
0
 public PingReceived(MqttCommand cmd, NamedConnection connection)
 {
     _command = cmd;
     _connection = connection;
 }
예제 #10
0
 public SubscribeReceive(MqttCommand cmd, NamedConnection connection)
 {
     _command = cmd;
     _connection = connection;
 }
예제 #11
0
 public PublishReceive(MqttCommand cmd, NamedConnection connection)
 {
     _command = cmd;
     _connection = connection;
 }
예제 #12
0
 public CommandRead(MqttCommand command, NamedConnection connection)
 {
     Command    = command;
     Connection = connection;
 }