Package kilim
Class MailboxMPSC<T>
java.lang.Object
kilim.MailboxMPSC<T>
- All Implemented Interfaces:
EventPublisher,PauseReason
This is a typed buffer that supports single producers and a single consumer.
It is the basic construct used for tasks to interact and synchronize with
each other (as opposed to direct java calls or static member variables).
put() and get() are the two essential functions.
We use the term "block" to mean thread block, and "pause" to mean fiber
pausing. The suffix "nb" on some methods (such as getnb()) stands for
non-blocking. Both put() and get() have blocking and non-blocking variants in
the form of putb(), putnb
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Eventstatic final int(package private) VolatileReferenceCell<EventSubscriber> static final intstatic final Event(package private) Queue<EventSubscriber> static final intstatic final Event -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidget()get(long timeoutMillis) get(EventSubscriber eo) Non-blocking, nonpausing get.getnb()Get, don't pause or block.private EventSubscriberprivate longgetSize()booleanTrue if the given task's reason for pausing is still valid.voidput a non-null message in the mailbox, and pause the calling task until the mailbox has spacebooleanput a non-null message in the mailbox, and pause the calling task for timeoutMillis if the mailbox is full.booleanput(T msg, EventSubscriber eo) booleanAttempt to put a message, and return true if successful.voidvoidprivate booleansrcContains(Task t) toString()
-
Field Details
-
msgs
-
sink
-
srcs
Queue<EventSubscriber> srcs -
SPACE_AVAILABLE
public static final int SPACE_AVAILABLE- See Also:
-
MSG_AVAILABLE
public static final int MSG_AVAILABLE- See Also:
-
TIMED_OUT
public static final int TIMED_OUT- See Also:
-
spaceAvailble
-
messageAvailable
-
timedOut
-
-
Constructor Details
-
MailboxMPSC
public MailboxMPSC() -
MailboxMPSC
public MailboxMPSC(int initialSize)
-
-
Method Details
-
get
Non-blocking, nonpausing get.- Parameters:
eo- . If non-null, registers this observer and calls it with a MessageAvailable event when a put() is done.- Returns:
- buffered message if there's one, or null
-
put
-
getnb
Get, don't pause or block.- Returns:
- stored message, or null if no message found.
-
get
- Returns:
- non-null message.
- Throws:
Pausable
-
get
- Returns:
- non-null message, or null if timed out.
- Throws:
Pausable
-
putnb
Attempt to put a message, and return true if successful. The thread is not blocked, nor is the task paused under any circumstance. -
addSpaceAvailableListener
-
removeSpaceAvailableListener
-
addMsgAvailableListener
-
removeMsgAvailableListener
-
getProducer
-
srcContains
-
getSize
private long getSize() -
put
put a non-null message in the mailbox, and pause the calling task until the mailbox has space- Throws:
Pausable
-
put
put a non-null message in the mailbox, and pause the calling task for timeoutMillis if the mailbox is full.- Throws:
Pausable
-
toString
-
isValid
Description copied from interface:PauseReasonTrue if the given task's reason for pausing is still valid.- Specified by:
isValidin interfacePauseReason
-
fill
-