com.atomikos.util
Class UniqueIdMgr

java.lang.Object
  extended by com.atomikos.util.UniqueIdMgr

public class UniqueIdMgr
extends Object

For managing a set of unique IDs on behalf of a given server


Constructor Summary
UniqueIdMgr(String server)
          Generate a new instance for a given server.
UniqueIdMgr(String server, String directorypath)
          Preferred constructor: based on file-logged epoch value.
UniqueIdMgr(String server, String directorypath, int limit)
          Constructor for startup limit.
 
Method Summary
 String get()
          The main way of obtaining a new UniqueId.
 int getMaxIdLengthInBytes()
           
protected  long readEpoch()
          Read the next epoch value from the epoch file.
 void setPrefix(String prefix)
          Sets the prefix to add to each generated ID.
 void setSuffix(String suffix)
          Sets the suffix to add to each generated ID.
protected  void writeEpoch(long value)
          Write the given value into the epoch file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniqueIdMgr

public UniqueIdMgr(String server)
Generate a new instance for a given server. Assumption: there are never two servers with the same name!


UniqueIdMgr

public UniqueIdMgr(String server,
                   String directorypath)
Preferred constructor: based on file-logged epoch value.

Parameters:
server - The server's unique name.
directorypath - The path (with ending slash!) where the epoch file should be written.

UniqueIdMgr

public UniqueIdMgr(String server,
                   String directorypath,
                   int limit)
Constructor for startup limit. Useful for evaluation versions: after the epoch reaches the limit, no new IDs will be created.

Method Detail

setSuffix

public void setSuffix(String suffix)
Sets the suffix to add to each generated ID.

Parameters:
suffix - The suffix, defaults to empty string. This suffix is added directly after the server (base) name but is not the last part of the ID.

setPrefix

public void setPrefix(String prefix)
Sets the prefix to add to each generated ID.

Parameters:
prefix - The prefix, defaults to empty string. This value is added at the very beginning of each generated ID.

readEpoch

protected long readEpoch()
                  throws IOException
Read the next epoch value from the epoch file. At the same time, this increments the value in the epoch file, for next restart.

Returns:
long The next value to use.
Throws:
IOException - If reading or writing fails.

writeEpoch

protected void writeEpoch(long value)
                   throws IOException
Write the given value into the epoch file.

Parameters:
value - The next epoch value.
Throws:
IOException - On failure.

get

public String get()
The main way of obtaining a new UniqueId.


getMaxIdLengthInBytes

public int getMaxIdLengthInBytes()


Copyright © 2011. All Rights Reserved.