public class LocalReplicator extends Object implements Replicator
Replicator implementation for use by the side that publishes
Revisions, 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)
ReplicatorSessionToken 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 Replicatorpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic long getExpirationThreshold()
setExpirationThreshold(long)public InputStream obtainFile(String sessionID, String source, String fileName) throws IOException
ReplicatorInputStream 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 ReplicatorSessionExpiredException - if the specified session has already
expiredIOExceptionpublic void publish(Revision revision) throws IOException
ReplicatorRevision 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 ReplicatorIOExceptionpublic void release(String sessionID) throws IOException
ReplicatorSessionToken is no longer needed by the
caller.release in interface ReplicatorIOExceptionpublic void setExpirationThreshold(long expirationThreshold)
throws IOException
SessionExpiredException.IOExceptionCopyright © 2000-2024 Apache Software Foundation. All Rights Reserved.