Provides a simple mechanism for exchanging messages with Erlang processes or other instances of this class.
Each mailbox is associated with a unique {@link OtpErlangPid pid} thatcontains information necessary for delivery of messages. When sending messages to named processes or mailboxes, the sender pid is made available to the recipient of the message. When sending messages to other mailboxes, the recipient can only respond if the sender includes the pid as part of the message contents. The sender can determine his own pid by calling {@link #self() self()}.
Mailboxes can be named, either at creation or later. Messages can be sent to named mailboxes and named Erlang processes without knowing the {@link OtpErlangPid pid} that identifies the mailbox. This is neccessary inorder to set up initial communication between parts of an application. Each mailbox can have at most one name.
Since this class was intended for communication with Erlang, all of the send methods take {@link OtpErlangObject OtpErlangObject} arguments. However thisclass can also be used to transmit arbitrary Java objects (as long as they implement one of java.io.Serializable or java.io.Externalizable) by encapsulating the object in a {@link OtpErlangBinary OtpErlangBinary}.
Messages to remote nodes are externalized for transmission, and as a result the recipient receives a copy of the original Java object. To ensure consistent behaviour when messages are sent between local mailboxes, such messages are cloned before delivery.
Additionally, mailboxes can be linked in much the same way as Erlang processes. If a link is active when a mailbox is {@link #close closed}, any linked Erlang processes or OtpMboxes will be sent an exit signal. As well, exit signals will be (eventually) sent if a mailbox goes out of scope and its {@link #finalize finalize()} method called. However due to the nature offinalization (i.e. Java makes no guarantees about when {@link #finalize finalize()} will be called) it is recommended that you always explicitlyclose mailboxes if you are using links instead of relying on finalization to notify other parties in a timely manner.
When retrieving messages from a mailbox that has received an exit signal, an {@link OtpErlangExit OtpErlangExit} exception will be raised. Note that theexception is queued in the mailbox along with other messages, and will not be raised until it reaches the head of the queue and is about to be retrieved.
|
|
|
|
|
|
|
|