org.apache.ace.repository.ext.impl
Class CachedRepositoryImpl

java.lang.Object
  extended by org.apache.ace.repository.ext.impl.CachedRepositoryImpl
All Implemented Interfaces:
CachedRepository, org.apache.ace.repository.Repository

public class CachedRepositoryImpl
extends Object
implements CachedRepository

Provides a CachedRepository, which uses either a Repository and a BackupRepository as remote and local storage, or a URL location and two files, from which it will create a Repository and a FileBasedBackupRepository. Note that this class is not thread-safe, and should be synchronized by the caller.


Field Summary
static long UNCOMMITTED_VERSION
           
 
Constructor Summary
CachedRepositoryImpl(org.osgi.service.useradmin.User user, org.apache.ace.repository.Repository remote, BackupRepository backup, long mostRecentVersion)
          Creates a cached repository using.
CachedRepositoryImpl(org.osgi.service.useradmin.User user, URL remote, String customer, String name, File local, File backup, long mostRecentVersion)
          Creates a cached repository which uses remote, customer and name to create a RemoteRepository, and uses the Filess passed in as a for local storage and backup.
 
Method Summary
 InputStream checkout(boolean fail)
          Checks our the most current version from the actual repository.
 InputStream checkout(long version)
           
 boolean commit()
          Commits the most current version to the actual repository.
 boolean commit(InputStream data, long fromVersion)
           
 boolean commit(long fromVersion)
           
 InputStream getLocal(boolean fail)
          Gets the most recent version of the object.
 long getMostRecentVersion()
          Gets the most recent version of this repository, that is, the most recent version number that is either committed (successfully) or checked out.
 org.apache.ace.range.SortedRangeSet getRange()
           
 boolean isCurrent()
          Checks whether the version we have locally is current with respect to the version on the server.
 boolean revert()
          Undoes all changes made using writeLocal() since the last commit or checkout.
 void writeLocal(InputStream data)
          Writes the most recent version of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNCOMMITTED_VERSION

public static final long UNCOMMITTED_VERSION
See Also:
Constant Field Values
Constructor Detail

CachedRepositoryImpl

public CachedRepositoryImpl(org.osgi.service.useradmin.User user,
                            URL remote,
                            String customer,
                            String name,
                            File local,
                            File backup,
                            long mostRecentVersion)
Creates a cached repository which uses remote, customer and name to create a RemoteRepository, and uses the Filess passed in as a for local storage and backup.

Parameters:
user - A user object, which is allowed to access remote.
remote - The location of the remote repository.
customer - The customer name to be used with the remote repository.
name - The name to be used with the remote repository.
local - A local file to be used for storage of changes to the repository.
backup - A local file to be used as a local backup of what was on the server.
mostRecentVersion - The version from which backup was checked out or committed. If no version has been committed yet, use UNCOMMITTED_VERSION.

CachedRepositoryImpl

public CachedRepositoryImpl(org.osgi.service.useradmin.User user,
                            org.apache.ace.repository.Repository remote,
                            BackupRepository backup,
                            long mostRecentVersion)
Creates a cached repository using.

Parameters:
user - A user object, which is allowed to access remote.
remote - A repository which holds committed versions.
backup - A backup repository for local changes.
mostRecentVersion - The version from which backup was checked out or committed. If no version has been committed yet, use UNCOMMITTED_VERSION.
Method Detail

checkout

public InputStream checkout(boolean fail)
                     throws IOException,
                            IllegalArgumentException
Description copied from interface: CachedRepository
Checks our the most current version from the actual repository.

Specified by:
checkout in interface CachedRepository
Parameters:
fail - Indicates that this method should throw an IOException when no data is available. Setting it to false will make it return an empty stream in that case.
Returns:
An input stream representing the checked out object.
Throws:
IOException - Is thrown when the actual repository's commit does.
IllegalArgumentException

checkout

public InputStream checkout(long version)
                     throws IOException,
                            IllegalArgumentException
Specified by:
checkout in interface org.apache.ace.repository.Repository
Throws:
IOException
IllegalArgumentException

commit

public boolean commit(InputStream data,
                      long fromVersion)
               throws IOException,
                      IllegalArgumentException
Specified by:
commit in interface org.apache.ace.repository.Repository
Throws:
IOException
IllegalArgumentException

commit

public boolean commit()
               throws IOException
Description copied from interface: CachedRepository
Commits the most current version to the actual repository.

Specified by:
commit in interface CachedRepository
Returns:
true on success, false on failure (e.g. bad version number)
Throws:
IOException - Is thrown when the actual repository's commit does.

commit

public boolean commit(long fromVersion)
               throws IOException,
                      IllegalArgumentException
Throws:
IOException
IllegalArgumentException

getRange

public org.apache.ace.range.SortedRangeSet getRange()
                                             throws IOException
Specified by:
getRange in interface org.apache.ace.repository.Repository
Throws:
IOException

getLocal

public InputStream getLocal(boolean fail)
                     throws IllegalArgumentException,
                            IOException
Description copied from interface: CachedRepository
Gets the most recent version of the object. If no current version is available, and empty stream will be returned.

Specified by:
getLocal in interface CachedRepository
Parameters:
fail - Indicates that this method should throw an IOException when no data is available. Setting it to false will make it return an empty stream in that case.
Returns:
An input stream representing the most recently written object.
Throws:
IOException - Thrown when there is a problem retrieving the data.
IllegalArgumentException

revert

public boolean revert()
               throws IOException
Description copied from interface: CachedRepository
Undoes all changes made using writeLocal() since the last commit or checkout.

Specified by:
revert in interface CachedRepository
Throws:
IOException

writeLocal

public void writeLocal(InputStream data)
                throws IllegalArgumentException,
                       IOException
Description copied from interface: CachedRepository
Writes the most recent version of the object.

Specified by:
writeLocal in interface CachedRepository
Throws:
IOException - Thrown when there is a problem storing the data.
IllegalArgumentException

getMostRecentVersion

public long getMostRecentVersion()
Description copied from interface: CachedRepository
Gets the most recent version of this repository, that is, the most recent version number that is either committed (successfully) or checked out.

Specified by:
getMostRecentVersion in interface CachedRepository
Returns:
The most recent version of the underlying repository.

isCurrent

public boolean isCurrent()
                  throws IOException
Description copied from interface: CachedRepository
Checks whether the version we have locally is current with respect to the version on the server.

Specified by:
isCurrent in interface CachedRepository
Returns:
whether the version we have locally is current with respect to the version on the server.
Throws:
IOException - Thrown when an error occurs communicating with the server.


Copyright © 2009-2011 The Apache Software Foundation. All Rights Reserved.