com.cometway.om
Class FileObjectManager

java.lang.Object
  extended by com.cometway.props.Props
      extended by com.cometway.ak.Agent
          extended by com.cometway.ak.ServiceAgent
              extended by com.cometway.om.FileObjectManager
All Implemented Interfaces:
AgentInterface, IObjectManager, HasStateMachineModel

public class FileObjectManager
extends ServiceAgent
implements IObjectManager

The FileObjectManager manages Props objects and persists them as files, using FilePropsContainers. A Props object must first be created by calling createObject with an ObjectType to get an ObjectID which matches that props Object. The only ObjectType supported in this Manager is the PropsType. Since only Props Objects are stored, using other types will fail. The actual Props object can be fetched by calling getObject with the ObjectID. The ObjectID associated with its props is: new ObjectID(props.getString("type"),props.getString("id")); Props objects can be listed by calling listObjects with an Object which listObjects will use as a queryObject. If this object is null, all ObjectID's will be listed. If this Object is an instanceof ObjectType, then all the ObjectID's of the props objects of this type will be returned. If this Object is an instanceof Pair, then the ObjectID whos props contains a property name that is the String stored in Pair.first() with a value that is equal to the String stored in Pair.second(). Props objects can be removed by calling removeObject with an ObjectID.

All the Props objects managed by this manager is cached in a hashtable called 'allprops' with ObjectID's as keys associated with the Props object. The id property stored in the props object matches its persistent filename as the number after \"prop#\", i.e. filename is \"prop\"+id. This manager is passed a String or File that is the root directory to store all props persistence files in. The props is written to the file as a serialized Hashtable. This hashtable is kept in the FilePropsContainer which keeps the file updated with its hashtable.

See Also:
Props, FilePropsContainer, ObjectID, TODO:

Field Summary
protected  java.util.Hashtable allprops
           
protected  java.lang.Object fsSync
           
protected  long nextID
           
protected  java.io.File rootdir
           
protected  java.util.Hashtable types
           
 
Fields inherited from class com.cometway.ak.Agent
agent_id, agentController, CREATING_STATE, debugReporter, DESTROYED_STATE, DESTROYING_STATE, errorReporter, FAILED_STATE, printlnReporter, props, RUNNING_STATE, STARTING_STATE, STOPPED_STATE, STOPPING_STATE, warningReporter
 
Fields inherited from interface com.cometway.om.IObjectManager
LIST_SUPPORTED_TYPES, LIST_TYPES
 
Constructor Summary
FileObjectManager()
           
 
Method Summary
 boolean changeObjectID(ObjectID oldID, ObjectID newID)
          This method changes an object's ObjectID.
 ObjectID createObject(ObjectType type)
          Creates a new object in the object manager of the specified object type.
 java.lang.Object getObject(ObjectID id)
          Retrieves the object corresponding to an object ID.
protected  void initialize()
          This constructor creates all the directories that doesn't exist.
 void initProps()
          Sets the service_name property to object_manager if a value was not provided.
 java.util.Vector listObjects(java.lang.Object objectQuery)
          Returns a Vector of objects designated by the objectQuery parameter.
 boolean removeObject(ObjectID id)
          Deletes the object corresponding to an object ID from the object manager.
 void start()
          Starts and registers the object cache.
 void stop()
          Stops and unregisters the object cache.
 
Methods inherited from class com.cometway.ak.Agent
currentStateEquals, debug, destroy, error, error, getAgentController, getDateTimeStr, getProps, getServiceImpl, getStateMachineModel, println, register, registerService, setAgentController, setProps, toString, unregister, unregisterService, warning, warning
 
Methods inherited from class com.cometway.props.Props
addListener, append, copy, copyFrom, copyTo, decrementInteger, dump, enableListeners, enumerateKeys, format, getBoolean, getByteArray, getCharacter, getDate, getDate, getDateString, getDouble, getFloat, getHexString, getInteger, getKeys, getLong, getNextKey, getProperty, getProperty, getPropsContainer, getSize, getString, getString, getTokens, getTokens, getTrimmedString, getVector, hasProperty, incrementInteger, insertProps, loadProps, notifyPropsChanged, notifyPropsChangedIgnore, notifyPropsChangedIgnore, parse, propertyMatchesRegEx, readFromFile, regExPropertyMatches, removeAll, removeListener, removeProperty, resumeNotify, saveProps, set, setBoolean, setCharacter, setDefault, setDouble, setFloat, setInteger, setLong, setProperty, setProperty, setProperty, setPropsContainer, suspendNotify, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

types

protected java.util.Hashtable types

allprops

protected java.util.Hashtable allprops

nextID

protected long nextID

rootdir

protected java.io.File rootdir

fsSync

protected java.lang.Object fsSync
Constructor Detail

FileObjectManager

public FileObjectManager()
Method Detail

initProps

public void initProps()
Sets the service_name property to object_manager if a value was not provided.

Specified by:
initProps in interface AgentInterface
Overrides:
initProps in class Agent

start

public void start()
Starts and registers the object cache.

Specified by:
start in interface AgentInterface
Overrides:
start in class ServiceAgent

stop

public void stop()
Stops and unregisters the object cache.

Specified by:
stop in interface AgentInterface
Overrides:
stop in class ServiceAgent

initialize

protected void initialize()
                   throws java.io.IOException
This constructor creates all the directories that doesn't exist. Initialzes local fields, Reads all new props from root directory.

Parameters:
rootdir - This is the File of the directory to store all persistence files
Throws:
java.io.IOException - This exception is thrown if the root directory is invalid or could not be used.

createObject

public ObjectID createObject(ObjectType type)
Description copied from interface: IObjectManager
Creates a new object in the object manager of the specified object type.

Note: Currently, only the PropsType is supported.

Specified by:
createObject in interface IObjectManager
Parameters:
type - a reference to an ObjectType representing the type of object to create.
Returns:
a reference to a valid ObjectID if successful; null otherwise.

getObject

public java.lang.Object getObject(ObjectID id)
Description copied from interface: IObjectManager
Retrieves the object corresponding to an object ID.

Specified by:
getObject in interface IObjectManager
Parameters:
id - a reference to an ObjectID representing a valid object in the object manager.
Returns:
a reference to an Object if one was found; null otherwise.

listObjects

public java.util.Vector listObjects(java.lang.Object objectQuery)
Description copied from interface: IObjectManager
Returns a Vector of objects designated by the objectQuery parameter. Valid objects for this parameter are:
IObjectManager.LIST_TYPES Lists object types that already exist.
IObjectManager.LIST_SUPPORTED_TYPES Lists objects which can be passed to createObject.
ObjectType Lists all existing objects of the same ObjectType.
PropsQuery Lists Props based on data from the PropsQuery object.
Note: Some object managers may support additional values for access to non-standard features.

Specified by:
listObjects in interface IObjectManager
Parameters:
objectQuery - any valid object from the list above.
Returns:
a Vector containing Objects based on the query; null if the query wasn't recognized.

removeObject

public boolean removeObject(ObjectID id)
Description copied from interface: IObjectManager
Deletes the object corresponding to an object ID from the object manager.

Specified by:
removeObject in interface IObjectManager
Parameters:
id - a reference to an ObjectID representing a valid object in the object manager.
Returns:
true if the object was successfully deleted; false otherwise.

changeObjectID

public boolean changeObjectID(ObjectID oldID,
                              ObjectID newID)
Description copied from interface: IObjectManager
This method changes an object's ObjectID.

Specified by:
changeObjectID in interface IObjectManager