|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.instantreality.InstantIO.Slot
org.instantreality.InstantIO.InSlot
org.instantreality.InstantIO.BufferedInSlot
public class BufferedInSlot
InSlot that buffers values.
Usually, InSlots do not buffer values, i.e. when a new data value is written into the InSlot before the old data value has been received by the application, the old data value gets lost. This is ok under many circumstances, but sometimes it is important to get all data values (e.g. when receiving button press and release events). For this reason, the BufferedInSlot class exists.
When you create a BufferedInSlot object, you have to specify
the maximum number of data values that get buffered by the
BufferedInSlot. When the BufferedInSlot receives a new data value, it
adds it to the buffer. When you call the pop
method,
the BufferedInSlot removes the oldest value from the buffer and
returns it. When more values are written into the BufferedInSlot than
the maximum number, the new data values overwrite the oldest data
values stored in the buffer.
Besides buffering data values, BufferedInSlots do not differ from normal InSlots, they behave exactly the same way. To replace a normal InSlot by a BufferedInSlot, you just have to change the code that creates the Inslot.
InSlot
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.instantreality.InstantIO.InSlot |
---|
InSlot.Listener |
Field Summary |
---|
Fields inherited from class org.instantreality.InstantIO.Slot |
---|
In, Out |
Constructor Summary | |
---|---|
BufferedInSlot(java.lang.Class type,
int numValues)
Creates a new BufferedInSlot object. |
|
BufferedInSlot(java.lang.Class type,
java.lang.String description,
int numValues)
Creates a new BufferedInSlot object. |
Method Summary | |
---|---|
boolean |
empty()
Returns if data is available on the BufferedInSlot. |
java.lang.Object |
pop()
Removes the oldest data value from the buffer and returns it. |
Data |
popData()
Removes the oldest data value from the buffer and returns it. |
java.lang.Object |
top()
Returns the oldest data value without removing it from the buffer. |
Data |
topData()
Returns the oldest data value without removing it from the buffer. |
Methods inherited from class org.instantreality.InstantIO.InSlot |
---|
addListener, connect, disconnect, getDirection, isConnected, newData, removeListener, startInSlot, stopInSlot |
Methods inherited from class org.instantreality.InstantIO.Slot |
---|
getDescription, getType |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BufferedInSlot(java.lang.Class type, int numValues)
The following example demonstrates how to create a BufferedInSlot that receives boolean values and buffers up to 10 data values:
BufferedInSlot inSlot = new BufferedInSlot(Boolean.class, 10);
type
- The type of data that can be written into
this InSlot. InSlots can only connect to OutSlots
that have the same type of data. To use basic Java types (e.g.
boolean
, int
or float
)
you have to use the wrapper classes provided by Java (e.g.
Boolean
, Integer
or Float
).numValues
- The maximum number of values that are buffered
by this InSlot.public BufferedInSlot(java.lang.Class type, java.lang.String description, int numValues)
The following example demonstrates how to create a BufferedInSlot that receives boolean values that represent button press events and buffers up to 10 data values:
BufferedInSlot inSlot = new BufferedInSlot(Boolean.class, "Used to receive button press events", 10);
type
- The type of data that can be written into
this InSlot. InSlots can only connect to OutSlots
that have the same type of data. To use basic Java types (e.g.
boolean
, int
or float
)
you have to use the wrapper classes provided by Java (e.g.
Boolean
, Integer
or Float
).description
- The description of this InSlot. The
description is not used by the system in any way. It
primarily serves documentation purposes. Some user interfaces
that allow to manage the system print the description
alongside with the InSlot.numValues
- The maximum number of values that are buffered
by this InSlot.Method Detail |
---|
public boolean empty()
All methods that receive data values (top
, topData
, pop
, popData
)
block when no data is available until data is received from an
OutSlot
. By using this method, you can prevent
this blocking by checking if data is actually available.
The following example demonstrates how to use the empty
method when you have to poll for new data values on a BufferedInSlot
that receives boolean values:
BufferedInSlot inSlot = ...; while (inSlot.empty() == false) { Boolean b = (Boolean) inSlot.pop(); // do something with the boolean value }
empty
in class InSlot
public java.lang.Object top() throws java.lang.InterruptedException
This method blocks when no data is available until data
is received from an OutSlot
. By using the
empty
method you can check if data is
available before calling this method.
This method just returns the data value, but not the time
when the data value has been created. When you need to get
a timestamp, use the topData
method instead
of this method.
To remove the data value from the buffer, you can call the
pop
or popData
methods.
The following example demonstrates how to use the top
method to get the oldest data value from a BufferedInSlot
that receives boolean values:
BufferedInSlot inSlot = ...; Boolean b = (Boolean) inSlot.top(); // do something with the boolean value
top
in class InSlot
java.lang.InterruptedException
- when the thread blocked in
the top method got interruptedempty
,
topData
,
pop
,
popData
public Data topData() throws java.lang.InterruptedException
This method blocks when no data is available until data
is received from an OutSlot
. By using the
empty
method you can check if data is
available before calling this method.
This method returns a Data
object that contains
the oldest data value and the time when it has been created.
When you do not need the timestamp, you can call the top
method that returns the data value directly.
To remove the data value from the buffer, you can call the
pop
or popData
methods.
The following example demonstrates how to use the topData
method to get the oldest data value and its timestamp from a
BufferedInSlot that receives boolean values:
BufferedInSlot inSlot = ...; Data data = inSlot.topData(); Boolean b = (Boolean) data.getValue(); long timeStamp = data.getTimeStamp(); // do something with the boolean value and the timestamp
topData
in class InSlot
Data
object that contains the oldest
data value and the time when it has been created.
java.lang.InterruptedException
- when the thread blocked in
the topData method got interruptedempty
,
top
,
pop
,
popData
public java.lang.Object pop() throws java.lang.InterruptedException
This method blocks when no data is available until data
is received from an OutSlot
. By using the
empty
method you can check if data is
available before calling this method.
This method just returns the data value, but not the time
when the data value has been created. When you need to get
a timestamp, use the popData
method instead
of this method.
To get the data value without removing it from the InSlot,
use the top
or topData
methods.
The following example demonstrates how to use the pop
method to get and remove the oldest data value from a
BufferedInSlot that receives boolean values:
BufferedInSlot inSlot = ...; Boolean b = (Boolean) inSlot.pop(); // do something with the boolean value
pop
in class InSlot
java.lang.InterruptedException
- when the thread blocked in
the pop method got interruptedempty
,
popData
,
top
,
topData
public Data popData() throws java.lang.InterruptedException
OutSlot
. By using the
empty
method you can check if data is
available before calling this method.
This method returns a Data
object that contains
the oldest data value and the time when it has been created.
When you do not need the timestamp, you can call the pop
method that returns the data value directly.
The following example demonstrates how to use the popData
method to get and remove the oldest data value and its timestamp from
a BufferedInSlot that receives boolean values:
BufferedInSlot inSlot = ...; Data data = inSlot.popData(); Boolean b = (Boolean) data.getValue(); long timeStamp = data.getTimeStamp(); // do something with the boolean value and the timestamp
popData
in class InSlot
Data
object that contains the oldest
data value and the time when it has been created.
java.lang.InterruptedException
- when the thread blocked in
the popData method got interruptedempty
,
pop
,
top
,
topData
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |