org.mega.gasp.bluetooth.miniplatform
Class IDManager

java.lang.Object
  extended byorg.mega.gasp.bluetooth.miniplatform.IDManager

public class IDManager
extends java.lang.Object

IDManager provide a management of the temporary IDs: ActorSessionID (ASID). These ID must be unique on the platform. There is a vector of released ASID sort by ASID and a meter to insure unicity. A max is set to limit the size of the IDs to improve the length of the message communications, in this version of the platform the type short is used. The algorithm to generate a new ID: the meter is incremented for a new ID attribution if the vector of released ID is empty, else the first ID of the vector is attributed and removed from the vector. The algorithm to release an ID: the meter is decremented if the ID is the max attributed ID and a purge of the vector is done, else the ID is released in the vector and insert at the right place (growing order).

Author:
PELLERIN Romain (pellerin@cnam.fr) - MEGA Project

Field Summary
private  java.util.Vector freeASID
           
private  int max
           
private  int maxFreeID
           
 
Constructor Summary
IDManager()
           
 
Method Summary
 int generateASID()
          Generate an unique ActorSession ID.
private  void indexID(java.util.Vector releasedIdVector, int tempID)
          Place the ID at his place in the vector, increase order.
private  void purgeVector(java.util.Vector releasedIdVector)
          Purge the vector with the alogorithm above: -> if the released ID is the max used ID then search in the vector releasedID-1, if it is in remove it, set to max Free ID and replay the algorithm.
 void releaseASID(int tempID)
          Release an ActorSession ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max

private int max

maxFreeID

private int maxFreeID

freeASID

private java.util.Vector freeASID
Constructor Detail

IDManager

public IDManager()
Method Detail

generateASID

public int generateASID()
Generate an unique ActorSession ID.

Returns:
ASID

releaseASID

public void releaseASID(int tempID)
Release an ActorSession ID.

Parameters:
tempID - the ASID

indexID

private void indexID(java.util.Vector releasedIdVector,
                     int tempID)
Place the ID at his place in the vector, increase order.

Parameters:
releasedIdVector - the vector of released ID
tempID - the tempID to place

purgeVector

private void purgeVector(java.util.Vector releasedIdVector)
Purge the vector with the alogorithm above: -> if the released ID is the max used ID then search in the vector releasedID-1, if it is in remove it, set to max Free ID and replay the algorithm.

Parameters:
releasedIdVector -