public void ProposeDrain(LocalMailbox mailbox)
 {
     if (this.scheduler.ProposeDrain(mailbox))
     {
         mailbox.Drain();
     }
 }
        public PostOfficeChannel(StageOutput <S, T> sendBundle, StageInput <S, T> recvBundle, Action <S[], int[], int> routingHashcodeFunction, NetworkChannel networkChannel, int channelId, Channel.Flags flags)
        {
            if ((flags & Channel.Flags.SpillOnRecv) == Channel.Flags.SpillOnRecv)
            {
                throw new Exception("SpillingLocalMailbox not currently supported");
            }

            this.sendBundle = sendBundle;
            this.recvBundle = recvBundle;
            this.channelID  = channelId;

            var computation = sendBundle.ForStage.InternalComputation;

            // populate mailboxes; [proxy] destinations for sent messages.
            this.mailboxes = new Mailbox <S, T> [recvBundle.ForStage.Placement.Count];
            foreach (VertexLocation loc in recvBundle.ForStage.Placement)
            {
                if (loc.ProcessId == computation.Controller.Configuration.ProcessID)
                {
                    var postOffice     = this.recvBundle.GetPin(loc.VertexId).Vertex.Scheduler.State(computation).PostOffice;
                    var progressBuffer = new Runtime.Progress.ProgressUpdateBuffer <T>(this.ChannelId, this.recvBundle.GetPin(loc.VertexId).Vertex.Scheduler.State(computation).Producer);

                    LocalMailbox <S, T> localMailbox = new LocalMailbox <S, T>(postOffice, this.recvBundle.GetPin(loc.VertexId), channelID, loc.VertexId, progressBuffer);

                    this.mailboxes[loc.VertexId] = localMailbox;

                    postOffice.RegisterMailbox(localMailbox);
                    if (networkChannel != null)
                    {
                        networkChannel.RegisterMailbox(localMailbox);
                    }
                }
                else
                {
                    this.mailboxes[loc.VertexId] = new RemoteMailbox <S, T>(this.channelID, loc.ProcessId, loc.VertexId, sendBundle.ForStage.InternalComputation);
                }
            }

            // populate postboxes; collection points for each local worker.
            this.postboxes = new Dictionary <int, Postbox <S, T> >();
            foreach (VertexLocation location in sendBundle.ForStage.Placement)
            {
                if (location.ProcessId == sendBundle.ForStage.InternalComputation.Controller.Configuration.ProcessID)
                {
                    var progressBuffer = new Runtime.Progress.ProgressUpdateBuffer <T>(this.ChannelId, this.sendBundle.GetFiber(location.VertexId).Vertex.Scheduler.State(computation).Producer);

                    // determine type of postbox to use.
                    if (routingHashcodeFunction == null)
                    {
                        this.postboxes[location.VertexId] = new NoHashCodePostbox <S, T>(this.channelID, this.sendBundle.GetFiber(location.VertexId), this.recvBundle, this.mailboxes, networkChannel, progressBuffer);
                    }
                    else
                    {
                        this.postboxes[location.VertexId] = new BufferingPostbox <S, T>(this.channelID, this.sendBundle.GetFiber(location.VertexId), this.recvBundle, this.mailboxes, routingHashcodeFunction, networkChannel, progressBuffer);
                    }
                }
            }
        }
 public void RegisterMailbox(LocalMailbox mailbox)
 {
     this.mailboxes.Add(mailbox);
 }