org.ungoverned.oscar.util
Class DefaultBundleCache

java.lang.Object
  extended by org.ungoverned.oscar.util.DefaultBundleCache
All Implemented Interfaces:
BundleCache

public class DefaultBundleCache
extends java.lang.Object
implements BundleCache

This class, combined with DefaultBundleArchive, implements the default file system-based bundle cache for Oscar. It is possible to configure the default behavior of this class by setting system properties or passing properties into Oscar's constructor. The configuration properties for this class are:

For specific information on how to configure Oscar using system properties, refer to the Oscar usage documentation.

See Also:
DefaultBundleArchive

Field Summary
protected static int BUFSIZE
           
protected static java.lang.String BUNDLE_DIR_PREFIX
           
static java.lang.String CACHE_BUFSIZE_PROP
           
protected static java.lang.String CACHE_DIR_NAME
           
static java.lang.String CACHE_DIR_PROP
           
static java.lang.String CACHE_PROFILE_DIR_PROP
           
static java.lang.String CACHE_PROFILE_PROP
           
 
Constructor Summary
DefaultBundleCache()
           
 
Method Summary
 BundleArchive create(long id, java.lang.String location, java.io.InputStream is)
           Creates a new bundle archive for the specified bundle identifier using the supplied location string and input stream.
 BundleArchive getArchive(long id)
           Returns the bundle archive associated with the specified bundle indentifier.
 BundleArchive[] getArchives()
           Returns all cached bundle archives.
 void initialize(Oscar oscar)
           This method is called before using the BundleCache implementation to initialize it and to pass it a reference to its associated Oscar instance.
 void purge(BundleArchive ba)
           Purges all old revisions of the specified bundle from the cache.
 void remove(BundleArchive ba)
           Removes the specified bundle from the cache.
 void update(BundleArchive ba, java.io.InputStream is)
           Saves an updated revision of the specified bundle to the bundle cache using the supplied input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_BUFSIZE_PROP

public static final java.lang.String CACHE_BUFSIZE_PROP
See Also:
Constant Field Values

CACHE_DIR_PROP

public static final java.lang.String CACHE_DIR_PROP
See Also:
Constant Field Values

CACHE_PROFILE_DIR_PROP

public static final java.lang.String CACHE_PROFILE_DIR_PROP
See Also:
Constant Field Values

CACHE_PROFILE_PROP

public static final java.lang.String CACHE_PROFILE_PROP
See Also:
Constant Field Values

BUFSIZE

protected static transient int BUFSIZE

CACHE_DIR_NAME

protected static final transient java.lang.String CACHE_DIR_NAME
See Also:
Constant Field Values

BUNDLE_DIR_PREFIX

protected static final transient java.lang.String BUNDLE_DIR_PREFIX
See Also:
Constant Field Values
Constructor Detail

DefaultBundleCache

public DefaultBundleCache()
Method Detail

initialize

public void initialize(Oscar oscar)
                throws java.lang.Exception
Description copied from interface: BundleCache

This method is called before using the BundleCache implementation to initialize it and to pass it a reference to its associated Oscar instance. The main purpose for passing the BundleCache implementation a reference to its Oscar instance is to allow it to use Oscar.getConfigProperty() to access system property values; the BundleCache implementation should not use System.getProperty() directly. Oscar.getConfigProperty() provides access to properties passed into the Oscar instance's constructor. If no properties were passed in to the constructor then it searches System.getProperty(). This approach allows multiple instances of Oscar to exist in memory at the same time, but for them to be configured differently. For example, an application may want two instances of Oscar, where each instance stores their cache in a different location in the file system. When using multiple instances of Oscar in memory at the same time, system properties should be avoided and all properties should be passed in to Oscar's constructor.

Specified by:
initialize in interface BundleCache
Parameters:
oscar - the Oscar instance associated with the bundle cache.
Throws:
java.lang.Exception - if any error occurs.

getArchives

public BundleArchive[] getArchives()
                            throws java.lang.Exception
Description copied from interface: BundleCache

Returns all cached bundle archives.

Specified by:
getArchives in interface BundleCache
Returns:
an array of all cached bundle archives.
Throws:
java.lang.Exception - if any error occurs.

getArchive

public BundleArchive getArchive(long id)
                         throws java.lang.Exception
Description copied from interface: BundleCache

Returns the bundle archive associated with the specified bundle indentifier.

Specified by:
getArchive in interface BundleCache
Parameters:
id - the identifier of the bundle archive to retrieve.
Returns:
the bundle archive assocaited with the specified bundle identifier.
Throws:
java.lang.Exception - if any error occurs.

create

public BundleArchive create(long id,
                            java.lang.String location,
                            java.io.InputStream is)
                     throws java.lang.Exception
Description copied from interface: BundleCache

Creates a new bundle archive for the specified bundle identifier using the supplied location string and input stream. The contents of the bundle JAR file should be read from the supplied input stream, which will not be null. The input stream is closed by the caller; the implementation is only responsible for closing streams it opens. If this method completes successfully, then it means that the initial bundle revision of the specified bundle was successfully cached.

Specified by:
create in interface BundleCache
Parameters:
id - the identifier of the bundle associated with the new archive.
location - the location of the bundle associated with the new archive.
is - the input stream to the bundle's JAR file.
Returns:
the created bundle archive.
Throws:
java.lang.Exception - if any error occurs.

update

public void update(BundleArchive ba,
                   java.io.InputStream is)
            throws java.lang.Exception
Description copied from interface: BundleCache

Saves an updated revision of the specified bundle to the bundle cache using the supplied input stream. The contents of the updated bundle JAR file should be read from the supplied input stream, which will not be null. The input stream is closed by the caller; the implementation is only responsible for closing streams it opens. Updating a bundle in the cache does not replace the current revision of the bundle, it makes a new revision available. If this method completes successfully, then it means that the number of revisions of the specified bundle has increased by one.

Specified by:
update in interface BundleCache
Parameters:
ba - the bundle archive of the bundle to update.
is - the input stream to the bundle's updated JAR file.
Throws:
java.lang.Exception - if any error occurs.

purge

public void purge(BundleArchive ba)
           throws java.lang.Exception
Description copied from interface: BundleCache

Purges all old revisions of the specified bundle from the cache. If this method completes successfully, then it means that only the most current revision of the bundle should exist in the cache.

Specified by:
purge in interface BundleCache
Parameters:
ba - the bundle archive of the bundle to purge.
Throws:
java.lang.Exception - if any error occurs.

remove

public void remove(BundleArchive ba)
            throws java.lang.Exception
Description copied from interface: BundleCache

Removes the specified bundle from the cache. If this method completes successfully, there should be no trace of the removed bundle in the cache.

Specified by:
remove in interface BundleCache
Parameters:
ba - the bundle archive of the bundle to remove.
Throws:
java.lang.Exception - if any error occurs.