public class SecondsBehindCallback extends FutureCallback<Reply>
To account for idle servers we use the optime for each server and assign a value of zero to the "latest" optime and then subtract the remaining servers from that optime.
In the case of an exception the seconds behind is set to
Integer.MAX_VALUE
. The value is configurable as a long so in theory a
user can ignore this case using a large
MongoClientConfiguration.setMaxSecondaryLag(long)
.
Lastly, the state of the server is also checked and the seconds behind is set
to Double.MAX_VALUE
if not in the primary (1)
or secondary (2).
Modifier and Type | Field and Description |
---|---|
static Class<DocumentElement> |
DOCUMENT_TYPE
The document element type.
|
static Class<NumericElement> |
NUMERIC_TYPE
The numeric element type.
|
static int |
PRIMARY_STATE
The value for a primary server's state.
|
static int |
SECONDARY_STATE
The value for a secondary (actively replicating) server's state.
|
static Class<TimestampElement> |
TIMESTAMP_TYPE
The timestamp element type.
|
CLASS
Constructor and Description |
---|
SecondsBehindCallback(ServerState server)
Creates a new SecondsBehindCallback.
|
Modifier and Type | Method and Description |
---|---|
void |
callback(Reply result)
Called when the MongoDB operation has completed with the result of the
operation.
|
void |
exception(Throwable error)
Called when the operation fails due to an exception.
|
cancel, get, get, isCancelled, isDone
public static final Class<DocumentElement> DOCUMENT_TYPE
public static final Class<NumericElement> NUMERIC_TYPE
public static final int PRIMARY_STATE
public static final int SECONDARY_STATE
public static final Class<TimestampElement> TIMESTAMP_TYPE
public SecondsBehindCallback(ServerState server)
server
- The server we are tracking the latency for.public void callback(Reply result)
Sets the value for the future and triggers any pending FutureCallback.get()
to
return.
Overridden to update the server's latency based on the round trip reply time.
callback
in interface Callback<Reply>
callback
in class FutureCallback<Reply>
result
- The result of the operation.Callback.callback(V)
public void exception(Throwable error)
Sets the exception for the future and triggers any pending FutureCallback.get()
to throw a ExecutionException
.
Overridden to mark the server as Integer.MAX_VALUE
seconds behind
the primary.
exception
in interface Callback<Reply>
exception
in class FutureCallback<Reply>
error
- The thrown exception.Callback.exception(java.lang.Throwable)
Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.