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

            if (_allConnections.TryRemove(namedConnection.ClientId, out old))
            {
                old.Connection.Disconnect();
            }
        }
Exemple #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));
     }
 }
        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();
            }
        }
Exemple #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);
        }
Exemple #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();
            }
        }
 public CommandRead(MqttCommand command, NamedConnection connection)
 {
     Command = command;
     Connection = connection;
 }
 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));
     }
 }
Exemple #9
0
 public PingReceived(MqttCommand cmd, NamedConnection connection)
 {
     _command = cmd;
     _connection = connection;
 }
Exemple #10
0
 public SubscribeReceive(MqttCommand cmd, NamedConnection connection)
 {
     _command = cmd;
     _connection = connection;
 }
Exemple #11
0
 public PublishReceive(MqttCommand cmd, NamedConnection connection)
 {
     _command = cmd;
     _connection = connection;
 }
Exemple #12
0
 public CommandRead(MqttCommand command, NamedConnection connection)
 {
     Command    = command;
     Connection = connection;
 }