|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--edu.virginia.cs.mng.hypercast.MessageBuffer
This class provides a buffer which handles all the functionality for the producer/consumer problem. It assumes that there can be multiple producers and consumers. This is a FIFO style Buffer.
| Field Summary | |
private OverlaySocketConfig |
config
OverlaySocketConfig object. |
private int |
NumberOfElements
The number of messages in the Queue |
private I_Message[] |
Queue
The queue of messages. |
private int |
readersWaiting
Number of threads waiting to read. |
private int |
soTimeout
Timeout for reads. |
private int |
Start
The location of the oldest message in the queue. |
private int |
writersWaiting
Number of threads waiting to write. |
| Constructor Summary | |
(package private) |
MessageBuffer(OverlaySocketConfig c,
int size)
Constructs the BoundedBuffer with a size and a config file. |
| Method Summary | |
boolean |
available()
Checks if there is any messages available in the queue. |
void |
blockingWrite(I_Message msg)
Writes a message to the BoundedBuffer Algorithm: 1. |
java.lang.String[] |
getSchema()
Get the Statistics information description of this AdapterBuffer. |
(package private) int |
getSoTimeout()
Get the timeout time for a read operation. |
java.lang.String |
getStats(java.lang.String name)
Get the Statistics information of this AdapterBuffer. |
void |
nonblockingWrite(I_Message msg)
Writes a message to the DropTailMessageBuffer Algorithm: 1. |
int |
numInQueue()
Returns the number of messages in the queue. |
I_Message |
peek()
Peeks the message at the head of the queue Algorithm: If queue is empty return null, else return the packet at the head of the queue |
I_Message |
read()
Reads a message from the BoundedBuffer. |
(package private) void |
setSoTimeout(int i)
Set the timeout time for a read operation. |
void |
setStats(java.lang.String name,
java.lang.String value)
Set the Statistic information in this AdapterBuffer. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private OverlaySocketConfig config
private int NumberOfElements
private I_Message[] Queue
private int Start
private int soTimeout
private int readersWaiting
private int writersWaiting
| Constructor Detail |
MessageBuffer(OverlaySocketConfig c,
int size)
Size - size of the buffer (number of messages)fd - FileWriter of a debug file| Method Detail |
int getSoTimeout()
void setSoTimeout(int i)
public I_Message read()
throws java.lang.InterruptedException
Algorithm:
1. Waits till the queue is non-empty
2. Copies first element in the queue
3. Increments the Start pointer modulo Queue length
4. Decreases size of the Queue
5. Notifies any other process waiting
6. Returns the copied element
public void nonblockingWrite(I_Message msg)
Algorithm:
1. checks if Queue is full
2. Places New packet at the end of the Queue
3. Increments number of elements
4. Notifies all threads waiting
msg - a message to be added into the Queue
public void blockingWrite(I_Message msg)
throws java.lang.InterruptedException
Algorithm:
1. checks if Queue is full
2. Places New packet at the end of the Queue
3. Increments number of elements
4. Notifies all threads waiting
msg - a message to be added into the Queuepublic I_Message peek()
Algorithm:
If queue is empty return null, else return the packet at the head of the queue
public boolean available()
public int numInQueue()
public java.lang.String getStats(java.lang.String name)
throws StatsException
name - the String representation of a Statistic name
public void setStats(java.lang.String name,
java.lang.String value)
throws StatsException
name - the String representation of a Statistic namevalue - the String representation of the Statistic value
public java.lang.String[] getSchema()
throws StatsException
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||