Exemplo n.º 1
0
        private void HandleConnectionRequest(ConnectionMessages.ConnectionRequest msg)
        {
            if (_clients == null)
            {
                _clients =
                    Context.ActorSelection(ServerActorPaths.ClientsActor.Path)
                        .ResolveOne(TimeSpan.FromMilliseconds(500))
                        .Result;

                if (_clients == null)
                {
                    _logger.Error("ConnctionActor was unable to acquire an actor reference to the ClientsActor");
                }
            }

            IActorRef clientsHandler =
                Context.ActorSelection(Sender.Path.Sibling(ClientActorPaths.ClientsActor.Name))
                       .ResolveOne(TimeSpan.FromSeconds(1))
                       .Result;

            IActorRef messageHandler =
                Context.ActorSelection(Sender.Path.Sibling(ClientActorPaths.ChatMessageRouter.Name))
                       .ResolveOne(TimeSpan.FromSeconds(1))
                       .Result;

            _clients.Tell(new ClientsActor.NewClient(msg.ClientId, msg.Username, msg.InitialStatus, clientsHandler, messageHandler), Sender);
        }
Exemplo n.º 2
0
        private void HandleHeartbeat(ConnectionMessages.Heartbeat msg)
        {
            if (msg.Status != _status)
            {
                _status = msg.Status;
                Context.Parent.Tell(new ClientsActor.ClientStatusChanged(_clientId, _status));
            }

            Sender.Tell(new ConnectionMessages.HeartbeatAcknowledged());
        }
Exemplo n.º 3
0
        private void HandleLostConnection(ConnectionMessages.ConnectionLost msg)
        {
            MessageHandler.Tell(new MessagingActor.RemoveUser(msg.ClientId));

            var c = _clients.Values.First(x => x.Id == msg.ClientId);
            var disconnectedClient = new ClientTracking.ClientDisconnected(new ConnectedClient(c.Id, c.Username, c.Status));

            var monitor = _monitors[msg.ClientId];
            _monitors.Remove(msg.ClientId);
            _clients.Remove(msg.ClientId);
            Context.Stop(monitor);

            foreach (var client in _clients.Values)
            {
                client.ClientsHandler.Tell(disconnectedClient);
            }
        }
Exemplo n.º 4
0
        private void HandleLostConnection(ConnectionMessages.ConnectionLost msg)
        {
            Context.Stop(_heartbeatActor);
            _heartbeatActor = null;
            _errorActor.Tell(new ErrorDialogActor.ErrorMessage("Dropped connection", "Connection to the server was lost"));

            Become(Disconnected);
        }
Exemplo n.º 5
0
        private void HandleConnectionResponse(ConnectionMessages.ConnectionResponse msg)
        {
            Context.SetReceiveTimeout(null);

            var prop = Context.DI().Props<HeartbeatActor>();
            _heartbeatActor = Context.ActorOf(prop, ClientActorPaths.HeartbeatActor.Name);
            _heartbeatActor.Tell(new HeartbeatActor.BeginHeartbeat(msg.HearbeatReceiver, _status));

            Context.ActorSelection(ClientActorPaths.ClientsActor.Path)
                   .Tell(new ClientTracking.NewClientList(msg.ConnectedClients));

            _messagingActor.Tell(new ConnectionMade(msg.MessageHandler));
            Become(Connected);
        }
Exemplo n.º 6
0
 private void HandleDisconnect(ConnectionMessages.Disconnect msg)
 {
     StopHeartbeat();
     _target.Tell(msg);
 }
Exemplo n.º 7
0
 private void HandleAck(ConnectionMessages.HeartbeatAcknowledged msg)
 {
     _lastAck = DateTime.UtcNow;
 }