public class ReplicatorImpl extends java.lang.Object implements Replicator
Replicator.State
Modifier and Type | Field and Description |
---|---|
static int |
NULL_ID |
Constructor and Description |
---|
ReplicatorImpl(com.cloudant.sync.replication.ReplicationStrategy strategy) |
ReplicatorImpl(com.cloudant.sync.replication.ReplicationStrategy strategy,
int id) |
Modifier and Type | Method and Description |
---|---|
void |
complete(com.cloudant.sync.replication.ReplicationStrategyCompleted rc) |
void |
error(com.cloudant.sync.replication.ReplicationStrategyErrored re) |
EventBus |
getEventBus()
Returns an EventBus that clients can use to listen for state changes
for this replicator.
|
int |
getId() |
Replicator.State |
getState()
Returns the
Replicator.State this replicator is in. |
void |
start()
Starts a replication.
|
void |
stop()
Stops an in-progress replication.
|
public static final int NULL_ID
public ReplicatorImpl(com.cloudant.sync.replication.ReplicationStrategy strategy)
public ReplicatorImpl(com.cloudant.sync.replication.ReplicationStrategy strategy, int id)
public void start()
Replicator
Starts a replication.
The replication will continue until the replication is caught up with the source database; that is, until there are no current changes to replicate.
start
can be called from any thread. It spawns background
threads for its work. The methods on the ReplicationListener
may be called from the background threads; any work that needs
to be on the main thread will need to be explicitly executed
on that thread.
start
will spawn a manager thread for the replication and
immediately return.
A given replicator instance can be reused:
Replicator.State.PENDING
,
replication will start.Replicator.State.STARTED
, nothing changes.Replicator.State.STOPPING
, nothing changes.Replicator.State.ERROR
, the replication will restart.
It's likely its going to error again, however, depending on whether
the error is transient or not.Replicator.State.STOPPED
or
Replicator.State.COMPLETE
, the replication will start a
second or further time.start
in interface Replicator
public void stop()
Replicator
Stops an in-progress replication.
Already replicated changes will remain in the datastore database.
stop
can be called from any thread. It will initiate a
shutdown process and return immediately.
The shutdown process may take time as we need to wait for in-flight
network requests to complete before background threads can be safely
stopped. However, no modifications to the database will be made
after stop
is called, including checkpoint related
operations.
Consumers should check
Replicator.getState()
if they need
to know when the replicator has fully stopped. After stop
is
called, the replicator will be in the Replicator.State.STOPPING
state while operations complete and will move to the
Replicator.State.STOPPED
state when the replicator has fully
shutdown.
It is also possible the replicator moves to the
Replicator.State.ERROR
state if an error happened during the
shutdown process.
If the replicator is in the Replicator.State.PENDING
state,
it will immediately move to the Replicator.State.STOPPED
state.
stop
in interface Replicator
public Replicator.State getState()
Replicator
Returns the Replicator.State
this replicator is in.
getState
may be called from any thread.
In all states other than Replicator.State.STARTED
and
Replicator.State.STOPPING
, the replicator object
is idle with no background threads.
getState
in interface Replicator
Replicator.State
this replicator is inpublic void complete(com.cloudant.sync.replication.ReplicationStrategyCompleted rc)
public void error(com.cloudant.sync.replication.ReplicationStrategyErrored re)
public EventBus getEventBus()
Replicator
Returns an EventBus that clients can use to listen for state changes for this replicator.
The replicator raises the following events:
ReplicationErrored
if
there is an error during replication.ReplicationCompleted
when the replication is completed, unless there is an error.getEventBus
in interface Replicator
public int getId()
getId
in interface Replicator