Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Subscribe to one or more cluster domain events.
        /// </summary>
        /// <param name="subscriber">The actor who'll receive the cluster domain events</param>
        /// <param name="initialStateMode">
        /// If set to <see cref="ClusterEvent.SubscriptionInitialStateMode.InitialStateAsEvents"/>, then the events corresponding to the current state
        /// are sent to <paramref name="subscriber"/> to mimic what it would have seen if it were listening to the events when they occurred in the past.
        ///
        /// If set to <see cref="ClusterEvent.SubscriptionInitialStateMode.InitialStateAsSnapshot"/>, then a snapshot of
        /// <see cref="ClusterEvent.CurrentClusterState"/> will be sent to <paramref name="subscriber"/> as the first message.
        /// </param>
        /// <param name="to">An array of event types that the actor receives.</param>
        /// <exception cref="ArgumentException">
        /// This exception is thrown when the array of supplied types, <paramref name="to"/>, is empty
        /// or contains types that do not implement <see cref="ClusterEvent.IClusterDomainEvent"/>.
        /// </exception>
        public void Subscribe(IActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, params Type[] to)
        {
            if (to.Length == 0)
                throw new ArgumentException("At least one `IClusterDomainEvent` class is required", nameof(to));
            if (!to.All(t => typeof(ClusterEvent.IClusterDomainEvent).IsAssignableFrom(t)))
                throw new ArgumentException($"Subscribe to `IClusterDomainEvent` or subclasses, was [{string.Join(", ", to.Select(c => c.Name))}]", nameof(to));

            ClusterCore.Tell(new InternalClusterAction.Subscribe(subscriber, initialStateMode, ImmutableHashSet.Create(to)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Subscribe to one or more cluster domain events.
        /// </summary>
        /// <param name="subscriber">The actor who'll receive the cluster domain events</param>
        /// <param name="initialStateMode">
        /// If set to <see cref="ClusterEvent.SubscriptionInitialStateMode.InitialStateAsEvents"/> the events corresponding to the current state
        /// will be sent to <see cref="subscriber"/> to mimic what it would have seen if it were listening to the events when they occurred in the past.
        ///
        /// If set to <see cref="ClusterEvent.SubscriptionInitialStateMode.InitialStateAsSnapshot"/>
        /// a snapshot of <see cref="ClusterEvent.CurrentClusterState"/> will be sent to <see cref="subscriber"/> as the first message. </param>
        /// <param name="to"><see cref="ClusterEvent.IClusterDomainEvent"/> subclasses</param>
        public void Subscribe(IActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode, Type[] to)
        {
            var val = _clusterCore;

            _clusterCore.Tell(new InternalClusterAction.Subscribe(subscriber, initialStateMode, ImmutableHashSet.Create <Type>(to)));
        }
Exemplo n.º 4
0
 public Subscribe(IActorRef subscriber, ClusterEvent.SubscriptionInitialStateMode initialStateMode,
     ImmutableHashSet<Type> to)
 {
     _subscriber = subscriber;
     _initialStateMode = initialStateMode;
     _to = to;
 }