Exemplo n.º 1
0
        public RoomActor(long id, string name, 
                         IActorRef roomAccess, 
                         IActorRef messageAccess, 
                         ICanTell signalR)
        {
            _roomId =id;
            _name = name;
            _users = new Dictionary<long, User>();

            _roomAccess = roomAccess;
            _messageAccess = messageAccess;
            _signalR = signalR;

            Receive<UsersInRoomMessage>(message =>
            {
                message.Users.ForEach(user =>
                {
                    _users.Add(user.Id, user);
                });
                _log.Info("RoomActor-" + _name + "  established");
                Become(Established);
            });

            Receive<FailedToGetUsersInRoomMessage>(message =>
            {
                _log.Error("FailedToGetUsersInRoomMessage-" + _roomId + ": " + message.Message);
                ScheduleUserLoading(TimeSpan.FromSeconds(30));
            });

            ReceiveAny(x => Stash.Stash());
        }
 protected override void InternalScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
 {
     var cancellationToken = cancelable == null ? CancellationToken.None : cancelable.Token;
     InternalScheduleOnce(delay, () =>
     {
         receiver.Tell(message, sender);
     }, cancellationToken);
 }
Exemplo n.º 3
0
 // ReSharper disable once MemberCanBePrivate.Global - Akka needs it to be public
 public ProxyActor(TestKitBase testKit, ICanTell target)
 {
     IActorRef testActor = testKit.TestActor;
     ReceiveAny(m =>
     {
         if (Sender.Equals(testActor))
             target.Tell(m, Self);
         else
             testActor.Tell(m, Self);
     });
 }
Exemplo n.º 4
0
        protected override void PreStart()
        {
            _roomAccess = Context.ActorOf(Context.DI().Props<RoomAccesActor>().WithRouter(new RoundRobinPool(20)), "roomaccess");
            _messageAccess = Context.ActorOf(Context.DI().Props<RoomMessageActor>().WithRouter(new RoundRobinPool(20)), "messageaccess");
            _signalR = Context.ActorSelection(string.Format(ActorPaths.SignalR.Path, "*"));

            //Self.Tell(new CreateRoomMessage(1, "testi", DateTimeOffset.UtcNow));

            // Schedule lazy room loading 
            ScheduleRoomsUpdateMessage(TimeSpan.FromSeconds(3));
            base.PreStart();
        }
 public static bool OverrideReceiver(INotificationChannel channel, ICanTell receiver)
 {
     var akkaChannel = channel as AkkaReceiverNotificationChannel;
     if (akkaChannel != null)
     {
         akkaChannel.Receiver = receiver;
         return true;
     }
     else
     {
         return false;
     }
 }
Exemplo n.º 6
0
        public RoomMessageActor(IMessageService messageService)
        {
            _messageService = messageService;
            _signalR = Context.ActorSelection(string.Format(ActorPaths.SignalR.Path, "*"));

            Receive<TweetArrivedMessage>(message =>
            {
                var self = Self;

                _messageService.StoreMessageAsync(message.Message).SafelyPipeTo(
                    task => new TweetSavedMessage(task.Result),
                    task => new FailedToSaveTweetMessage(task.Exception?.InnerException),
                    _signalR, self);
            });
        }
Exemplo n.º 7
0
        private void InternalSchedule(TimeSpan? initialDelay, TimeSpan delay, ICanTell receiver, object message, Action action,
            IActorRef sender, ICancelable cancelable, int deliveryCount = 0)
        {
            var scheduledTime = _now.Add(initialDelay ?? delay).UtcTicks;

            Queue<ScheduledItem> tickItems = null;
            if (!_scheduledWork.TryGetValue(scheduledTime, out tickItems))
            {
                tickItems = new Queue<ScheduledItem>();
                _scheduledWork.TryAdd(scheduledTime, tickItems);
            }
            
            var type = message == null ? ScheduledItem.ScheduledItemType.Action : ScheduledItem.ScheduledItemType.Message;

            tickItems.Enqueue(new ScheduledItem(initialDelay ?? delay, delay, type, message, action,
                initialDelay.HasValue || deliveryCount > 0, receiver, sender, cancelable));
        }
Exemplo n.º 8
0
 protected abstract void InternalScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable);
Exemplo n.º 9
0
 protected abstract void InternalScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable);
Exemplo n.º 10
0
 void ITellScheduler.ScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
 {
     ValidateDelay(initialDelay, "initialDelay");
     ValidateInterval(interval, "interval");
     InternalScheduleTellRepeatedly(initialDelay, interval, receiver, message, sender, cancelable);
 }
Exemplo n.º 11
0
 public void ScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICanTell receiver, object message,
                                    IActorRef sender, ICancelable cancelable)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="delay">TBD</param>
 /// <param name="receiver">TBD</param>
 /// <param name="message">TBD</param>
 /// <param name="sender">TBD</param>
 /// <param name="cancelable">TBD</param>
 protected abstract void InternalScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable);
Exemplo n.º 13
0
 public void ScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICanTell receiver, object message,
     IActorRef sender)
 {
     InternalSchedule(initialDelay, interval, receiver, message, null, sender, null);
 }
Exemplo n.º 14
0
 void ITellScheduler.ScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
 {
     ValidateDelay(delay, "delay");
     InternalScheduleTellOnce(delay, receiver, message, sender, cancelable);
 }
Exemplo n.º 15
0
 /// <summary>Schedules to send a message once after a specified period of time.</summary>
 /// <param name="scheduler">The scheduler</param>
 /// <param name="millisecondsDelay">The time in milliseconds that has to pass before the message is sent.</param>
 /// <param name="receiver">The receiver.</param>
 /// <param name="message">The message.</param>
 /// <param name="sender">The sender.</param>
 /// <returns>An <see cref="ICancelable"/> that can be used to cancel sending of the message. Once the message already has been sent, it cannot be cancelled.</returns>
 public static ICancelable ScheduleTellOnceCancelable(this IScheduler scheduler, int millisecondsDelay, ICanTell receiver, object message, IActorRef sender)
 {
     var cancelable = new Cancelable(scheduler);
     scheduler.ScheduleTellOnce(millisecondsDelay, receiver, message, sender, cancelable);
     return cancelable;
 }
Exemplo n.º 16
0
 /// <summary>Schedules to send a message once after a specified period of time.</summary>
 /// <param name="scheduler">The scheduler</param>
 /// <param name="millisecondsDelay">The time in milliseconds that has to pass before the message is sent.</param>
 /// <param name="receiver">The receiver.</param>
 /// <param name="message">The message.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="cancelable">OPTIONAL. An <see cref="ICancelable"/> that can be used to cancel sending of the message. Note that once the message has been sent, it cannot be canceled.</param>
 public static void ScheduleTellOnce(this ITellScheduler scheduler, int millisecondsDelay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable = null)
 {
     scheduler.ScheduleTellOnce(TimeSpan.FromMilliseconds(millisecondsDelay), receiver, message, sender, cancelable);
 }
Exemplo n.º 17
0
        /// <summary>
        /// Handles the PipeTo exception
        /// </summary>
        /// <param name="system">
        /// The actor system.
        /// </param>
        /// <param name="recipient">The recipient of the payload and/or exception </param>
        /// <param name="sender">The sender</param>
        /// <param name="exception">
        /// The exception
        /// </param>
        /// <returns>
        /// Routed object
        /// </returns>
        private object HandlePipedException(ActorSystem system, ICanTell recipient, IActorRef sender, Exception exception)
        {
            exception = this.ExtractException(exception);
            exception.Match()
                .With<ParcelTimeoutException>(
                () =>
                    {
                        var maxNumberOfAttempts = system.Settings.Config.GetInt("ClusterKit.LargeObjects.MaxReadAttempts", 5);
                        if (this.ReceiveAttempt < maxNumberOfAttempts)
                        {
                            var rereadInterval = system.Settings.Config.GetTimeSpan("ClusterKit.LargeObjects.RereadInterval", TimeSpan.FromSeconds(5));
                            system.Scheduler.ScheduleTellOnce(rereadInterval, recipient, this, sender);
                        }
                        else
                        {
                            exception = new ParcelServerErrorException("Server is unresponsive");
                        }
                    });

            return exception;
        }
Exemplo n.º 18
0
 public static Props Props(TestKitBase testKit, ICanTell target)
 {
     return Akka.Actor.Props.Create(() => new ProxyActor(testKit, target));
 }
Exemplo n.º 19
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="initialDelay">TBD</param>
 /// <param name="interval">TBD</param>
 /// <param name="receiver">TBD</param>
 /// <param name="message">TBD</param>
 /// <param name="sender">TBD</param>
 /// <param name="cancelable">TBD</param>
 protected abstract void InternalScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable);
Exemplo n.º 20
0
 protected override void InternalScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender,
     ICancelable cancelable)
 {
     receiver.Tell(message, sender);
 }
Exemplo n.º 21
0
 public AkkaReceiverTarget(ICanTell receiver)
 {
     Receiver = receiver;
 }
Exemplo n.º 22
0
 /// <summary>
 /// Receive parcel's payload and sends it contents to the specified recipient
 /// </summary>
 /// <param name="system">The actor system</param>
 /// <param name="recipient">The recipient of the payload and/or exception </param>
 /// <param name="sender">The sender</param>
 /// <returns>The executing task</returns>
 public virtual Task ReceiveWithPipeTo(ActorSystem system, ICanTell recipient, IActorRef sender)
 {
     return this.Receive(system).PipeTo(
         recipient, 
         sender, 
         failure: e => this.HandlePipedException(system, recipient, sender, e));
 }
 public AkkaReceiverNotificationChannel(ICanTell receiver)
 {
     Receiver = receiver;
 }
Exemplo n.º 24
0
 /// <summary>Schedules to send a message repeatedly. The first message will be sent after the specified initial delay and there after at the rate specified.</summary>
 /// <param name="scheduler">The scheduler</param>
 /// <param name="initialMillisecondsDelay">The time in milliseconds that has to pass before the first message is sent.</param>
 /// <param name="millisecondsInterval">The interval, i.e. the time in milliseconds that has to pass between messages are sent.</param>
 /// <param name="receiver">The receiver.</param>
 /// <param name="message">The message.</param>
 /// <param name="sender">The sender.</param>
 /// <returns>An <see cref="ICancelable"/> that can be used to cancel sending of the message. Once the message already has been sent, it cannot be cancelled.</returns>
 public static ICancelable ScheduleTellRepeatedlyCancelable(this IScheduler scheduler, int initialMillisecondsDelay, int millisecondsInterval, ICanTell receiver, object message, IActorRef sender)
 {
     var cancelable = new Cancelable(scheduler);
     scheduler.ScheduleTellRepeatedly(initialMillisecondsDelay, millisecondsInterval, receiver, message, sender, cancelable);
     return cancelable;
 }
Exemplo n.º 25
0
        public override void Setup()
        {
            base.Setup();
            var c1 = ConfigurationFactory.ParseString(GetConfig());
            var c2 = ConfigurationFactory.ParseString(GetOtherRemoteSysConfig());


            var conf = c2.WithFallback(c1);  //ConfigurationFactory.ParseString(GetOtherRemoteSysConfig());

            remoteSystem = ActorSystem.Create("remote-sys", conf);
            Deploy(sys, new Deploy(@"/gonk", new RemoteScope(Addr(remoteSystem, "tcp"))));
            Deploy(sys, new Deploy(@"/zagzag", new RemoteScope(Addr(remoteSystem, "udp"))));

            remote = remoteSystem.ActorOf(Props.Create<Echo2>(), "echo");
            here = sys.ActorSelection("akka.test://remote-sys@localhost:12346/user/echo");
        }
Exemplo n.º 26
0
 /// <summary>Schedules to send a message repeatedly. The first message will be sent after the specified initial delay and there after at the rate specified.</summary>
 /// <param name="scheduler">The scheduler</param>
 /// <param name="initialMillisecondsDelay">The time in milliseconds that has to pass before the first message is sent.</param>
 /// <param name="millisecondsInterval">The interval, i.e. the time in milliseconds that has to pass between messages are being sent.</param>
 /// <param name="receiver">The receiver.</param>
 /// <param name="message">The message.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="cancelable">OPTIONAL. An <see cref="ICancelable"/> that can be used to cancel sending of the message. Note that once the message has been sent, it cannot be canceled.</param>
 public static void ScheduleTellRepeatedly(this ITellScheduler scheduler, int initialMillisecondsDelay, int millisecondsInterval, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable = null)
 {
     scheduler.ScheduleTellRepeatedly(TimeSpan.FromMilliseconds(initialMillisecondsDelay), TimeSpan.FromMilliseconds(millisecondsInterval), receiver, message, sender, cancelable);
 }
Exemplo n.º 27
0
 protected override void InternalScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender,
     ICancelable cancelable)
 {
     InternalSchedule(delay, TimeSpan.Zero, new ScheduledTell(receiver, message, sender), cancelable);
 }
Exemplo n.º 28
0
 public ScheduledItem(TimeSpan initialDelay, TimeSpan delay, ScheduledItemType type, object message, Action action, bool repeating, ICanTell receiver, 
     IActorRef sender, ICancelable cancelable)
 {
     InitialDelay = initialDelay;
     Delay = delay;
     Type = type;
     Message = message;
     Action = action;
     Repeating = repeating;
     Receiver = receiver;
     Sender = sender;
     Cancelable = cancelable;
     DeliveryCount = 0;
 }
Exemplo n.º 29
0
 protected override void InternalScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICanTell receiver, object message,
     IActorRef sender, ICancelable cancelable)
 {
     InternalSchedule(initialDelay, interval, new ScheduledTell(receiver, message, sender), cancelable);
 }
Exemplo n.º 30
0
 public void ScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
 {
     InternalSchedule(null, delay, receiver, message, null, sender, cancelable);
 }
Exemplo n.º 31
0
 public ScheduledTell(ICanTell receiver, object message, IActorRef sender)
 {
     _receiver = receiver;
     _message = message;
     _sender = sender;
 }
Exemplo n.º 32
0
 protected override void PreStart()
 {
     _signalR = ActorSystemContext.SignalUser;
     base.PreStart();
     _log.Info("UserManagerActor up and running");
 }
Exemplo n.º 33
0
 void ITellScheduler.ScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
 {
     ValidateDelay(delay, "delay");
     InternalScheduleTellOnce(delay, receiver, message, sender, cancelable);
 }
 protected override void InternalScheduleTellRepeatedly(TimeSpan initialDelay, TimeSpan interval, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
 {
     var cancellationToken = cancelable == null ? CancellationToken.None : cancelable.Token;
     InternalScheduleRepeatedly(initialDelay, interval, () => receiver.Tell(message, sender), cancellationToken);
 }
Exemplo n.º 35
0
 public void ScheduleTellOnce(TimeSpan delay, ICanTell receiver, object message, IActorRef sender, ICancelable cancelable)
 {
     throw new NotImplementedException();
 }