public void Enqueue(IActorRef receiver, Envelope envelope) { if (!_queue.TryAdd(envelope, PushTimeOut)) // dump messages that can't be delivered in-time into DeadLetters { receiver.AsInstanceOf<IInternalActorRef>().Provider.DeadLetters.Tell(new DeadLetter(envelope.Message, envelope.Sender, receiver), envelope.Sender); } }
/// <summary> /// Invokes the specified envelope. /// </summary> /// <param name="envelope">The envelope.</param> public void Invoke(Envelope envelope) { var message = envelope.Message; CurrentMessage = message; _currentEnvelopeId ++; Sender = MatchSender(envelope); try { var autoReceivedMessage = message as IAutoReceivedMessage; if (autoReceivedMessage != null) AutoReceiveMessage(envelope); else ReceiveMessage(message); CurrentMessage = null; } catch (Exception cause) { HandleInvokeFailure(cause); } finally { CheckReceiveTimeout(); // Reschedule receive timeout } }
/// <summary> /// Directly inject messages into actor receive behavior. Any exceptions /// thrown will be available to you, while still being able to use /// become/unbecome. /// </summary> /// <param name="message">The message.</param> /// <param name="sender">The sender.</param> public void Receive(object message, IActorRef sender = null) { var cell = Cell; sender = sender.IsNobody() ? cell.System.DeadLetters : sender; var envelope = new Envelope { Message = message, Sender = sender }; cell.UseThreadContext(() => cell.ReceiveMessageForTest(envelope)); }
protected override bool LockedTryDequeue(out Envelope envelope) { if (_prioQueue.Count() > 0) { envelope = _prioQueue.Dequeue(); return true; } envelope = default (Envelope); return false; }
public void Enqueue(IActorRef receiver, Envelope envelope) { if (envelope.Message is DeadLetter) { // actor subscribing to DeadLetter. Drop it. return; } _deadLetters.Tell(new DeadLetter(envelope.Message, envelope.Sender, receiver), envelope.Sender); }
/// <summary> /// Attempt to dequeue a message from the front of the prepend buffer. /// /// If the prepend buffer is empty, dequeue a message from the normal /// <see cref="MessageQueue"/> wrapped but this wrapper. /// </summary> /// <param name="envelope">The message to return, if any</param> /// <returns><c>true</c> if a message was available, <c>false</c> otherwise.</returns> public bool TryDequeue(out Envelope envelope) { if (_prependBuffer.Count > 0) { envelope = _prependBuffer.Pop(); return true; } return _messageQueue.TryDequeue(out envelope); }
public override void SendMessage(Envelope envelope) { if(!(RouterConfig.IsManagementMessage(envelope.Message)) && resizer.IsTimeForResize(_resizeCounter.GetAndIncrement()) && _resizeInProgress.CompareAndSet(false, true)) { base.SendMessage(new Envelope(new Resize(), Self, System)); } base.SendMessage(envelope); }
public void Enqueue(Envelope envelope) { if (PushTimeOut.Milliseconds >= 0) { _queue.TryAdd(envelope, PushTimeOut); } else { _queue.Add(envelope); } }
public bool TryDequeue(out Envelope envelope) { Monitor.TryEnter(_lock, BlockTimeOut); try { return LockedTryDequeue(out envelope); } finally { Monitor.Exit(_lock); } }
public void Enqueue(Envelope envelope) { Monitor.TryEnter(_lock, BlockTimeOut); try { LockedEnqueue(envelope); } finally { Monitor.Exit(_lock); } }
public void Enqueue(Envelope item) { _data.Add(item); var ci = _data.Count - 1; // child index; start at end while (ci > 0) { var pi = (ci - 1) / 2; // parent index if (_priorityCalculator(_data[ci].Message).CompareTo(_priorityCalculator(_data[pi].Message)) >= 0) break; // child item is larger than (or equal) parent so we're done var tmp = _data[ci]; _data[ci] = _data[pi]; _data[pi] = tmp; ci = pi; } }
/// <summary> /// Invokes the specified envelope. /// </summary> /// <param name="envelope">The envelope.</param> public void Invoke(Envelope envelope) { CurrentMessage = envelope.Message; Sender = envelope.Sender; //set the current context try { AutoReceiveMessage(envelope); } catch (Exception cause) { Parent.Tell(new Failed(Self, cause)); } }
/* def autoReceiveMessage(msg: Envelope): Unit = { if (system.settings.DebugAutoReceive) publish(Debug(self.path.toString, clazz(actor), "received AutoReceiveMessage " + msg)) msg.message match { case t: Terminated ⇒ receivedTerminated(t) case AddressTerminated(address) ⇒ addressTerminated(address) case Kill ⇒ throw new ActorKilledException("Kill") case PoisonPill ⇒ self.stop() case sel: ActorSelectionMessage ⇒ receiveSelection(sel) case Identify(messageId) ⇒ sender() ! ActorIdentity(messageId, Some(self)) } } */ protected virtual void AutoReceiveMessage(Envelope envelope) { var message = envelope.Message; var actor = _actor; var actorType = actor != null ? actor.GetType() : null; if (System.Settings.DebugAutoReceive) Publish(new Debug(Self.Path.ToString(), actorType, "received AutoReceiveMessage " + message)); var m = envelope.Message; if (m is Terminated) ReceivedTerminated(m as Terminated); else if (m is AddressTerminated) AddressTerminated((m as AddressTerminated).Address); else if (m is Kill) Kill(); else if (m is PoisonPill) HandlePoisonPill(); else if (m is ActorSelectionMessage) ReceiveSelection(m as ActorSelectionMessage); else if (m is Identify) HandleIdentity(m as Identify); }
/* def autoReceiveMessage(msg: Envelope): Unit = { if (system.settings.DebugAutoReceive) publish(Debug(self.path.toString, clazz(actor), "received AutoReceiveMessage " + msg)) msg.message match { case t: Terminated ⇒ receivedTerminated(t) case AddressTerminated(address) ⇒ addressTerminated(address) case Kill ⇒ throw new ActorKilledException("Kill") case PoisonPill ⇒ self.stop() case sel: ActorSelectionMessage ⇒ receiveSelection(sel) case Identify(messageId) ⇒ sender() ! ActorIdentity(messageId, Some(self)) } } */ protected virtual void AutoReceiveMessage(Envelope envelope) { var message = envelope.Message; var actor = _actor; var actorType = actor != null ? actor.GetType() : null; if(System.Settings.DebugAutoReceive) Publish(new Debug(Self.Path.ToString(), actorType, "received AutoReceiveMessage " + message)); envelope.Message .Match() .With<Terminated>(ReceivedTerminated) .With<AddressTerminated>(a => AddressTerminated(a.Address)) .With<Kill>(Kill) .With<PoisonPill>(HandlePoisonPill) .With<ActorSelectionMessage>(ReceiveSelection) .With<Identify>(HandleIdentity); }
public override void Post(IActorRef receiver, Envelope envelope) { var message = envelope.Message; if(message is ISystemMessage) { Mailbox.DebugPrint("DeadLetterMailbox forwarded system message " + envelope+ " as a DeadLetter"); _deadLetters.Tell(new DeadLetter(message, receiver, receiver), receiver); } else if(message is DeadLetter) { //Just drop it like it's hot Mailbox.DebugPrint("DeadLetterMailbox dropped DeadLetter " + envelope); } else { Mailbox.DebugPrint("DeadLetterMailbox forwarded message " + envelope + " as a DeadLetter"); var sender = envelope.Sender; _deadLetters.Tell(new DeadLetter(message, sender, receiver),sender); } }
public override void Post(Envelope envelope) { var message = envelope.Message; if(message is SystemMessage) { Mailbox.DebugPrint("DeadLetterMailbox forwarded system message " + envelope+ " as a DeadLetter"); _deadLetters.Tell(new DeadLetter(message, _deadLetters, _deadLetters), _deadLetters);//TODO: When we have refactored Post to SystemEnqueue(ActorRef receiver, Envelope envelope), replace _deadLetters with receiver } else if(message is DeadLetter) { //Just drop it like it's hot Mailbox.DebugPrint("DeadLetterMailbox dropped DeadLetter " + envelope); } else { Mailbox.DebugPrint("DeadLetterMailbox forwarded message " + envelope + " as a DeadLetter"); var sender = envelope.Sender; _deadLetters.Tell(new DeadLetter(message,sender,_deadLetters),sender);//TODO: When we have refactored Post to Enqueue(ActorRef receiver, Envelope envelope), replace _deadLetters with receiver } }
/// <summary> /// Invokes the specified envelope. /// </summary> /// <param name="envelope">The envelope.</param> /// <exception cref="ActorKilledException"> /// This exception is thrown if a <see cref="Akka.Actor.Kill"/> message is included in the given <paramref name="envelope"/>. /// </exception>> public void Invoke(Envelope envelope) { var message = envelope.Message; var influenceReceiveTimeout = !(message is INotInfluenceReceiveTimeout); try { // Akka JVM doesn't have these lines CurrentMessage = envelope.Message; _currentEnvelopeId++; Sender = MatchSender(envelope); if (influenceReceiveTimeout) { CancelReceiveTimeout(); } if (message is IAutoReceivedMessage) { AutoReceiveMessage(envelope); } else { ReceiveMessage(message); } CurrentMessage = null; } catch (Exception cause) { HandleInvokeFailure(cause); } finally { if (influenceReceiveTimeout) { CheckReceiveTimeout(); // Reschedule receive timeout } } }
/// <summary> /// Invokes the specified envelope. /// </summary> /// <param name="envelope">The envelope.</param> public void Invoke(Envelope envelope) { var message = envelope.Message; CurrentMessage = message; Sender = envelope.Sender; try { var autoReceivedMessage = message as AutoReceivedMessage; if(autoReceivedMessage!=null) AutoReceiveMessage(envelope); else ReceiveMessage(message); } catch(Exception cause) { Mailbox.Suspend(); Parent.Tell(new Failed(Self, cause)); } }
protected override void LockedEnqueue(Envelope envelope) { _prioQueue.Enqueue(envelope); }
/// <summary> /// Systems the invoke. /// </summary> /// <param name="envelope">The envelope.</param> public void SystemInvoke(Envelope envelope) { try { var m = envelope.Message; if (m is CompleteTask) HandleCompleteTask(m as CompleteTask); else if (m is Failed) HandleFailed(m as Failed); else if (m is DeathWatchNotification) { var msg = m as DeathWatchNotification; WatchedActorTerminated(msg.Actor, msg.ExistenceConfirmed, msg.AddressTerminated); } else if (m is Create) HandleCreate((m as Create).Failure); else if (m is Watch) { var watch = m as Watch; AddWatcher(watch.Watchee, watch.Watcher); } else if (m is Unwatch) { var unwatch = m as Unwatch; RemWatcher(unwatch.Watchee, unwatch.Watcher); } else if (m is Recreate) FaultRecreate((m as Recreate).Cause); else if (m is Suspend) FaultSuspend(); else if (m is Resume) FaultResume((m as Resume).CausedByFailure); else if (m is Terminate) Terminate(); else if (m is Supervise) { var supervise = m as Supervise; Supervise(supervise.Child, supervise.Async); } else { throw new NotSupportedException("Unknown message " + m.GetType().Name); } } catch (Exception cause) { HandleInvokeFailure(cause); } }
/// <summary> /// If the envelope.Sender property is null, then we'll substitute /// Deadletters as the <see cref="Sender"/> of this message. /// </summary> /// <param name="envelope">The envelope we received</param> /// <returns>An IActorRef that corresponds to a Sender</returns> private IActorRef MatchSender(Envelope envelope) { var sender = envelope.Sender; return sender ?? System.DeadLetters; }
/// <summary> /// Posts the specified envelope to the mailbox. /// </summary> /// <param name="receiver"></param> /// <param name="envelope">The envelope.</param> public abstract void Post(ActorRef receiver, Envelope envelope);
/// <summary> /// This is only intended to be called from TestKit's TestActorRef /// </summary> /// <param name="envelope"></param> public void ReceiveMessageForTest(Envelope envelope) { var message = envelope.Message; CurrentMessage = message; Sender = envelope.Sender; try { ReceiveMessage(message); } finally { CurrentMessage = null; Sender = System.DeadLetters; } }
public bool TryDequeue(out Envelope envelope) { return _queue.TryDequeue(out envelope); }
public void Enqueue(Envelope envelope) { _queue.Enqueue(envelope); }
/// <summary> /// Posts the specified envelope to the mailbox. /// </summary> /// <param name="envelope">The envelope.</param> public abstract void Post(Envelope envelope);
/// <summary> /// Systems the invoke. /// </summary> /// <param name="envelope">The envelope.</param> public void SystemInvoke(Envelope envelope) { try { envelope .Message .Match() .With<CompleteFuture>(HandleCompleteFuture) .With<Failed>(HandleFailed) .With<DeathWatchNotification>(m => WatchedActorTerminated(m.Actor, m.ExistenceConfirmed, m.AddressTerminated)) .With<Create>(m => HandleCreate(m.Failure)) //TODO: see """final def init(sendSupervise: Boolean, mailboxType: MailboxType): this.type = {""" in dispatch.scala //case Create(failure) ⇒ create(failure) .With<Watch>(m => AddWatcher(m.Watchee, m.Watcher)) .With<Unwatch>(m => RemWatcher(m.Watchee, m.Watcher)) .With<Recreate>(m => FaultRecreate(m.Cause)) .With<Suspend>(m => FaultSuspend()) .With<Resume>(m => FaultResume(m.CausedByFailure)) .With<Terminate>(Terminate) .With<Supervise>(s => Supervise(s.Child, s.Async)) .Default(m => { throw new NotSupportedException("Unknown message " + m.GetType().Name); }); } catch (Exception cause) { HandleInvokeFailure(cause); } }
public override void SendMessage(Envelope envelope) { if (RouterConfig.IsManagementMessage(envelope.Message)) base.SendMessage(envelope); else Router.Route(envelope.Message, envelope.Sender); }
/// <summary> /// Posts the specified envelope. /// </summary> /// <param name="receiver"></param> /// <param name="envelope"> The envelope. </param> public override void Post(IActorRef receiver, Envelope envelope) { if (_isClosed) return; hasUnscheduledMessages = true; if (envelope.Message is ISystemMessage) { Mailbox.DebugPrint("{0} enqueued system message {1} to {2}", ActorCell.Self, envelope, ActorCell.Self.Equals(receiver) ? "itself" : receiver.ToString()); _systemMessages.Enqueue(envelope); } else { Mailbox.DebugPrint("{0} enqueued message {1} to {2}", ActorCell.Self, envelope, ActorCell.Self.Equals(receiver) ? "itself" : receiver.ToString()); _userMessages.Enqueue(envelope); } Schedule(); }
public virtual void Post(IActorRef sender, object message) { if (Mailbox == null) { return; //stackoverflow if this is the deadletters actorref //this._systemImpl.DeadLetters.Tell(new DeadLetter(message, sender, this.Self)); } if (_systemImpl.Settings.SerializeAllMessages && !(message is INoSerializationVerificationNeeded)) { Serializer serializer = _systemImpl.Serialization.FindSerializerFor(message); byte[] serialized = serializer.ToBinary(message); object deserialized = _systemImpl.Serialization.Deserialize(serialized, serializer.Identifier, message.GetType()); message = deserialized; } var m = new Envelope { Sender = sender, Message = message, }; Mailbox.Post(Self, m); }