public class LocalReplicator extends Object implements Replicator
Replicator
implementation for use by the side that publishes
Revision
s, as well for clients to check for updates
. When a client needs to be updated, it is returned a
SessionToken
through which it can
obtain
the files of that
revision. As long as a revision is being replicated, this replicator
guarantees that it will not be released
.
Replication sessions expire by default after
DEFAULT_SESSION_EXPIRATION_THRESHOLD
, and the threshold can be
configured through setExpirationThreshold(long)
.
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_SESSION_EXPIRATION_THRESHOLD
Threshold for expiring inactive sessions.
|
Constructor and Description |
---|
LocalReplicator() |
Modifier and Type | Method and Description |
---|---|
SessionToken |
checkForUpdate(String currentVersion)
Check whether the given version is up-to-date and returns a
SessionToken which can be used for fetching the revision files,
otherwise returns null . |
void |
close() |
protected void |
ensureOpen()
Ensure that replicator is still open, or throw
AlreadyClosedException otherwise. |
long |
getExpirationThreshold()
Returns the expiration threshold.
|
InputStream |
obtainFile(String sessionID,
String source,
String fileName)
Returns an
InputStream for the requested file and source in the
context of the given session . |
void |
publish(Revision revision)
Publish a new
Revision for consumption by clients. |
void |
release(String sessionID)
Notify that the specified
SessionToken is no longer needed by the
caller. |
void |
setExpirationThreshold(long expirationThreshold)
Modify session expiration time - if a replication session is inactive that
long it is automatically expired, and further attempts to operate within
this session will throw a
SessionExpiredException . |
public static final long DEFAULT_SESSION_EXPIRATION_THRESHOLD
protected final void ensureOpen()
AlreadyClosedException
otherwise.public SessionToken checkForUpdate(String currentVersion)
Replicator
SessionToken
which can be used for fetching the revision files,
otherwise returns null
.
NOTE: when the returned session token is no longer needed, you
should call Replicator.release(String)
so that the session resources can be
reclaimed, including the revision files.
checkForUpdate
in interface Replicator
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public long getExpirationThreshold()
setExpirationThreshold(long)
public InputStream obtainFile(String sessionID, String source, String fileName) throws IOException
Replicator
InputStream
for the requested file and source in the
context of the given session
.
NOTE: it is the caller's responsibility to close the returned stream.
obtainFile
in interface Replicator
SessionExpiredException
- if the specified session has already
expiredIOException
public void publish(Revision revision) throws IOException
Replicator
Revision
for consumption by clients. It is the
caller's responsibility to verify that the revision files exist and can be
read by clients. When the revision is no longer needed, it will be
released
by the replicator.publish
in interface Replicator
IOException
public void release(String sessionID) throws IOException
Replicator
SessionToken
is no longer needed by the
caller.release
in interface Replicator
IOException
public void setExpirationThreshold(long expirationThreshold) throws IOException
SessionExpiredException
.IOException
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.