Akka.Interfaced.SlimSocket.Server.TcpGateway.EstablishChannel C# (CSharp) Метод

EstablishChannel() приватный Метод

private EstablishChannel ( string token, TcpConnection connection ) : bool
token string
connection TcpConnection
Результат bool
        internal bool EstablishChannel(string token, TcpConnection connection)
        {
            WaitingItem item;

            lock (_waitingMap)
            {
                if (_waitingMap.TryGetValue(token, out item) == false)
                    return false;

                _waitingMap.Remove(token);
            }

            _self.Tell(new AcceptByTokenMessage(connection, item.Tag, item.BindingActor), _self);
            return true;
        }

Usage Example

        protected void OnConnectionReceive(TcpConnection connection, object packet)
        {
            _connection.Closed   -= OnConnectionClose;
            _connection.Received -= OnConnectionReceive;

            try
            {
                // Before token is validated

                var p = packet as Packet;
                if (p == null)
                {
                    _eventStream.Publish(new Warning(
                                             _self.Path.ToString(), GetType(),
                                             $"Receives null packet from {_connection?.RemoteEndPoint}"));
                    return;
                }

                if (p.Type != PacketType.System || (p.Message is string) == false)
                {
                    _eventStream.Publish(new Warning(
                                             _self.Path.ToString(), GetType(),
                                             $"Receives a bad packet without a message from {_connection?.RemoteEndPoint}"));
                    return;
                }

                // Try to open

                var token     = (string)p.Message;
                var succeeded = _gateway.EstablishChannel(token, _connection);
                if (succeeded)
                {
                    // set null to avoid closing connection in PostStop
                    _connection = null;
                }
                else
                {
                    _eventStream.Publish(new Warning(
                                             _self.Path.ToString(), GetType(),
                                             $"Receives wrong token({token}) from {_connection?.RemoteEndPoint}"));
                    return;
                }
            }
            finally
            {
                // This actor will be destroyed anyway after this call.
                _self.Tell(PoisonPill.Instance);
            }
        }