Package kilim
Class Cell<T>
java.lang.Object
kilim.Cell<T>
- All Implemented Interfaces:
EventPublisher,PauseReason
A cell is a single-space buffer that supports multiple producers and a single
consumer, functionally identical to Mailbox bounded to a size of 1 (and hence
optimized for this size)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescription(package private) VolatileReferenceCell<T> static 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 TypeMethodDescriptionvoidvoidget()get(long timeoutMillis) get(EventSubscriber eo) Non-blocking, nonpausing get.getb()retrieve a message, blocking the thread indefinitely.getb(long timeoutMillis) retrieve a msg, and block the Java thread for the time given.getnb()Get, don't pause or block.booleanbooleanhasSpace()booleanTrue if the given task's reason for pausing is still valid.voidbooleanbooleanput(T msg, EventSubscriber eo) Non-blocking, nonpausing put.voidvoidbooleanvoidvoidtoString()
-
Field Details
-
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
-
sink
-
message
VolatileReferenceCell<T> message
-
-
Constructor Details
-
Cell
public Cell()
-
-
Method Details
-
get
Non-blocking, nonpausing get.- Parameters:
eo- . If non-null (and if there is no message), registers this observer. The observer is notified with a MessageAvailable event when a put() is done.- Returns:
- buffered message if there's one, or null
-
put
Non-blocking, nonpausing put.- Parameters:
eo- . If non-null, registers this observer and calls it with an SpaceAvailable event when there's space.- Returns:
- buffered message if there's one, or null
-
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.
- Throws:
Pausable
-
addSpaceAvailableListener
-
removeSpaceAvailableListener
-
addMsgAvailableListener
-
removeMsgAvailableListener
-
putnb
-
put
- Throws:
Pausable
-
put
- Throws:
Pausable
-
putb
-
putb
-
hasMessage
public boolean hasMessage() -
hasSpace
public boolean hasSpace() -
getb
retrieve a message, blocking the thread indefinitely. Note, this is a heavyweight block, unlike #get() that pauses the Fiber but doesn't block the thread. -
getb
retrieve a msg, and block the Java thread for the time given.- Parameters:
millis- . max wait time- Returns:
- null if timed out.
-
toString
-
isValid
Description copied from interface:PauseReasonTrue if the given task's reason for pausing is still valid.- Specified by:
isValidin interfacePauseReason
-