Package org.apache.lucene.replicator
Class LocalReplicator
java.lang.Object
org.apache.lucene.replicator.LocalReplicator
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Replicator
A
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)
.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Threshold for expiring inactive sessions. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncheckForUpdate
(String currentVersion) Check whether the given version is up-to-date and returns aSessionToken
which can be used for fetching the revision files, otherwise returnsnull
.void
close()
protected final void
Ensure that replicator is still open, or throwAlreadyClosedException
otherwise.long
Returns the expiration threshold.obtainFile
(String sessionID, String source, String fileName) Returns anInputStream
for the requested file and source in the context of the givensession
.void
Publish a newRevision
for consumption by clients.void
Notify that the specifiedSessionToken
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 aSessionExpiredException
.
-
Field Details
-
DEFAULT_SESSION_EXPIRATION_THRESHOLD
public static final long DEFAULT_SESSION_EXPIRATION_THRESHOLDThreshold for expiring inactive sessions. Defaults to 30 minutes.- See Also:
-
-
Constructor Details
-
LocalReplicator
public LocalReplicator()
-
-
Method Details
-
ensureOpen
protected final void ensureOpen()Ensure that replicator is still open, or throwAlreadyClosedException
otherwise. -
checkForUpdate
Description copied from interface:Replicator
Check whether the given version is up-to-date and returns aSessionToken
which can be used for fetching the revision files, otherwise returnsnull
.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.- Specified by:
checkForUpdate
in interfaceReplicator
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
getExpirationThreshold
public long getExpirationThreshold()Returns the expiration threshold.- See Also:
-
obtainFile
Description copied from interface:Replicator
Returns anInputStream
for the requested file and source in the context of the givensession
.NOTE: it is the caller's responsibility to close the returned stream.
- Specified by:
obtainFile
in interfaceReplicator
- Throws:
SessionExpiredException
- if the specified session has already expiredIOException
-
publish
Description copied from interface:Replicator
Publish a newRevision
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 bereleased
by the replicator.- Specified by:
publish
in interfaceReplicator
- Throws:
IOException
-
release
Description copied from interface:Replicator
Notify that the specifiedSessionToken
is no longer needed by the caller.- Specified by:
release
in interfaceReplicator
- Throws:
IOException
-
setExpirationThreshold
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 aSessionExpiredException
.- Throws:
IOException
-