simulator
Class Queue

java.lang.Object
  |
  +--simulator.Queue

class Queue
extends java.lang.Object

This class implements a circular-shared-queue for string elements. The acesses to the queue are im mutual exclusion to prevent theads conflict. To prevent that the queue become full two semaphore array are required and are used as producer-consumer. So the initialization of this semaphores are made by user that can use for examples a queue of 10 elements, but 6 of one type, and 4 of another type. When one of this type is finished the process is suspend until the resources it needs become free.


Field Summary
protected  Semaphore[] availableCells
          This is the array of semaphore that contains the available resources of the index-array type
(package private)  int countElem
          The actual number of elements that the queue contains
(package private)  int head
          The pointer to head of queue
protected  Semaphore mutex
          the mutex to prevent conflict in shared queue
(package private)  int numElem
          This contain the dimansion of the queue
protected  Semaphore[] presentMessage
          This is the array of semaphore that contains the occupied resources of the index-array type
private  java.lang.String[] Q
          This is the array that contain the string values
(package private)  int tile
          The pointer to tile of queue
 
Constructor Summary
Queue(int numElem, Semaphore[] availableCells, Semaphore[] presentMessage)
          Initialize the shared queue
 
Method Summary
(package private)  java.lang.String get(java.lang.String name, int sorg)
          Get a string from the sorg index of array in the queue
(package private)  void put(java.lang.String name, java.lang.String s, int dest)
          Put the string s in the queue using the dest index of array
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

Q

private java.lang.String[] Q
This is the array that contain the string values

numElem

int numElem
This contain the dimansion of the queue

countElem

int countElem
The actual number of elements that the queue contains

head

int head
The pointer to head of queue

tile

int tile
The pointer to tile of queue

availableCells

protected Semaphore[] availableCells
This is the array of semaphore that contains the available resources of the index-array type

presentMessage

protected Semaphore[] presentMessage
This is the array of semaphore that contains the occupied resources of the index-array type

mutex

protected Semaphore mutex
the mutex to prevent conflict in shared queue
Constructor Detail

Queue

public Queue(int numElem,
             Semaphore[] availableCells,
             Semaphore[] presentMessage)
Initialize the shared queue
Parameters:
numElem - number of total element of the cell
availableCells - the semaphore array (must be just initialized) for available resources
presentMessage - the semaphore array (must be just initialized) for occupied resources
See Also:
availableCells, presentMessage
Method Detail

put

void put(java.lang.String name,
         java.lang.String s,
         int dest)
Put the string s in the queue using the dest index of array
Parameters:
name - the name of process that call put (actual never used)
s - the string to insert in the queue
dest - the index of array (type of resources)

get

java.lang.String get(java.lang.String name,
                     int sorg)
Get a string from the sorg index of array in the queue
Parameters:
name - the name of process that call put (actual never used)
sorg - the index of array (type of resources)
Returns:
the string from the queue