public class ReplicationClient extends Object implements Closeable
Replicator
.
It can be used to either periodically check for updates by invoking
startUpdateThread(long, java.lang.String)
, or manually by calling updateNow()
.
Whenever a new revision is available, the requiredFiles(Map)
are
copied to the Directory
specified by PerSessionDirectoryFactory
and
a handler is notified.
Modifier and Type | Class and Description |
---|---|
static interface |
ReplicationClient.ReplicationHandler
Handler for revisions obtained by the client.
|
static interface |
ReplicationClient.SourceDirectoryFactory
Resolves a session and source into a
Directory to use for copying
the session files to. |
Modifier and Type | Field and Description |
---|---|
static String |
INFO_STREAM_COMPONENT
The component name to use with
InfoStream.isEnabled(String) . |
Constructor and Description |
---|
ReplicationClient(Replicator replicator,
ReplicationClient.ReplicationHandler handler,
ReplicationClient.SourceDirectoryFactory factory)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
ensureOpen()
Throws
AlreadyClosedException if the client has already been closed. |
protected void |
handleUpdateException(Throwable t)
Called when an exception is hit by the replication thread.
|
boolean |
isUpdateThreadAlive()
Returns true if the update thread is alive.
|
protected Map<String,List<RevisionFile>> |
requiredFiles(Map<String,List<RevisionFile>> newRevisionFiles)
Returns the files required for replication.
|
void |
setInfoStream(InfoStream infoStream)
Sets the
InfoStream to use for logging messages. |
void |
startUpdateThread(long intervalMillis,
String threadName)
Start the update thread with the specified interval in milliseconds.
|
void |
stopUpdateThread()
Stop the update thread.
|
String |
toString() |
void |
updateNow()
Executes the update operation immediately, irregardless if an update thread
is running or not.
|
public static final String INFO_STREAM_COMPONENT
InfoStream.isEnabled(String)
.public ReplicationClient(Replicator replicator, ReplicationClient.ReplicationHandler handler, ReplicationClient.SourceDirectoryFactory factory)
replicator
- the Replicator
used for checking for updateshandler
- notified when new revisions are readyfactory
- returns a Directory
for a given source and sessionprotected final void ensureOpen()
AlreadyClosedException
if the client has already been closed.protected void handleUpdateException(Throwable t)
InfoStream
set in
setInfoStream(InfoStream)
, or the default
one. You can override to log the exception elswhere.
NOTE: if you override this method to throw the exception further,
the replication thread will be terminated. The only way to restart it is to
call stopUpdateThread()
followed by
startUpdateThread(long, String)
.
protected Map<String,List<RevisionFile>> requiredFiles(Map<String,List<RevisionFile>> newRevisionFiles)
public void close()
close
in interface Closeable
close
in interface AutoCloseable
public void startUpdateThread(long intervalMillis, String threadName)
Thread.setName(String)
. If you pass null
, a default name
will be set.IllegalStateException
- if the thread has already been startedpublic void stopUpdateThread()
public boolean isUpdateThreadAlive()
started
and not
stopped
, as well as didn't hit an error which
caused it to terminate (i.e. handleUpdateException(Throwable)
threw the exception further).public void updateNow() throws IOException
IOException
public void setInfoStream(InfoStream infoStream)
InfoStream
to use for logging messages.Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.