org.rhq.core.pluginapi.content.version
Class PackageVersions

java.lang.Object
  extended by org.rhq.core.pluginapi.content.version.PackageVersions

public class PackageVersions
extends Object

Access to the persistent storage of package versions. This class provides the ability to save and load the versions to disk, along with the basic retrieval and set calls for the versions themselves.


Field Summary
static String FILENAME
          Name of the file used to persist the version data.
static String LEGACY_FILENAME
          Name of the file used in JON 2.1 and earlier to persist the version data.
 
Constructor Summary
PackageVersions(String pluginName, String dataDirectory)
          Creates a new entry point to the persisted version data.
 
Method Summary
 String getVersion(String packageKey)
          Retrieves the version for the package identified by the supplied package key.
 void loadFromDisk()
          Loads the last known application (package) versions for the plugin this instance is scoped to.
 void putVersion(String packageKey, String version)
          Updates the store with a new version for the package identified by the specified key.
 void saveToDisk()
          Saves the current state of the application (package) versions to disk.
 void unload()
          For internal use only - Removes the static data object to simulate the first load in the system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILENAME

public static final String FILENAME
Name of the file used to persist the version data.

See Also:
Constant Field Values

LEGACY_FILENAME

public static final String LEGACY_FILENAME
Name of the file used in JON 2.1 and earlier to persist the version data.

See Also:
Constant Field Values
Constructor Detail

PackageVersions

public PackageVersions(String pluginName,
                       String dataDirectory)
Creates a new entry point to the persisted version data. Multiple instances of this class may be instantiated; the storage of the data itself does not live in any particular instance of this class. This call will not load the data from disk, it must explicitly be done by the user through a call to loadFromDisk().

Parameters:
pluginName - plugin loading the version data
dataDirectory - directory into which to persist the versions
Method Detail

loadFromDisk

public void loadFromDisk()
Loads the last known application (package) versions for the plugin this instance is scoped to. This method will absorb and log any errors that occur while saving; this call represents a best-effort to save the values. If a data store for the versions has already been found, this method will not reload it from disk. Thus it is safe to make this call multiple times not only per instance, but per class loader, as the data is stored as a static variable across all instances of this class.


saveToDisk

public void saveToDisk()
Saves the current state of the application (package) versions to disk. The values will be saved scoped to the plugin specified in the constructor. This method will absorb and log any errors that occur while saving; this call represents a best-effort to save the values.


getVersion

public String getVersion(String packageKey)
Retrieves the version for the package identified by the supplied package key. This method will synchronize against the data store, thus callers need not worry about handling calls across multiple discovery threads.

Parameters:
packageKey - identifies the package
Returns:
version of the package if it is known; null otherwise

unload

public void unload()
For internal use only - Removes the static data object to simulate the first load in the system. This should not be called by production code and is only for testing purposes.


putVersion

public void putVersion(String packageKey,
                       String version)
Updates the store with a new version for the package identified by the specified key. If there is an existing version in the store, it will be overwritten. This method will synchronize on against the data store, thus callers need not worry about handling calls across multiple deploy threads.

Parameters:
packageKey - identifies the package
version - version of the package


Copyright © 2008-2009 RHQ Project Advisory Board (Red Hat, Inc.). All Rights Reserved.