private void OnReceived(ByteString data) { timer.CancelIfNotNull(); timer = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(connectionTimeoutLimit), Self, Timer.Instance, ActorRefs.NoSender); try { OnData(data); } catch { Disconnect(true); } }
private void OnReceived(ByteString data) { timer.CancelIfNotNull(); timer = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromMinutes(1), Self, Timer.Instance, ActorRefs.NoSender); try { OnData(data); } catch { Log($"error occurred when parse message:[{Remote.Address}]", LogLevel.Warning); Disconnect(true); } }
protected override void PostStop() { Log($"OnStop TaskManager {blockchain.Name}"); timer.CancelIfNotNull(); syncTimer.CancelIfNotNull(); base.PostStop(); }
protected override void PostStop() { timer.CancelIfNotNull(); ws_host?.Dispose(); tcp_listener?.Tell(Tcp.Unbind.Instance); base.PostStop(); }
protected override void PostStop() { Log($"OnStop RemoteNode {blockchain.Name} {Remote}"); localNode.RemoteNodes.TryRemove(Self, out _); timer.CancelIfNotNull(); base.PostStop(); }
protected override void PostStop() { if (stream != null) { CloseStream(); } scheduledRead.CancelIfNotNull(); }
private void ChangeTimer(TimeSpan delay) { timer_token.CancelIfNotNull(); timer_token = Context.System.Scheduler.ScheduleTellOnceCancelable(delay, Self, new Timer { Height = context.BlockIndex, ViewNumber = context.ViewNumber }, ActorRefs.NoSender); }
private void ChangeTimer(TimeSpan delay) { clock_started = TimeProvider.Current.UtcNow; expected_delay = delay; timer_token.CancelIfNotNull(); timer_token = Context.System.Scheduler.ScheduleTellOnceCancelable(delay, Self, new Timer { Height = context.Block.Index, ViewNumber = context.ViewNumber }, ActorRefs.NoSender); }
private void HandleActorIdentity(ActorIdentity x) { waitForIdentityCancelable.CancelIfNotNull(); if (Sender.Path != Self.Path) { _allOthers.Add(Sender); } waitForIdentityCancelable = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(2), Self, new Initiate(), Self); }
private void HandleActorIdentity(ActorIdentity x) { waitForIdentityCancelable.CancelIfNotNull(); if (Sender.Path != Self.Path) { _allOthers.Add(Sender); } // only two lines that need to be changed in order to add some random ordering int delay = rnd.Next(1, 10); waitForIdentityCancelable = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(delay), Self, new Initiate(), Self); }
private UntypedReceive Connected(IActorRef connection, IActorRef parsingActor, ICancelable cancelCommand) { return(message => { if (message is DoWeighingCommand) //received command to do weighing { connection.Tell(Tcp.Write.Create(weighingCommandA)); } else if (message is Tcp.Received) // data received from network { var received = message as Tcp.Received; _log.Debug(Encoding.ASCII.GetString(received.Data.ToArray())); parsingActor.Tell(received.Data); } else if (message is Tcp.PeerClosed) //try reconnect itself! { _log.Debug("Connection closed"); cancelCommand.CancelIfNotNull(); Context.System.Tcp().Tell(new Tcp.ConnectionClosed()); Become(OnReceive); Self.Tell(new DoConnectCommand()); } else if (message is NotAcknowledgedEvent) { _log.Debug("NAK received"); cancelCommand.CancelIfNotNull(); Context.System.Tcp().Tell(new Tcp.NoAck(_sensor.Uri.Host)); Become(OnReceive); Self.Tell(new DoConnectCommand()); } else { Unhandled(message); } }); }
private UntypedReceive Connecting(ICancelable cancelReconnect) { return(message => { if (message is Tcp.Connected) { cancelReconnect.CancelIfNotNull(); var connected = message as Tcp.Connected; _log.Debug("Connected to {0}", connected.RemoteAddress); // Register self as connection handler Sender.Tell(new Tcp.Register(Self)); var cancelCommand = new Cancelable(Context.System.Scheduler); var parsingActor = Context.ActorOf(Props.Create(() => new ResponseHandlerActor(_sensor))); Become(Connected(Sender, parsingActor, cancelCommand)); // schedule itself every 0.01 second Context.System.Scheduler.ScheduleTellRepeatedly(TimeSpan.FromSeconds(0.05), TimeSpan.FromSeconds(0.01), Self, new DoWeighingCommand(), Self, cancelCommand); } else if (message is Tcp.CommandFailed) { var received = message as Tcp.CommandFailed; _log.Debug("Connection failed"); Context.System.Tcp().Tell(new Tcp.CommandFailed(received.Cmd)); Become(OnReceive); Self.Tell(new DoConnectCommand()); } else if (message is Tcp.Received) { var received = message as Tcp.Received; if (received.Data.Count == 1 && received.Data[0] == 21) { //received NAK _log.Debug("NAK received"); Context.System.Tcp().Tell(new Tcp.NoAck(_sensor.Uri.Host)); Become(OnReceive); Self.Tell(new DoConnectCommand()); } } else if (message is DoWeighingCommand) { } else { Unhandled(message); } }); }
private void SubscribeForEvent(Type eventType, IActorRef subscriber) { _scheduler.CancelIfNotNull(); if (!_subscriptions.Keys.Contains(eventType)) { _subscriptions.Add(eventType, new List <IActorRef> { subscriber }); _scheduler = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(5), Self, new StartProjecting(), Self); return; } if (!_subscriptions[eventType].Contains(subscriber)) { _subscriptions[eventType].Add(subscriber); } _scheduler = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromSeconds(5), Self, new StartProjecting(), Self); }
protected override void OnReceive(object message) { switch (message) { case Tcp.Received received: if ("stop_server".Equals(Encoding.ASCII.GetString(received.Data.ToArray()))) { Context.Stop(Self); } else { receivedCount++; //Log.Info($"{receivedCount} Data received"); //for (int i = 0; i <= 100000; i++) //{ } //Log.Info("msg size is {0}", received.Data.Count); //var arr = received.Data.ToArray().ToHexString(); //Log.Info("msg content: {0}", arr); } break; case TPSTimer _: Log.Info("Tps is {0}/s", receivedCount); receivedCount = 0; break; case Tcp.ConnectionClosed _: Log.Warning("Connection Closed"); scheduler.CancelIfNotNull(); Context.Stop(Self); break; default: Unhandled(message); break; } }
protected override void PostStop() { timer.CancelIfNotNull(); base.PostStop(); }
private void RescheduleReceiveTimeout(TimeSpan timeout) { _pendingReceiveTimeout.CancelIfNotNull(); //Cancel any ongoing future _pendingReceiveTimeout = System.Scheduler.ScheduleTellOnceCancelable(timeout, Self, Akka.Actor.ReceiveTimeout.Instance, Self); _receiveTimeoutDuration = timeout; }
protected override void PostStop() { UnStashSchedule.CancelIfNotNull(); }