org.mega.gasp.platform.impl
Class IDManagerImpl

java.lang.Object
  extended byorg.mega.gasp.platform.impl.IDManagerImpl
All Implemented Interfaces:
IDManager

public class IDManagerImpl
extends java.lang.Object
implements IDManager

IDManager provide a management of the temporary IDs: the MasterApplicationID(MAID), ApplicationInstanceID(AIID), SessionID (SID) and ActorSessionID (ASID). These ID must be unique on the platform. For all type of IDs, there is a vector of released ID sort by ID 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  int AIID
           
private  int ASID
           
private  org.apache.log4j.Category cat
           
private  java.util.Vector freeAIID
           
private  java.util.Vector freeASID
           
private  java.util.Vector freeMAID
           
private  java.util.Vector freeSID
           
private  int MAID
           
private  int max
           
private  java.util.Vector maxFreeIDs
           
private  int SID
           
 
Constructor Summary
IDManagerImpl()
           
 
Method Summary
private  void decrementMaxFreeID(int idType)
          Decrements the max free id of ID type.
 int generateAIID()
          Generate an unique ApplicationInstance ID .
 int generateASID()
          Generate an unique ActorSession ID.
private  int generateID(java.util.Vector releasedIdVector, int index)
          Generate a unique ID.
 int generateMAID()
          Generate an unique MasterApplication ID.
 int generateSID()
          Generate an unique Session ID.
private  int getMaxFreeID(int idType)
          Returns the max free ID for ID type.
private  void incrementMaxFreeID(int idType)
          Increments the max free id of ID type.
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, int index)
          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 releaseAIID(int tempID)
          Release an ApplicationInstance ID.
 void releaseASID(int tempID)
          Release an ActorSession ID.
private  void releaseID(java.util.Vector releasedIdVector, int index, int tempID)
           
 void releaseMAID(int tempID)
          Release a MasterApplication ID.
 void releaseSID(int tempID)
          Release a Session ID.
private  void setMaxFreeID(int idType, int value)
          Sets the max free ID to value of ID type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

max

private int max

maxFreeIDs

private java.util.Vector maxFreeIDs

freeASID

private java.util.Vector freeASID

freeSID

private java.util.Vector freeSID

freeAIID

private java.util.Vector freeAIID

freeMAID

private java.util.Vector freeMAID

cat

private org.apache.log4j.Category cat

MAID

private final int MAID
See Also:
Constant Field Values

AIID

private final int AIID
See Also:
Constant Field Values

SID

private final int SID
See Also:
Constant Field Values

ASID

private final int ASID
See Also:
Constant Field Values
Constructor Detail

IDManagerImpl

public IDManagerImpl()
Method Detail

getMaxFreeID

private int getMaxFreeID(int idType)
Returns the max free ID for ID type.

Parameters:
idType -
Returns:
int

setMaxFreeID

private void setMaxFreeID(int idType,
                          int value)
Sets the max free ID to value of ID type.

Parameters:
idType -
value -

incrementMaxFreeID

private void incrementMaxFreeID(int idType)
Increments the max free id of ID type.

Parameters:
idType -

decrementMaxFreeID

private void decrementMaxFreeID(int idType)
Decrements the max free id of ID type.

Parameters:
idType -

generateMAID

public int generateMAID()
Generate an unique MasterApplication ID.

Specified by:
generateMAID in interface IDManager
Returns:
an MAID

generateAIID

public int generateAIID()
Generate an unique ApplicationInstance ID .

Specified by:
generateAIID in interface IDManager
Returns:
an AIID

generateSID

public int generateSID()
Generate an unique Session ID.

Specified by:
generateSID in interface IDManager
Returns:
an SID

generateASID

public int generateASID()
Generate an unique ActorSession ID.

Specified by:
generateASID in interface IDManager
Returns:
ASID

releaseMAID

public void releaseMAID(int tempID)
Release a MasterApplication ID.

Specified by:
releaseMAID in interface IDManager
Parameters:
tempID - the MAID

releaseAIID

public void releaseAIID(int tempID)
Release an ApplicationInstance ID.

Specified by:
releaseAIID in interface IDManager
Parameters:
tempID - the AIID

releaseSID

public void releaseSID(int tempID)
Release a Session ID.

Specified by:
releaseSID in interface IDManager
Parameters:
tempID - the SID

releaseASID

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

Specified by:
releaseASID in interface IDManager
Parameters:
tempID - the ASID

generateID

private int generateID(java.util.Vector releasedIdVector,
                       int index)
Generate a unique ID.

Parameters:
releasedIdVector - the corresponding vector
index - the index of the max free IDs table
Returns:
the generated ID

releaseID

private void releaseID(java.util.Vector releasedIdVector,
                       int index,
                       int tempID)
Parameters:
releasedIdVector -
index - the index of the max free IDs table
tempID -

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,
                         int index)
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 -
index -