Domain events published to the event bus. Subscribe with: {{{ Cluster(system).subscribe(actorRef, classOf[ClusterDomainEvent]) }}}
Example #1
0
 private void PublishDiff(Gossip oldGossip, Gossip newGossip, Action <object> pub)
 {
     foreach (var @event in ClusterEvent.DiffMemberEvents(oldGossip, newGossip))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffUnreachable(oldGossip, newGossip))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffReachable(oldGossip, newGossip))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffLeader(oldGossip, newGossip, _selfUniqueAddress))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffRolesLeader(oldGossip, newGossip, _selfUniqueAddress))
     {
         pub(@event);
     }
     // publish internal SeenState for testing purposes
     foreach (var @event in ClusterEvent.DiffSeen(oldGossip, newGossip, _selfUniqueAddress))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffReachability(oldGossip, newGossip))
     {
         pub(@event);
     }
 }
Example #2
0
 private void PublishDiff(MembershipState oldState, MembershipState newState, Action <object> pub)
 {
     foreach (var @event in ClusterEvent.DiffMemberEvents(oldState, newState))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffUnreachable(oldState, newState))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffReachable(oldState, newState))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffLeader(oldState, newState))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffRolesLeader(oldState, newState))
     {
         pub(@event);
     }
     // publish internal SeenState for testing purposes
     foreach (var @event in ClusterEvent.DiffSeen(oldState, newState))
     {
         pub(@event);
     }
     foreach (var @event in ClusterEvent.DiffReachability(oldState, newState))
     {
         pub(@event);
     }
 }
        private bool RoleLeaderChanged(ClusterEvent.RoleLeaderChanged rlc)
        {
            if (Cluster.SelfRoles.Contains(rlc.Role))
            {
                if (rlc.Leader == Cluster.SelfAddress)
                {
                    Schedule();
                    return true;
                }
                else
                {
                    m_TokenSource.Cancel();
                }
            }

            return false;
        }
        public void PushClusterState(ClusterEvent.CurrentClusterState clusterState, Address currentClusterAddress)
        {
            // Push ClusterState x to subscribed client.
            // So if client A subscibes to ClusterState A then it should only get A and not B.
            // TODO:
            
            List<ClusterRoleLeader> clusterRoleLeaders = new List<ClusterRoleLeader>();
            foreach (var member in clusterState.Members)
            {
                var role = member.Roles.First();
                var address = clusterState.RoleLeader(role);
                clusterRoleLeaders.Add(new ClusterRoleLeader(role, address));
            }

            var context = GlobalHost.ConnectionManager.GetHubContext<ClusterStateHub>();
            dynamic allClients = context.Clients.All.broadcastClusterState(clusterState, clusterRoleLeaders, currentClusterAddress);
        }
Example #5
0
        public void ClusterState(ClusterEvent.CurrentClusterState clusterState, Address currentClusterAddress)
        {
            List<ClusterRoleLeader> clusterRoleLeaders = new List<ClusterRoleLeader>();
            foreach (var member in clusterState.Members)
            {
                foreach (var role in member.Roles)
                {
                    var address = clusterState.RoleLeader(role);
                    clusterRoleLeaders.Add(new ClusterRoleLeader(role, address));
                }
            }

            var context = GlobalHost.ConnectionManager.GetHubContext<MonitorHub>();
            context.Clients.All.broadcastClusterState(new
            {
                state = clusterState,
                leaders = clusterRoleLeaders,
                address = currentClusterAddress,
                time = DateTime.UtcNow
            });
        }
 /// <summary>
 /// Update the initial node ring for those nodes that are <see cref="MemberStatus.Up"/>
 /// </summary>
 private void ReceiveState(ClusterEvent.CurrentClusterState state)
 {
     Nodes = state.Members.Where(x => x.Status == MemberStatus.Up).Select(x => x.Address).ToImmutableHashSet();
 }
Example #7
0
 private void Init(ClusterEvent.CurrentClusterState snapshot)
 {
     var nodes = snapshot.Members.Where(x => x.Status == MemberStatus.Up).Select(x => x.UniqueAddress).ToImmutableHashSet();
     _state = _state.Init(nodes);
 }
Example #8
0
 private void PublishInternalStats(ClusterEvent.CurrentInternalStats currentStats)
 {
     Publish(currentStats);
 }
Example #9
0
        private void Subscribe(IActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initMode,
            IEnumerable<Type> to)
        {
            if (initMode == ClusterEvent.SubscriptionInitialStateMode.InitialStateAsEvents)
            {
                Action<object> pub = @event =>
                {
                    var eventType = @event.GetType();
                    //TODO: IsAssignableFrom same as in scala?
                    if (to.Any(o => o.IsAssignableFrom(eventType)))
                        subscriber.Tell(@event);
                };
                PublishDiff(Gossip.Empty, _latestGossip, pub);
            }
            else if(initMode == ClusterEvent.SubscriptionInitialStateMode.InitialStateAsSnapshot)
            {
                SendCurrentClusterState(subscriber);
            }

            foreach (var t in to) _eventStream.Subscribe(subscriber, t);
        }
 private void PrintClusterEvent(ClusterEvent.MemberStatusChange msg)
 {
     _log.Info("Member {MemberStatus} {MemberAddress} {MemberRoles}", msg.Member.Status, msg.Member.Address,
         string.Join(",", msg.Member.Roles));
 }
 private void MemberUp(ClusterEvent.MemberUp memberUp)
 {
     if (memberUp.Member.Address != _cluster.SelfAddress)
     {
         _clusterNodes = _clusterNodes.Add(memberUp.Member.Address);
         TakeOverResponsibility(memberUp.Member.Address);
         Unreachable.Remove(memberUp.Member.Address);
     }
 }
 private void MemberRemoved(ClusterEvent.MemberRemoved memberRemoved)
 {
     if (memberRemoved.Member.Address != _cluster.SelfAddress)
     {
         _clusterNodes = _clusterNodes.Remove(memberRemoved.Member.Address);
         if (memberRemoved.PreviousStatus == MemberStatus.Down)
         {
             Quarantine(memberRemoved.Member.Address, memberRemoved.Member.UniqueAddress.Uid);
         }
         PublishAddressTerminated(memberRemoved.Member.Address);
     }
 }
Example #13
0
 internal PublishEvent(ClusterEvent.IClusterDomainEvent @event)
 {
     _event = @event;
 }
Example #14
0
 public Subscribe(IActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode,
     ImmutableHashSet<Type> to)
 {
     _subscriber = subscriber;
     _initialStateMode = initialStateMode;
     _to = to;
 }
        private void PrintClusterEvent(ClusterEvent.MemberStatusChange msg)
        {
            _log.Info("Member {MemberStatus} {MemberAddress} {MemberRoles}", msg.Member.Status, msg.Member.Address,
                string.Join(",", msg.Member.Roles));

            var address = msg.Member.Address;
            var userPath = $"akka.tcp://{address.System}@{address.Host}:{address.Port}/user";
            Context.ActorSelection(userPath).Tell(new Identify(Guid.NewGuid()));
            var remotePath = $"akka.tcp://{address.System}@{address.Host}:{address.Port}/remote";
            Context.ActorSelection(remotePath).Tell(new Identify(Guid.NewGuid()));
            var sysPath = $"akka.tcp://{address.System}@{address.Host}:{address.Port}/system";
            Context.ActorSelection(sysPath).Tell(new Identify(Guid.NewGuid()));
        }
 public CurrentClusterStatus(List<ClusterRoleLeader> clusterRoleLeaders, Address currentClusterAddress, ClusterEvent.CurrentClusterState clusterState)
 {
     ClusterRoleLeaders = clusterRoleLeaders;
     CurrentClusterAddress = currentClusterAddress;
     ClusterState = clusterState;
 }