public ClusterSingletonProxy(string singletonManagerPath, ClusterSingletonProxySettings settings)
        {
            _settings = settings;
            _singletonPath = (singletonManagerPath + "/" + settings.SingletonName).Split('/');
            _identityId = CreateIdentifyId(_identityCounter);

            Receive<ClusterEvent.CurrentClusterState>(s => HandleInitial(s));
            Receive<ClusterEvent.MemberUp>(m => Add(m.Member));
            Receive<ClusterEvent.MemberExited>(m => Remove(m.Member));
            Receive<ClusterEvent.MemberRemoved>(m => Remove(m.Member));
            Receive<ClusterEvent.IMemberEvent>(m =>
            {
                /* do nothing */
            });
            Receive<ActorIdentity>(identity =>
                {
                    if (identity.Subject != null)
                    {
                        // if the new singleton is defined, deliver all buffered messages
                        var subject = identity.Subject;
                        Log.Info("Singleton identified at [{0}]", subject.Path);
                        _singleton = subject;
                        Context.Watch(subject);
                        CancelTimer();
                        SendBuffered();
                    }
                });
            Receive<TryToIdentifySingleton>(_ =>
                 {
                     var oldest = _membersByAge.FirstOrDefault();
                     if (oldest != null && _identityTimer != null)
                     {
                         var singletonAddress = new RootActorPath(oldest.Address) / _singletonPath;
                         Log.Debug("Trying to identify singleton at [{0}]", singletonAddress);
                         Context.ActorSelection(singletonAddress).Tell(new Identify(_identityId));
                     }
                 });
            Receive<Terminated>(terminated =>
                {
                    if (Equals(_singleton, terminated.ActorRef))
                    {
                        // buffering mode, identification of new will start when old node is removed
                        _singleton = null;
                    }
                });
            ReceiveAny(msg =>
                {
                    if (_singleton != null)
                    {
                        if (Log.IsDebugEnabled)
                            Log.Debug("Forwarding message of type [{0}] to current singleton instance at [{1}]", msg.GetType(), _singleton.Path);
                        _singleton.Forward(msg);
                    }
                    else
                        Buffer(msg);
                });
        }
Exemple #2
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="singletonManagerPath">TBD</param>
        /// <param name="settings">TBD</param>
        public ClusterSingletonProxy(string singletonManagerPath, ClusterSingletonProxySettings settings)
        {
            _settings      = settings;
            _singletonPath = (singletonManagerPath + "/" + settings.SingletonName).Split('/');
            _identityId    = CreateIdentifyId(_identityCounter);

            Receive <ClusterEvent.CurrentClusterState>(s => HandleInitial(s));
            Receive <ClusterEvent.MemberUp>(m => Add(m.Member));
            Receive <ClusterEvent.MemberExited>(m => Remove(m.Member));
            Receive <ClusterEvent.MemberRemoved>(m =>
            {
                if (m.Member.UniqueAddress.Equals(_cluster.SelfUniqueAddress))
                {
                    Context.Stop(Self);
                }
                else
                {
                    Remove(m.Member);
                }
            });
            Receive <ClusterEvent.IMemberEvent>(m =>
            {
                /* do nothing */
            });
            Receive <ActorIdentity>(identity =>
            {
                if (identity.Subject != null)
                {
                    // if the new singleton is defined, deliver all buffered messages
                    var subject = identity.Subject;
                    Log.Info("Singleton identified at [{0}]", subject.Path);
                    _singleton = subject;
                    Context.Watch(subject);
                    CancelTimer();
                    SendBuffered();
                }
            });
            Receive <TryToIdentifySingleton>(_ =>
            {
                var oldest = _membersByAge.FirstOrDefault();
                if (oldest != null && _identityTimer != null)
                {
                    var singletonAddress = new RootActorPath(oldest.Address) / _singletonPath;
                    Log.Debug("Trying to identify singleton at [{0}]", singletonAddress);
                    Context.ActorSelection(singletonAddress).Tell(new Identify(_identityId));
                }
            });
            Receive <Terminated>(terminated =>
            {
                if (Equals(_singleton, terminated.ActorRef))
                {
                    // buffering mode, identification of new will start when old node is removed
                    _singleton = null;
                }
            });
            ReceiveAny(msg =>
            {
                if (_singleton != null)
                {
                    if (Log.IsDebugEnabled)
                    {
                        Log.Debug("Forwarding message of type [{0}] to current singleton instance at [{1}]", msg.GetType(), _singleton.Path);
                    }
                    _singleton.Forward(msg);
                }
                else
                {
                    Buffer(msg);
                }
            });
        }
Exemple #3
0
 /// <summary>
 /// Factory method for <see cref="ClusterSingletonProxy"/> <see cref="Actor.Props"/>.
 /// </summary>
 /// <param name="singletonManagerPath">
 /// The logical path of the singleton manager, e.g. `/user/singletonManager`,
 /// which ends with the name you defined in `actorOf` when creating the <see cref="ClusterSingletonManager"/>.
 /// </param>
 /// <param name="settings">Cluster singleton proxy settings.</param>
 /// <returns>TBD</returns>
 public static Props Props(string singletonManagerPath, ClusterSingletonProxySettings settings)
 {
     return(Actor.Props.Create(() => new ClusterSingletonProxy(singletonManagerPath, settings)).WithDeploy(Deploy.Local));
 }
 public ClusterSingletonProxy(string singletonManagerPath, ClusterSingletonProxySettings settings)
 {
     _settings = settings;
     _singletonPath = (singletonManagerPath + "/" + settings.SingletonName).Split('/');
     _identityId = CreateIdentifyId(_identityCounter);
 }
 /// <summary>
 /// Faactory method for <see cref="ClusterSingletonProxy"/> <see cref="Actor.Props"/>.
 /// </summary>
 /// <param name="singletonManagerPath">
 /// The logical path of the singleton manager, e.g. `/user/singletonManager`, 
 /// which ends with the name you defined in `actorOf` when creating the <see cref="ClusterSingletonManager"/>.
 /// </param>
 /// <param name="settings">Cluster singleton proxy settings.</param>
 public static Props Props(string singletonManagerPath, ClusterSingletonProxySettings settings)
 {
     return Actor.Props.Create(() => new ClusterSingletonProxy(singletonManagerPath, settings)).WithDeploy(Deploy.Local);
 }
 public ClusterSingletonProxy(string singletonManagerPath, ClusterSingletonProxySettings settings)
 {
     _settings      = settings;
     _singletonPath = (singletonManagerPath + "/" + settings.SingletonName).Split('/');
     _identityId    = CreateIdentifyId(_identityCounter);
 }