public void Disconnect(NamedConnection namedConnection) { NamedConnection old; if (_allConnections.TryRemove(namedConnection.ClientId, out old)) { old.Connection.Disconnect(); } }
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(); } }
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); }
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)); } }
public PingReceived(MqttCommand cmd, NamedConnection connection) { _command = cmd; _connection = connection; }
public SubscribeReceive(MqttCommand cmd, NamedConnection connection) { _command = cmd; _connection = connection; }
public PublishReceive(MqttCommand cmd, NamedConnection connection) { _command = cmd; _connection = connection; }