Package EDU.oswego.cs.dl.util.concurrent
Class Slot
- java.lang.Object
-
- EDU.oswego.cs.dl.util.concurrent.SemaphoreControlledChannel
-
- EDU.oswego.cs.dl.util.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.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Objectitem_The slot-
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.SemaphoreControlledChannel
capacity_, putGuard_, takeGuard_
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Objectextract()Take item known to existprotected voidinsert(java.lang.Object x)Set the item in preparation for a takejava.lang.Objectpeek()Return, but do not remove object at head of Channel, or null if it is empty.
-
-
-
Constructor Detail
-
Slot
public Slot(java.lang.Class semaphoreClass) throws java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetExceptionCreate a buffer with the given capacity, using the supplied Semaphore class for semaphores.- Throws:
java.lang.NoSuchMethodException- If class does not have constructor that intializes permitsjava.lang.SecurityException- if constructor information not accessiblejava.lang.InstantiationException- if semaphore class is abstractjava.lang.IllegalAccessException- if constructor cannot be calledjava.lang.reflect.InvocationTargetException- if semaphore constructor throws an exception
-
Slot
public Slot()
Create a new Slot using default Semaphore implementations
-
-
Method Detail
-
insert
protected void insert(java.lang.Object x)
Set the item in preparation for a take- Specified by:
insertin classSemaphoreControlledChannel
-
extract
protected java.lang.Object extract()
Take item known to exist- Specified by:
extractin classSemaphoreControlledChannel
-
peek
public java.lang.Object peek()
Description copied from interface:ChannelReturn, but do not remove object at head of Channel, or null if it is empty.
-
-