Package ucb.util.mailbox
Class Rendezvous<Msg extends Serializable>
- java.lang.Object
-
- java.rmi.server.RemoteObject
-
- java.rmi.server.RemoteServer
-
- java.rmi.server.UnicastRemoteObject
-
- ucb.util.mailbox.Rendezvous<Msg>
-
- All Implemented Interfaces:
Serializable
,Remote
,Mailbox<Msg>
public class Rendezvous<Msg extends Serializable> extends UnicastRemoteObject
A Mailbox with a capacity of 0. A depositer must wait until his message is received.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Msg
msg
protected boolean
open
-
Fields inherited from class java.rmi.server.RemoteObject
ref
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Rendezvous(Class<Msg> msgClass)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
awaitClose()
Wait for THIS to be closed.boolean
awaitClose(long millis)
Wait for THIS to be closed, or MILLIS milliseconds, whichever comes first.int
capacity()
The capacity (see interface comment above) of THIS.<T extends Serializable>
Mailbox<T>checkType(Class<T> msgClass)
Returns THIS, assuming that THIS conveys messages of class MSGCLASS.void
close()
Short for close (0).void
close(long millis)
Performs a flush(MILLIS) and then invalidates THIS for all future use, deleting all remaining messages.static <Msg extends Serializable>
Rendezvous<Msg>create()
A new Rendezvous for messages of unchecked type.static <Msg extends Serializable>
Rendezvous<Msg>create(Class<Msg> msgClass)
A new Rendezvous for messages of type MSGCLASS.void
deposit(Msg msg)
Deposit MSG in this Mailbox.boolean
deposit(Msg msg, long millis)
Deposit MSG in this Mailbox, if this can be done within approximately MILLIS milliseconds.boolean
flush(long millis)
Wait for any queued message to be received, or MILLIS milliseconds, whichever comes first.protected void
forward(Msg msg, long millis)
void
forwardTo(List<Mailbox<Msg>> boxes)
Forward copies of all messages (including any already present) to BOXES in the order received.void
forwardTo(Mailbox<Msg> box)
Forward copies of all messages (including any already present) to BOXES in the order received.boolean
isClosed()
True iff THIS is closed.boolean
isForwarding()
True iff THIS is currently forwarding messages as a result of forwardTo.Class<Msg>
messageType()
The (runtime) type of message sent through this box.protected long
myWait(long limit)
Msg
receive()
Receive the next queued message in this Mailbox.Msg
receive(long millis)
Receive the next queued message in this Mailbox, if one is available within MILLIS milliseconds.void
stopForwarding()
Stop forwarding copies of messages.-
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, exportObject, exportObject, unexportObject
-
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
-
-
-
-
Field Detail
-
msg
protected Msg extends Serializable msg
-
open
protected boolean open
-
-
Constructor Detail
-
Rendezvous
protected Rendezvous(Class<Msg> msgClass) throws RemoteException
- Throws:
RemoteException
-
-
Method Detail
-
create
public static <Msg extends Serializable> Rendezvous<Msg> create(Class<Msg> msgClass)
A new Rendezvous for messages of type MSGCLASS.
-
create
public static <Msg extends Serializable> Rendezvous<Msg> create()
A new Rendezvous for messages of unchecked type.
-
deposit
public void deposit(Msg msg) throws InterruptedException, RemoteException
Deposit MSG in this Mailbox. If the Mailbox is full, wait if necessary for space to be available. MSG must be non-null. Throws Interrupted exception and does nothing if current thread is interrupted.- Throws:
InterruptedException
RemoteException
-
deposit
public boolean deposit(Msg msg, long millis) throws InterruptedException, RemoteException
Deposit MSG in this Mailbox, if this can be done within approximately MILLIS milliseconds. Returns true iff the message was deposited. Does not block if MILLIS is 0. MSG must be non-null. Throws Interrupted exception and does nothing if current thread is interrupted.- Throws:
InterruptedException
RemoteException
-
receive
public Msg receive() throws InterruptedException
Receive the next queued message in this Mailbox. Throws Interrupted exception and does nothing if current thread is interrupted.- Throws:
InterruptedException
-
receive
public Msg receive(long millis) throws InterruptedException
Receive the next queued message in this Mailbox, if one is available within MILLIS milliseconds. Returns null otherwise. Does not block if MILLIS is 0. Throws Interrupted exception and does nothing if current thread is interrupted.- Throws:
InterruptedException
-
forwardTo
public void forwardTo(Mailbox<Msg> box) throws InterruptedException, RemoteException
Forward copies of all messages (including any already present) to BOXES in the order received. Once forwarded to all destinations, messages are otherwise treated as usual. Deposit blocks until all forwarding is complete.- Throws:
InterruptedException
RemoteException
-
forwardTo
public void forwardTo(List<Mailbox<Msg>> boxes) throws InterruptedException, RemoteException
Description copied from interface:Mailbox
Forward copies of all messages (including any already present) to BOXES in the order received. Once forwarded to all destinations, messages are otherwise treated as usual. Deposit blocks until all forwarding is complete.- Throws:
InterruptedException
RemoteException
-
stopForwarding
public void stopForwarding()
Stop forwarding copies of messages.
-
flush
public boolean flush(long millis) throws InterruptedException
Wait for any queued message to be received, or MILLIS milliseconds, whichever comes first. Returns true if all pending messages were flushed within the time limit.- Throws:
InterruptedException
-
close
public void close(long millis) throws InterruptedException
Performs a flush(MILLIS) and then invalidates THIS for all future use, deleting all remaining messages. Any waiting threads or subsequent calls receive an immediate InvalidStateException indicating an invalid state. In general, the thread that uses a Mailbox to send messages is the one that closes it.- Throws:
InterruptedException
-
close
public void close() throws InterruptedException
Short for close (0).- Throws:
InterruptedException
-
awaitClose
public void awaitClose() throws InterruptedException
Wait for THIS to be closed. Receives and throws away any messages sent to THIS. Throws InterruptedException if current thread is interrupted first.- Throws:
InterruptedException
-
awaitClose
public boolean awaitClose(long millis) throws InterruptedException
Wait for THIS to be closed, or MILLIS milliseconds, whichever comes first. Receives and throws away any messages sent to THIS. Returns true iff box is closed. Throws InterruptedException if current thread is interrupted first.- Throws:
InterruptedException
-
isForwarding
public boolean isForwarding()
True iff THIS is currently forwarding messages as a result of forwardTo.
-
isClosed
public boolean isClosed()
Description copied from interface:Mailbox
True iff THIS is closed.
-
capacity
public int capacity()
The capacity (see interface comment above) of THIS.
-
forward
protected void forward(Msg msg, long millis) throws RemoteException, InterruptedException
- Throws:
RemoteException
InterruptedException
-
myWait
protected long myWait(long limit) throws InterruptedException
- Throws:
InterruptedException
-
messageType
public Class<Msg> messageType()
Description copied from interface:Mailbox
The (runtime) type of message sent through this box.- Specified by:
messageType
in interfaceMailbox<Msg extends Serializable>
-
checkType
public <T extends Serializable> Mailbox<T> checkType(Class<T> msgClass)
Description copied from interface:Mailbox
Returns THIS, assuming that THIS conveys messages of class MSGCLASS.- Specified by:
checkType
in interfaceMailbox<Msg extends Serializable>
-
-