The EventStream is a pub-sub stream of events that can be both system and user generated. The subscribers are IActorRef instances and events can be any object. Subscriptions are hierarchical meaning that if you listen to an event for a particular type you will receive events for that type and any sub types. If the debug flag is activated any operations on the event stream will be published as debug level events.
Наследование: LoggingBus
Пример #1
0
 public EventStreamUnsubscriber(EventStream eventStream, ActorSystem system, bool debug)
 {
     _eventStream = eventStream;
     _system = system;
     _debug = debug;
    
 }
Пример #2
0
 public ClusterActorRefProvider(string systemName, Settings settings, EventStream eventStream /*DynamicAccess*/)
     : base(systemName, settings, eventStream)
 {
     var clusterConfig = ClusterConfigFactory.Default();
     settings.InjectTopLevelFallback(clusterConfig);
     Deployer = new ClusterDeployer(settings);
 }
        protected override void PreStart()
        {
            base.PreStart();

            _self = Self;
            _eventStream = Context.System.EventStream;

            // create initial actors and bind them

            if (_initiator.CreateInitialActors != null)
            {
                var actors = _initiator.CreateInitialActors(Context, _connection);
                if (actors != null)
                {
                    foreach (var actor in actors)
                    {
                        BindActor(actor.Item1, actor.Item2.Select(t => new BoundType(t)));
                    }
                }
            }

            // accept it

            _connection.MessageHandler = OnConnectionMessage;
            _connection.Approve();
        }
Пример #4
0
 /// <summary>
 /// Default constructor...
 /// </summary>
 public DefaultDispatcherPrerequisites(EventStream eventStream, IScheduler scheduler, Settings settings, Mailboxes mailboxes)
 {
     Mailboxes = mailboxes;
     Settings = settings;
     Scheduler = scheduler;
     EventStream = eventStream;
 }
Пример #5
0
 public void NotAllowNullAsSubscriber()
 {
     var bus = new EventStream(true);
     XAssert.Throws<ArgumentNullException>(() =>
     {
         bus.Subscribe(null, typeof(M));
     });
 }
 /// <summary>
 /// Constructor that reads parameters from config.
 /// Expecting config properties named 'threshold', 'max-sample-size',
 /// 'min-std-deviation', 'acceptable-heartbeat-pause', and 'heartbeat-interval'.
 /// </summary>
 public PhiAccrualFailureDetector(Config config, EventStream ev)
     : this(DefaultClock)
 {
     _threshold = config.GetDouble("threshold");
     _maxSampleSize = config.GetInt("max-sample-size");
     _minStdDeviation = config.GetTimeSpan("min-std-deviation");
     _acceptableHeartbeatPause = config.GetTimeSpan("acceptable-heartbeat-pause");
     _firstHeartbeatEstimate = config.GetTimeSpan("heartbeat-interval");
     state = new State(FirstHeartBeat, null);
 }
Пример #7
0
        public void ManageSubscriptions()
        {
            var bus = new EventStream(true);
            bus.Subscribe(TestActor, typeof(M));

            bus.Publish(new M { Value = 42 });
            ExpectMsg(new M { Value = 42 });
            bus.Unsubscribe(TestActor);
            bus.Publish(new M { Value = 43 });
            ExpectNoMsg(TimeSpan.FromSeconds(1));
        }
        protected override void PreStart()
        {
            base.PreStart();

            _self = Self;
            _eventStream = Context.System.EventStream;

            // create initial actors and bind them

            if (_initiator.CreateInitialActors != null)
            {
                var actors = _initiator.CreateInitialActors(Context, _connection);
                if (actors != null)
                {
                    foreach (var actor in actors)
                    {
                        BindActor(actor.Item1, actor.Item2.Select(t => new BoundType(t)));
                    }
                }
            }

            // link connection to this

            _connection.Closed += OnConnectionClose;
            _connection.Received += OnConnectionReceive;

            if (_connection.IsOpen == false)
            {
                try
                {
                    _connection.Open();
                }
                catch (Exception e)
                {
                    _logger.ErrorFormat("Cannot open connection.", e);
                }
            }
            else
            {
                if (_connection.Active)
                {
                    _connection.Send(new Packet
                    {
                        Type = PacketType.System,
                        Message = "1",
                    });
                }
                else
                {
                    OnConnectionClose(_connection, -1);
                }
            }
        }
Пример #9
0
 public void NotAllowNullAsUnsubscriber()
 {
     var bus = new EventStream(true);
     intercept<ArgumentNullException>(() =>
     {
         bus.Unsubscribe(null, typeof(M));
     });
     intercept<ArgumentNullException>(() =>
     {
         bus.Unsubscribe(null);
     });
 }
Пример #10
0
        public void ManageSubscriptions()
        {

            var bus = new EventStream(true);
            bus.StartUnsubscriber(Sys.AsInstanceOf<ActorSystemImpl>());
            bus.Subscribe(TestActor, typeof(M));

            bus.Publish(new M { Value = 42 });
            ExpectMsg(new M { Value = 42 });
            bus.Unsubscribe(TestActor);
            bus.Publish(new M { Value = 43 });
            ExpectNoMsg(TimeSpan.FromSeconds(1));
        }
        protected override void PreStart()
        {
            base.PreStart();

            _self = Self;
            _eventStream = Context.System.EventStream;

            _connection.Closed += OnConnectionClose;
            _connection.Received += OnConnectionReceive;
            _connection.Open();

            if (_initiator.TokenTimeout != TimeSpan.Zero)
            {
                _timeoutCanceler = Context.System.Scheduler.ScheduleTellOnceCancelable(
                    _initiator.TokenTimeout, Self, PoisonPill.Instance, Self);
            }
        }
Пример #12
0
        public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func<ActorPath, InternalActorRef> deadLettersFactory)
        {
            _settings = settings;
            _eventStream = eventStream;
            _deployer = deployer ?? new Deployer(settings);
            _rootPath = new RootActorPath(new Address("akka", systemName));
            _log = Logging.GetLogger(eventStream, "LocalActorRefProvider(" + _rootPath.Address + ")");
            if (deadLettersFactory == null)
                deadLettersFactory = p => new DeadLetterActorRef(this, p, _eventStream);
            _deadLetters = deadLettersFactory(_rootPath / "deadLetters");
            _tempNumber = new AtomicCounterLong(1);
            _tempNode = _rootPath / "temp";

            //TODO: _guardianSupervisorStrategyConfigurator = dynamicAccess.createInstanceFor[SupervisorStrategyConfigurator](settings.SupervisorStrategyClass, EmptyImmutableSeq).get
            _systemGuardianStrategy = SupervisorStrategy.DefaultStrategy;

        }
Пример #13
0
 public DeadLetterActorRef(IActorRefProvider provider, ActorPath path, EventStream eventStream)
     : base(provider, path, eventStream)
 {
     _eventStream = eventStream;
 }
Пример #14
0
 public EmptyLocalActorRef(IActorRefProvider provider, ActorPath path, EventStream eventStream)
 {
     _provider = provider;
     _path = path;
     _eventStream = eventStream;
 }
Пример #15
0
 /// <summary>
 /// Constructor that reads parameters from an Akka <see cref="Config"/> section.
 /// Expects property 'acceptable-heartbeat-pause'.
 /// </summary>
 /// <param name="config"></param>
 /// <param name="ev"></param>
 public DeadlineFailureDetector(Config config, EventStream ev) : this(config.GetTimeSpan("acceptable-heartbeat-pause")) { }
Пример #16
0
        public void ManageLogLevels()
        {
          var bus = new EventStream(false);
          bus.StartDefaultLoggers(sys);
          bus.Publish(new SetTarget(testActor));
          expectMsg("OK");

          verifyLevel(bus, LogLevel.InfoLevel);
          bus.SetLogLevel(LogLevel.WarningLevel);
          verifyLevel(bus, LogLevel.WarningLevel);
          bus.SetLogLevel(LogLevel.DebugLevel);
          verifyLevel(bus, LogLevel.DebugLevel);
          bus.SetLogLevel(LogLevel.ErrorLevel);
          verifyLevel(bus, LogLevel.ErrorLevel);

        }
Пример #17
0
        public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream, Deployer deployer, Func<ActorPath, IInternalActorRef> deadLettersFactory)
        {
            _settings = settings;
            _eventStream = eventStream;
            _deployer = deployer ?? new Deployer(settings);
            _rootPath = new RootActorPath(new Address("akka", systemName));
            _log = Logging.GetLogger(eventStream, "LocalActorRefProvider(" + _rootPath.Address + ")");
            if(deadLettersFactory == null)
                deadLettersFactory = p => new DeadLetterActorRef(this, p, _eventStream);
            _deadLetters = deadLettersFactory(_rootPath / "deadLetters");
            _tempNumber = new AtomicCounterLong(1);
            _tempNode = _rootPath / "temp";

            _systemGuardianStrategy = SupervisorStrategy.DefaultStrategy;
            _userGuardianStrategyConfigurator = SupervisorStrategyConfigurator.CreateConfigurator(Settings.SupervisorStrategyClass);
        }
Пример #18
0
 public LocalActorRefProvider(string systemName, Settings settings, EventStream eventStream)
     : this(systemName, settings, eventStream, null, null)
 {
     //Intentionally left blank
 }
Пример #19
0
 /// <summary>
 /// Unsubscribes the specified subscriber.
 /// </summary>
 /// <typeparam name="TChannel">The channel.</typeparam>
 /// <param name="eventStream">The event stream.</param>
 /// <param name="subscriber">The subscriber.</param>
 /// <returns><c>true</c> if unsubscription was successful, <c>false</c> otherwise.</returns>
 /// <exception cref="System.ArgumentNullException">subscriber</exception>
 public static bool Unsubscribe <TChannel>(this EventStream eventStream, IActorRef subscriber)
 {
     return(eventStream.Unsubscribe(subscriber, typeof(TChannel)));
 }
 public EventStreamUnsubscriber(EventStream eventStream, ActorSystem system, bool debug)
 {
     _eventStream = eventStream;
     _system      = system;
     _debug       = debug;
 }
Пример #21
0
        public void ManageSubChannelsUsingClassesAndInterfacesUpdateOnUnsubscribeAll()
        {
            var es = new EventStream(false);
            var tm1 = new CC();
            var tm2 = new CCATBT();
            var a1 = CreateTestProbe();
            var a2 = CreateTestProbe();
            var a3 = CreateTestProbe();
            var a4 = CreateTestProbe();

            es.Subscribe(a1.Ref, typeof(AT)).ShouldBeTrue();
            es.Subscribe(a2.Ref, typeof(BT)).ShouldBeTrue();
            es.Subscribe(a3.Ref, typeof(CC)).ShouldBeTrue();
            es.Subscribe(a4.Ref, typeof(CCATBT)).ShouldBeTrue();
            es.Unsubscribe(a3.Ref).ShouldBeTrue();
            es.Publish(tm1);
            es.Publish(tm2);
            a1.ExpectMsg((object)tm2);
            a2.ExpectMsg((object)tm2);
            a3.ExpectNoMsg(TimeSpan.FromSeconds(1));
            a4.ExpectMsg((object)tm2);
            es.Unsubscribe(a1.Ref, typeof(AT)).ShouldBeTrue();
            es.Unsubscribe(a2.Ref, typeof(BT)).ShouldBeTrue();
            es.Unsubscribe(a3.Ref, typeof(CC)).ShouldBeFalse();
            es.Unsubscribe(a4.Ref, typeof(CCATBT)).ShouldBeTrue();
        }
Пример #22
0
 public FailureDetectorPuppet(Config config, EventStream ev)
 {
 }
Пример #23
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="DeadLetterActorRef" /> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="path">The path.</param>
 /// <param name="eventStream">The event stream.</param>
 public DeadLetterActorRef(ActorRefProvider provider, ActorPath path, EventStream eventStream)
 {
     this.eventStream = eventStream;
     this.path = path;
     this.provider = provider;
 }
Пример #24
0
 public void Start(ActorSystemImpl system, EventStream eventStream, bool debug)
 {
     system.SystemActorOf(Props.Create<EventStreamUnsubscriber>(eventStream, system, debug),
         string.Format("EventStreamUnsubscriber-{0}", _unsubscribersCounter.IncrementAndGet()));
 }
Пример #25
0
        public void ManageSubChannelsUsingClasses()
        {
            var a = new A();
            var b1 = new B1();
            var b2 = new B2();
            var c = new C();
            var bus = new EventStream(false);
            bus.Subscribe(TestActor, typeof(B2));
            bus.Publish(c);
            bus.Publish(b2);
            ExpectMsg(b2);
            bus.Subscribe(TestActor, typeof(A));
            bus.Publish(c);
            ExpectMsg(c);
            bus.Publish(b1);
            ExpectMsg(b1);

            bus.Unsubscribe(TestActor, typeof(B1));
            bus.Publish(c); //should not publish
            bus.Publish(b2); //should publish
            bus.Publish(a); //should publish
            ExpectMsg(b2);
            ExpectMsg(a);
            ExpectNoMsg(TimeSpan.FromSeconds(1));
        }
Пример #26
0
 public void Not_allow_null_as_unsubscriber()
 {
     var bus = new EventStream(true);
     XAssert.Throws<ArgumentNullException>(() =>
     {
         bus.Unsubscribe(null, typeof(M));
     });
     XAssert.Throws<ArgumentNullException>(() =>
     {
         bus.Unsubscribe(null);
     });
 }
Пример #27
0
        public void ManageLogLevels()
        {
            var bus = new EventStream(false);
            bus.StartDefaultLoggers((ActorSystemImpl)Sys);
            bus.Publish(new SetTarget(TestActor));
            ExpectMsg("OK", TimeSpan.FromSeconds(5));

            verifyLevel(bus, LogLevel.InfoLevel);
            bus.SetLogLevel(LogLevel.WarningLevel);
            verifyLevel(bus, LogLevel.WarningLevel);
            bus.SetLogLevel(LogLevel.DebugLevel);
            verifyLevel(bus, LogLevel.DebugLevel);
            bus.SetLogLevel(LogLevel.ErrorLevel);
            verifyLevel(bus, LogLevel.ErrorLevel);
        }
 public void Start(ActorSystemImpl system, EventStream eventStream, bool debug)
 {
     system.SystemActorOf(Props.Create <EventStreamUnsubscriber>(eventStream, system, debug),
                          string.Format("EventStreamUnsubscriber-{0}", _unsubscribersCounter.IncrementAndGet()));
 }
Пример #29
0
        public void ManageSubChannelsUsingClassesAndInterfacesUpdateOnUnsubscribeAll()
        {
            var es = new EventStream(false);
            var tm1 = new CC();
            var tm2 = new CCATBT();
            var a1 = TestProbe();
            var a2 = TestProbe();
            var a3 = TestProbe();
            var a4 = TestProbe();

            es.Subscribe(a1.Ref, typeof(AT)).Then(Assert.True);
            es.Subscribe(a2.Ref, typeof(BT)).Then(Assert.True);
            es.Subscribe(a3.Ref, typeof(CC)).Then(Assert.True);
            es.Subscribe(a4.Ref, typeof(CCATBT)).Then(Assert.True);
            es.Unsubscribe(a3.Ref).Then(Assert.True);
            es.Publish(tm1);
            es.Publish(tm2);
            a1.expectMsg(tm2);
            a2.expectMsg(tm2);
            a3.expectNoMsg(TimeSpan.FromSeconds(1));
            a4.expectMsg(tm2);
            es.Unsubscribe(a1.Ref, typeof(AT)).Then(Assert.True);
            es.Unsubscribe(a2.Ref, typeof(BT)).Then(Assert.True);
            es.Unsubscribe(a3.Ref, typeof(CC)).Then(Assert.False);
            es.Unsubscribe(a4.Ref, typeof(CCATBT)).Then(Assert.True);
        }
Пример #30
0
        public void Manage_sub_channels_using_classes_and_interfaces_update_on_unsubscribe()
        {
            var es = new EventStream(false);
            var tm1 = new CC();
            var tm2 = new CCATBT();
            var a1 = CreateTestProbe();
            var a2 = CreateTestProbe();
            var a3 = CreateTestProbe();
            var a4 = CreateTestProbe();

            es.Subscribe(a1.Ref, typeof(AT));
            es.Subscribe(a2.Ref, typeof(BT));
            es.Subscribe(a3.Ref, typeof(CC));
            es.Subscribe(a4.Ref, typeof(CCATBT));
            es.Unsubscribe(a3.Ref, typeof(CC));
            es.Publish(tm1);
            es.Publish(tm2);
            a1.ExpectMsg((object)tm2);
            a2.ExpectMsg((object)tm2);
            a3.ExpectNoMsg(TimeSpan.FromSeconds(1));
            a4.ExpectMsg((object)tm2);
            es.Unsubscribe(a1.Ref, typeof(AT)).ShouldBeTrue();
            es.Unsubscribe(a2.Ref, typeof(BT)).ShouldBeTrue();
            es.Unsubscribe(a3.Ref, typeof(CC)).ShouldBeFalse();
            es.Unsubscribe(a4.Ref, typeof(CCATBT)).ShouldBeTrue();
        }