autohit.universe.service
Class UniverseLocal

java.lang.Object
  extended byautohit.universe.service.UniverseLocal
All Implemented Interfaces:
Universe

public class UniverseLocal
extends java.lang.Object
implements Universe

Universe server implimentation for a local filesystem. This does NOT implement caching! Every object is unique. The 'root' property should be a path to the root of the universe on the filesystem. It should begin with a '/', and should have no trailing slashes. This universe assumes that storable objects can be serialized completely. If you plan on moving data that isn't in objects or are not inherently able to seriously completely, then you should obtain streams for put and get, and handle the IO yourself.

Version:
1.0 Version History EPG - New - 24Apr03
Author:
Erich P. Gatejen

Constructor Summary
UniverseLocal()
           
 
Method Summary
 void close()
          This will always be called when the universe is destroyed
 void discard(java.lang.String name)
          Discard an object.
 boolean exists(java.lang.String name)
          Check to see if an object exists
 void flush(java.lang.String name)
          Flush an object.
 void genesis(UniverseProperties props)
          Impliment the genesis.
 java.lang.Object get(java.lang.String name)
          Load an object from the universe.
 javax.activation.DataSource getDataSource(java.lang.String name)
          Get a Data Source that can interact with this universe object
 javax.activation.FileDataSource getFileDataSource(java.lang.String name)
          Get a FileDataSource that can interact with this universe object.
 java.io.InputStream getStream(java.lang.String name)
          Get an InputStream that can read from a universe object dump.
 java.lang.Object getUnique(java.lang.String name)
          Same as get, so just chain it.
 boolean isLocked(java.lang.String name)
          Since objects can never be locked, this will always return false.
 void lock(java.lang.String name)
          There is no locking.
 boolean lockIfNotLocked(java.lang.String name)
          There is no locking, so return true, since the caller is always allowed to get an object.
 void put(java.lang.String name, java.lang.Object o)
          Save an object into the universe.
 java.io.OutputStream putStream(java.lang.String name)
          Get an output stream to a universe object.
 void release(java.lang.String name)
          Release a lock on an object.
 void remove(java.lang.String name)
          Remove an object from the universe
 java.lang.String reserveUnique(java.lang.String base)
          Reserve unique object universe.
 long size(java.lang.String name)
          Report the size object from the universe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UniverseLocal

public UniverseLocal()
Method Detail

genesis

public void genesis(UniverseProperties props)
             throws UniverseException
Impliment the genesis.

Specified by:
genesis in interface Universe
Parameters:
props - a universe properties set
Returns:
the loaded object
Throws:
UniverseException
See Also:
UniverseProperties

close

public void close()
           throws UniverseException
This will always be called when the universe is destroyed

Specified by:
close in interface Universe
Throws:
UniverseException

get

public java.lang.Object get(java.lang.String name)
                     throws UniverseException
Load an object from the universe. It will be unique. There is no caching.

Specified by:
get in interface Universe
Parameters:
name - universe name
Returns:
the loaded object
Throws:
UniverseException

getUnique

public java.lang.Object getUnique(java.lang.String name)
                           throws UniverseException
Same as get, so just chain it.

Specified by:
getUnique in interface Universe
Parameters:
name - universe name
Returns:
the loaded object
Throws:
UniverseException

reserveUnique

public java.lang.String reserveUnique(java.lang.String base)
                               throws UniverseException
Reserve unique object universe. Guarantee it is a unique instance of it. Great for temp objects.

Specified by:
reserveUnique in interface Universe
Parameters:
base - base path for the object (including root object name)
Returns:
name of the reserved unique object.
Throws:
UniverseException - TODO make sure the object can actually be used

getStream

public java.io.InputStream getStream(java.lang.String name)
                              throws UniverseException
Get an InputStream that can read from a universe object dump. It does not assume the target is anything--object, bytes, whatever.

Specified by:
getStream in interface Universe
Parameters:
name - universe name
Returns:
a stream to the object
Throws:
UniverseException

getDataSource

public javax.activation.DataSource getDataSource(java.lang.String name)
                                          throws UniverseException
Get a Data Source that can interact with this universe object

Specified by:
getDataSource in interface Universe
Parameters:
name - universe name
Returns:
a data source
Throws:
UniverseException
UniverseDataSource

getFileDataSource

public javax.activation.FileDataSource getFileDataSource(java.lang.String name)
                                                  throws UniverseException
Get a FileDataSource that can interact with this universe object. The universe must handle making sure the object at least appears local to the FileDataSource

Specified by:
getFileDataSource in interface Universe
Parameters:
name - universe name
Returns:
a data source
Throws:
UniverseException

put

public void put(java.lang.String name,
                java.lang.Object o)
         throws UniverseException
Save an object into the universe. If a file is already there, it will overwrite it.

Specified by:
put in interface Universe
Parameters:
name - universe name
o - the object
Throws:
UniverseException

putStream

public java.io.OutputStream putStream(java.lang.String name)
                               throws UniverseException
Get an output stream to a universe object. CAller responsible for streaming and closing.

Specified by:
putStream in interface Universe
Parameters:
name - universe name
Returns:
a stream to the object
Throws:
UniverseException

lock

public void lock(java.lang.String name)
          throws UniverseException
There is no locking. Always immeadiately return.

Specified by:
lock in interface Universe
Parameters:
name - universe name
Throws:
UniverseException

lockIfNotLocked

public boolean lockIfNotLocked(java.lang.String name)
                        throws UniverseException
There is no locking, so return true, since the caller is always allowed to get an object.

Specified by:
lockIfNotLocked in interface Universe
Parameters:
name - universe name
Returns:
always true
Throws:
UniverseException

isLocked

public boolean isLocked(java.lang.String name)
                 throws UniverseException
Since objects can never be locked, this will always return false.

Specified by:
isLocked in interface Universe
Parameters:
name - universe name
Returns:
always false
Throws:
UniverseException

release

public void release(java.lang.String name)
             throws UniverseException
Release a lock on an object. Do nothing.

Specified by:
release in interface Universe
Parameters:
name - universe name
Throws:
UniverseException

exists

public boolean exists(java.lang.String name)
               throws UniverseException
Check to see if an object exists

Specified by:
exists in interface Universe
Parameters:
name - universe name
Returns:
true if the object exists, otherwise false
Throws:
UniverseException

flush

public void flush(java.lang.String name)
           throws UniverseException
Flush an object. Does nothing, since there is no caching.

Specified by:
flush in interface Universe
Parameters:
name - universe name
Returns:
true if the object exists, otherwise false
Throws:
UniverseException

discard

public void discard(java.lang.String name)
             throws UniverseException
Discard an object. Does nothing, since there is no caching.

Specified by:
discard in interface Universe
Parameters:
name - universe name
Returns:
true if the object exists, otherwise false
Throws:
UniverseException

remove

public void remove(java.lang.String name)
            throws UniverseException
Remove an object from the universe

Specified by:
remove in interface Universe
Parameters:
name - universe name
Returns:
true if the object exists, otherwise false
Throws:
UniverseException

size

public long size(java.lang.String name)
          throws UniverseException
Report the size object from the universe

Specified by:
size in interface Universe
Parameters:
name - universe name
Returns:
the size or 0 if empty
Throws:
UniverseException


Test.