Example #1
0
        private void HandleUnwatch(IContext context, Unwatch msg)
        {
            var remoteActor = _remoteActors.Single(ra => ra.Id == msg.Watcher.Id &&
                                                   ra.Address == msg.Watcher.Address);

            context.Unwatch(remoteActor);
        }
        public void Can_serialize_Unwatch()
        {
            var watchee = ActorOf <Watchee>().AsInstanceOf <IInternalActorRef>();
            var watcher = ActorOf <Watcher>().AsInstanceOf <IInternalActorRef>();
            var unwatch = new Unwatch(watchee, watcher);

            AssertEqual(unwatch);
        }
        public Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case RemoteTerminate msg:
            {
                _watched.Remove(msg.Watcher.Id);
                //create a terminated event for the Watched actor
                var t = new Terminated
                {
                    Who = msg.Watchee
                };
                //send the address Terminated event to the Watcher
                msg.Watcher.SendSystemMessage(t);
                break;
            }

            case EndpointTerminatedEvent _:
            {
                foreach (var(id, pid) in _watched)
                {
                    //create a terminated event for the Watched actor
                    var t = new Terminated
                    {
                        Who = pid,
                        AddressTerminated = true
                    };
                    var watcher = new PID(ProcessRegistry.Instance.Address, id);
                    //send the address Terminated event to the Watcher
                    watcher.SendSystemMessage(t);
                }
                break;
            }

            case RemoteUnwatch msg:
            {
                _watched[msg.Watcher.Id] = null;

                var w = new Unwatch(msg.Watcher);
                RemoteProcess.SendRemoteMessage(msg.Watchee, w);
                break;
            }

            case RemoteWatch msg:
            {
                _watched[msg.Watcher.Id] = msg.Watchee;

                var w = new Watch(msg.Watcher);
                RemoteProcess.SendRemoteMessage(msg.Watchee, w);
                break;
            }

            default:
                break;
            }
            return(Actor.Done);
        }
Example #4
0
        //
        // Unwatch
        //
        private byte[] UnwatchToProto(Unwatch unwatch)
        {
            var message = new Proto.Msg.WatchData();

            message.Watchee      = new Proto.Msg.ActorRefData();
            message.Watchee.Path = Akka.Serialization.Serialization.SerializedActorPath(unwatch.Watchee);
            message.Watcher      = new Proto.Msg.ActorRefData();
            message.Watcher.Path = Akka.Serialization.Serialization.SerializedActorPath(unwatch.Watcher);
            return(message.ToByteArray());
        }
Example #5
0
        private void HandleUnwatch(Unwatch unwatch)
        {
            if (!this._counterActors.ContainsKey(unwatch.CounterType))
            {
                return;
            }

            this._counterActors[unwatch.CounterType].Tell(new UnsubscribeCounter(unwatch.CounterType, this._chartingActor));
            this._chartingActor.Tell(new ChartingActor.RemoveSeries(unwatch.CounterType.ToString()));
        }
Example #6
0
        private void Handle(Unwatch message)
        {
            if (!_counterActors.ContainsKey(message.Counter))
            {
                return;
            }

            _counterActors[message.Counter].Tell(new UnsubscribeCounter(message.Counter, _chartingActor));

            _chartingActor.Tell(new ChartingActor.RemoveSeries(message.Counter.ToString()));
        }
        private void HandleUnwatch(Unwatch unwatch)
        {
            if (!_counterActors.ContainsKey(unwatch.Counter))
            {
                return; // noop
            }

            // unsubscribe the ChartingActor from receiving any more updates
            _counterActors[unwatch.Counter].Tell(
                new UnsubscribeCounter(unwatch.Counter, _chartingActor));

            // remove this series from the ChartingActor
            _chartingActor.Tell(new RemoveSeries(unwatch.Counter.ToString()));
        }
Example #8
0
        private Unwatch SynchronizeAndWatch(string fullSourcePath, string fullTargetPath)
        {
            var watcher = _fileWatcherFactory.Create(fullSourcePath);

            _folderSynchronizer.SyncFolder(fullSourcePath, fullTargetPath);
            watcher.Start();

            var subscription = watcher.FileObservable()
                               .Subscribe(x => _fileEventDispatcher.Dispatch(fullSourcePath, fullTargetPath, x));

            var unwatch = new Unwatch(
                watcher,
                subscription,
                new WatchFolder
            {
                Source = fullSourcePath,
                Target = fullTargetPath
            }
                );

            return(unwatch);
        }
Example #9
0
        public Task ConnectedAsync(IContext context)
        {
            switch (context.Message)
            {
            case RemoteTerminate msg:
            {
                if (_watched.TryGetValue(msg.Watcher.Id, out var pidSet))
                {
                    pidSet.Remove(msg.Watchee);
                    if (pidSet.Count == 0)
                    {
                        _watched[msg.Watcher.Id] = null;
                    }
                }

                //create a terminated event for the Watched actor
                var t = new Terminated
                {
                    Who = msg.Watchee
                };
                //send the address Terminated event to the Watcher
                msg.Watcher.SendSystemMessage(t);
                break;
            }

            case EndpointTerminatedEvent _:
            {
                _logger.LogDebug($"Handle terminated address {_address}");

                foreach (var(id, pidSet) in _watched)
                {
                    var watcherPid = new PID(ProcessRegistry.Instance.Address, id);
                    var watcherRef = ProcessRegistry.Instance.Get(watcherPid);
                    if (watcherRef != DeadLetterProcess.Instance)
                    {
                        foreach (var pid in pidSet)
                        {
                            //create a terminated event for the Watched actor
                            var t = new Terminated
                            {
                                Who = pid,
                                AddressTerminated = true
                            };

                            //send the address Terminated event to the Watcher
                            watcherPid.SendSystemMessage(t);
                        }
                    }
                }

                _watched.Clear();
                _behavior.Become(TerminatedAsync);
                break;
            }

            case RemoteUnwatch msg:
            {
                if (_watched.TryGetValue(msg.Watcher.Id, out var pidSet))
                {
                    pidSet.Remove(msg.Watchee);
                    if (pidSet.Count == 0)
                    {
                        _watched[msg.Watcher.Id] = null;
                    }
                }

                var w = new Unwatch(msg.Watcher);
                Remote.SendMessage(msg.Watchee, w, -1);
                break;
            }

            case RemoteWatch msg:
            {
                if (_watched.TryGetValue(msg.Watcher.Id, out var pidSet))
                {
                    pidSet.Add(msg.Watchee);
                }
                else
                {
                    _watched[msg.Watcher.Id] = new FastSet <PID> {
                        msg.Watchee
                    };
                }

                var w = new Watch(msg.Watcher);
                Remote.SendMessage(msg.Watchee, w, -1);
                break;
            }

            case Stopped _:
            {
                _logger.LogDebug($"Stopped EndpointWatcher at {_address}");
                break;
            }
            }
            return(Actor.Done);
        }
 //TODO: find out why this is never called
 /// <summary>
 ///     Handles the unwatch.
 /// </summary>
 /// <param name="m">The m.</param>
 private void HandleUnwatch(Unwatch m)
 {
     WatchedBy.Remove(m.Watcher);
     terminatedQueue.Remove(m.Watchee);
 }