java.lang.Object
org.ematgine.utils.concurrent.SemaphoreControlledChannel
org.ematgine.utils.concurrent.Slot
- All Implemented Interfaces:
- BoundedChannel, Channel, Puttable, Takable
- public class Slot
- extends SemaphoreControlledChannel
A one-slot buffer, using semaphores to control access.
Slots are usually more efficient and controllable than using other
bounded buffers implementations with capacity of 1.
Among other applications, Slots can be convenient in token-passing
designs: Here. the Slot holds a some object serving as a token,
that can be obtained
and returned by various threads.
[ Introduction to this package. ]
|
Constructor Summary |
Slot()
Create a new Slot using default Semaphore implementations |
Slot(java.lang.Class semaphoreClass)
Create a buffer with the given capacity, using
the supplied Semaphore class for semaphores. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
item_
protected java.lang.Object item_
- The slot
Slot
public Slot(java.lang.Class semaphoreClass)
throws java.lang.NoSuchMethodException,
java.lang.SecurityException,
java.lang.InstantiationException,
java.lang.IllegalAccessException,
java.lang.reflect.InvocationTargetException
- Create a buffer with the given capacity, using
the supplied Semaphore class for semaphores.
Slot
public Slot()
- Create a new Slot using default Semaphore implementations
insert
protected void insert(java.lang.Object x)
- Set the item in preparation for a take
- Specified by:
insert in class SemaphoreControlledChannel
extract
protected java.lang.Object extract()
- Take item known to exist
- Specified by:
extract in class SemaphoreControlledChannel
peek
public java.lang.Object peek()
- Description copied from interface:
Channel
- Return, but do not remove object at head of Channel,
or null if it is empty.