org.apache.commons.id.uuid.state
Class ReadOnlyResourceStateImpl

java.lang.Object
  extended by org.apache.commons.id.uuid.state.ReadOnlyResourceStateImpl
All Implemented Interfaces:
java.io.Serializable, State
Direct Known Subclasses:
ReadWriteFileStateImpl

public class ReadOnlyResourceStateImpl
extends java.lang.Object
implements State

The ReadOnlyResourceStateImpl is an implementation of the State interface. This implementation provides better guarantees that no duplicate UUID's will be generated; however since the only stateful information provided is the IEEE 802 address the generator should use a better choice is to use an implementation that also writes to persistent storage each time the state is loaded a new clock sequence is used. If the system time is adjusted backwards there is a possibility that a UUID generated with the same clock sequence and time could be generated.

Version:
$Id: ReadOnlyResourceStateImpl.java 480488 2006-11-29 08:57:26Z bayard $
Author:
Commons-Id team
See Also:
Serialized Form

Field Summary
static java.lang.String CONFIG_FILENAME_KEY
          The key to use in locating the uuid configuration xml file from System properties.
 
Fields inherited from interface org.apache.commons.id.uuid.state.State
DEFAULT_STATE_IMPL
 
Constructor Summary
ReadOnlyResourceStateImpl()
          Constructs a ReadOnlyResouceStateImpl.
 
Method Summary
 java.util.Set getNodes()
          Returns the collection of Nodes for this uuid state information.
 long getSynchInterval()
          Returns the number of milliseconds to wait between writing to stable storage.
 void load()
          Loads the System.property "commons.uuid.configFileName" (default is "uuid.conf") using commons.discovery.
protected  void parse(java.io.InputStream in)
          Parses the XML configuration into the Nodes and places into this instances node collection.
 void store(java.util.Set nodeSet)
          Stores the state information.
 void store(java.util.Set nodeSet, long timestamp)
          Stores the state information using a predetermined timestamp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIG_FILENAME_KEY

public static final java.lang.String CONFIG_FILENAME_KEY
The key to use in locating the uuid configuration xml file from System properties.

See Also:
Constant Field Values
Constructor Detail

ReadOnlyResourceStateImpl

public ReadOnlyResourceStateImpl()

Constructs a ReadOnlyResouceStateImpl.

Method Detail

load

public void load()
          throws java.lang.Exception

Loads the System.property "commons.uuid.configFileName" (default is "uuid.conf") using commons.discovery.

The uuid-[n].conf file is an xml file with the following syntax:

 
 
 
 
 
 
 ]>
 
 
 
 
 

See the documentation for further information on configuration tasks.

Specified by:
load in interface State
Throws:
java.lang.IllegalStateException - if the "commons.uuid.configFileName" system property is not set or the resource cannot be loaded.
org.xml.sax.SAXException - if an xml parsing error occurs
ParserConfigurationException - if the parser cannot be loaded
java.io.IOException - if an error occurs reading the file
java.lang.Exception
See Also:
State.load()

getSynchInterval

public long getSynchInterval()
Description copied from interface: State

Returns the number of milliseconds to wait between writing to stable storage.

Specified by:
getSynchInterval in interface State
Returns:
the number of milliseconds to wait between writing to stable storage.
See Also:
State.getSynchInterval()

getNodes

public java.util.Set getNodes()
Description copied from interface: State

Returns the collection of Nodes for this uuid state information.

Specified by:
getNodes in interface State
Returns:
the collection of Nodes for this uuid state.
See Also:
State.getNodes()

store

public void store(java.util.Set nodeSet)
           throws java.io.IOException
Description copied from interface: State

Stores the state information.

To increase the quality of the UUID uniqueness, a system that may write to stable storage SHOULD perist the state of the UUIDGenerator in order to reduce the likelihood of duplicate identifiers and increase the quality of the identifiers generated.

Specified by:
store in interface State
Parameters:
nodeSet - a Collection of Nodes to store.
Throws:
java.io.IOException - - an input/output Exception perhaps due to StringBuffer#append
See Also:
State.store(java.util.Set)

store

public void store(java.util.Set nodeSet,
                  long timestamp)
Description copied from interface: State

Stores the state information using a predetermined timestamp. This timestamp should be a time in the future but a shorter period than what the java virtual machine can restart within. This is normally linked to the sychInterval.

Using a point in time in the near future reduces unnecessary I/O, while allowing for the persistent state to be stored periodically, in an efficient manner.

Specified by:
store in interface State
Parameters:
nodeSet - a Collection of Nodes to store.
timestamp - the timestamp to write all Nodes last timestamp as.
See Also:
State.store(java.util.Set, long)

parse

protected void parse(java.io.InputStream in)
              throws java.lang.Exception

Parses the XML configuration into the Nodes and places into this instances node collection.

Parameters:
in - the XML input stream to parse.
Throws:
java.lang.Exception


Copyright © 2003-2008 The Apache Software Foundation. All Rights Reserved.