// $Id$ // // Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, // software distributed under the License is distributed on an // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. // using System; using Org.Apache.Etch.Bindings.Csharp.Msg; using Org.Apache.Etch.Bindings.Csharp.Util; namespace Org.Apache.Etch.Bindings.Csharp.Support { /// An interface used to deliver responses to a message. Support for the mechanism is somewhat /// dependent upon properties of the transport and message format. /// public interface Mailbox { /// the message id of this mailbox. long GetMessageId(); /// the next message to be read from the mailbox, or null if the mailbox is empty and closed. /// Wait forever for such a message to be delivered. /// Exception: /// throws InterruptedException thread interrupt. Element Read(); /// maxDelay the maximum amount of time in milliseconds to wait to read a message /// from an empty mailbox. 0 means wait forever, -1 means don't wait at all. /// the message read from the mailbox, or null if the mailbox is empty and closed, or if the time /// limit was exceeeded. /// Exception: /// throws InterruptedException thread interrupt. Element Read(int maxDelay); /// Closes the mailbox so that no more messages can be delivered. Queued messages remain to be read. /// Reading an empty closed mailbox returns null. /// true if this call closed the mailbox (that is, if action was taken), false if the mailbox was already closed. bool CloseDelivery(); /// Closes the mailbox so that no more messages will be delivered or read. Any remaining queued /// messages are delivered to a default handler. /// throws Exception bool CloseRead(); ///Registers a Notify interface implementation to receive a callback ///when a mailbox's status is changed. /// newNotify a Notify interface implementation to report the ///delivery status to. /// state a state value to pass thru to the Notify interface /// implementation. /// maxDelay the maximum amount of time in milliseconds to ///wait for delivery of a message to the mailbox. 0 means wait ///forever. The mailbox is closed upon timeout. void RegisterNotify( Notify newNotify, Object state, int maxDelay ); /// Unregisters a Notify interface implementation from receiving a callback /// when a mailbox's status is changed. Cancels any timeout. /// oldNotify a Notify interface implementation which was previously ///registered. void UnregisterNotify( Notify oldNotify ); bool Message(Who sender, Message msg); } ///The message as queued, including src and sender. public class Element : Who { /// sender the message sender. /// msg the message. public Element(Who sender, Message msg) { this.sender = sender; this.msg = msg; } /// The message sender. public Who sender; /// the message. public Message msg; } public interface Notify { /// Notifies of mailbox status change. /// mb the mailbox whose status has changed. /// state the state object passed in the register /// method. /// closed true if the mailbox timeout has expired and ///the mailbox is now closed to delivery, false if a message /// has arrived. void mailboxStatus(Mailbox mb, Object state, bool closed); } }