Package ucb.util.mailbox
Class QueuedMailbox<Msg extends Serializable>
java.lang.Object
java.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
ucb.util.mailbox.QueuedMailbox<Msg>
- All Implemented Interfaces:
Serializable
,Remote
,Mailbox<Msg>
- Direct Known Subclasses:
SinkBox
A Mailbox with a specified (positive) capacity
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected int
protected boolean
protected final LinkedList<Msg>
Fields inherited from class java.rmi.server.RemoteObject
ref
-
Constructor Summary
ModifierConstructorDescriptionprotected
QueuedMailbox
(Class<Msg> msgClass, int capacity) A new QueuedMailbox with given CAPACITY carrying messages of type MSGCLASS. -
Method Summary
Modifier and TypeMethodDescriptionint
capacity()
The capacity (see interface comment above) of THIS.<T extends Serializable>
Mailbox<T>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>
QueuedMailbox<Msg>create
(int capacity) A new QueuedMailbox with capacity () fixed at CAPACITY, with no type checking.static <Msg extends Serializable>
QueuedMailbox<Msg>A new QueuedMailboxwith capacity () fixed at CAPACITY. void
Deposit MSG in this Mailbox.boolean
Deposit MSG in this Mailbox, if this can be done within approximately MILLIS milliseconds.protected void
Place MSG at the end of the message queue.boolean
flush
(long millis) Wait for all queued messages to be received, or MILLIS milliseconds, whichever comes first.protected void
Perform forwarding of MSG to all recipients, waiting for up to MILLIS milliseconds for each deposit to be accepted.void
Forward copies of all messages (including any already present) to BOXES in the order received.void
Forward copies of all messages (including any already present) to BOXES in the order received.boolean
isClosed()
True iff THIS is closed.boolean
True iff THIS is currently forwarding messages as a result of forwardTo.The (runtime) type of message sent through this box.protected long
myWait
(long limit) Wait for up to LIMIT milliseconds or the next notify or interrupt.receive()
Receive the next queued message in this Mailbox.receive
(long millis) Receive the next queued message in this Mailbox, if one is available within MILLIS milliseconds.void
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 Details
-
queue
-
capacity
protected int capacity -
open
protected boolean open -
depositBlocks
protected int depositBlocks
-
-
Constructor Details
-
QueuedMailbox
A new QueuedMailbox with given CAPACITY carrying messages of type MSGCLASS. The factory method create, rather than this constructor, is intended for public use.- Throws:
RemoteException
-
-
Method Details
-
create
public static <Msg extends Serializable> QueuedMailbox<Msg> create(Class<Msg> msgClass, int capacity) A new QueuedMailboxwith capacity () fixed at CAPACITY. -
create
A new QueuedMailbox with capacity () fixed at CAPACITY, with no type checking. -
deposit
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 an IllegalStateException (or RemoteException) if THIS is closed. Throws IllegalArgumentException if MSG is null.- Throws:
InterruptedException
RemoteException
-
deposit
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 IllegalStateException (or RemoteException) if THIS is closed. Throws IllegalArgumentException if MSG is null.- Throws:
InterruptedException
RemoteException
-
receive
Receive the next queued message in this Mailbox. Returns null if THIS is closed. Throws Interrupted exception and does nothing if the current thread is interrupted.- Throws:
InterruptedException
-
receive
Receive the next queued message in this Mailbox, if one is available within MILLIS milliseconds. Returns null otherwise, including if THIS is closed. Does not block if MILLIS is 0. Throws Interrupted exception and does nothing if current thread is interrupted.- Throws:
InterruptedException
-
forwardTo
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
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
Wait for all queued messages to be received, or MILLIS milliseconds, whichever comes first. During this wait, the Mailbox acts as if full from the point of view of all threads attempting to deposit. Returns true if all messages were flushed within the time limit.- Throws:
InterruptedException
-
close
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
Short for close (0).- Throws:
InterruptedException
-
isForwarding
public boolean isForwarding()True iff THIS is currently forwarding messages as a result of forwardTo. -
isClosed
public boolean isClosed()True iff THIS is closed. -
capacity
public int capacity()The capacity (see interface comment above) of THIS. -
enqueue
Place MSG at the end of the message queue. -
forward
Perform forwarding of MSG to all recipients, waiting for up to MILLIS milliseconds for each deposit to be accepted.- Throws:
RemoteException
InterruptedException
-
myWait
Wait for up to LIMIT milliseconds or the next notify or interrupt. Returns the remaining time.- Throws:
InterruptedException
-
messageType
Description copied from interface:Mailbox
The (runtime) type of message sent through this box.- Specified by:
messageType
in interfaceMailbox<Msg extends Serializable>
-
checkType
Description copied from interface:Mailbox
Returns THIS, assuming that THIS conveys messages of class MSGCLASS.- Specified by:
checkType
in interfaceMailbox<Msg extends Serializable>
-