F
- The type for the converted Reply
.public abstract class AbstractReplyCallback<F> extends Object implements Callback<Reply>
Reply
message
into a different type of result.Modifier and Type | Field and Description |
---|---|
static String |
ERROR_CODE_FIELD
The fields that may contain the error code.
|
static List<String> |
ERROR_MESSAGE_FIELDS
The fields that may contain the error message.
|
Constructor and Description |
---|
AbstractReplyCallback(Callback<F> forwardCallback)
Create a new AbstractReplyCallback.
|
Modifier and Type | Method and Description |
---|---|
protected MongoDbException |
asError(Reply reply)
Creates an exception from the
Reply . |
protected MongoDbException |
asError(Reply reply,
boolean knownError)
Creates an exception from the
Reply . |
protected MongoDbException |
asError(Reply reply,
int okValue,
int errorNumber,
String errorMessage)
Creates an exception from the parsed reply fields.
|
protected String |
asString(Element errorMessageElem)
Converts the
Element to a string. |
void |
callback(Reply result)
Called when the MongoDB operation has completed with the result of the
operation.
|
protected void |
checkForError(Reply reply)
Checks for a non-flag error in the reply.
|
protected abstract F |
convert(Reply reply)
Converts the
Reply into the final response type. |
void |
exception(Throwable thrown)
Called when the operation fails due to an exception.
|
Callback<F> |
getForwardCallback()
Returns the forwardCallback value.
|
protected int |
toInt(Element element)
Converts a
NumericElement into an int value. |
protected void |
verify(Reply reply)
Checks the reply for an error message.
|
public static final String ERROR_CODE_FIELD
public void callback(Reply result)
Overridden to verify
the reply and then
convert
it to the final result.
callback
in interface Callback<Reply>
result
- The result of the operation.Callback.callback(V)
public void exception(Throwable thrown)
Overridden to forward the exception to the myForwardCallback
.
exception
in interface Callback<Reply>
thrown
- The thrown exception.Callback.exception(java.lang.Throwable)
public Callback<F> getForwardCallback()
protected MongoDbException asError(Reply reply)
Reply
.reply
- The raw reply.protected MongoDbException asError(Reply reply, boolean knownError)
Reply
.reply
- The raw reply.knownError
- If true then the reply is assumed to be an error reply.protected MongoDbException asError(Reply reply, int okValue, int errorNumber, String errorMessage)
reply
- The raw reply.okValue
- The 'ok' field.errorNumber
- The 'errno' field.errorMessage
- The 'errmsg' field.protected String asString(Element errorMessageElem)
Element
to a string. If a StringElement
the
value of the element is returned. In all other cases the toString()
result for the element is returned.errorMessageElem
- The element to convert to a string.Element
's string value.protected void checkForError(Reply reply) throws MongoDbException
reply
- The reply to check.MongoDbException
- On an error represented in the reply.protected abstract F convert(Reply reply) throws MongoDbException
Reply
into the final response type.reply
- The reply to convert.MongoDbException
- On a failure converting the reply. Generally, the
verify(Reply)
method should be used to report
errors.protected int toInt(Element element)
NumericElement
into an int value. If not a
NumericElement
then -1 is returned.element
- The element to convert.protected void verify(Reply reply) throws MongoDbException
reply
- The Reply to verify is successful.MongoDbException
- On a failure message in the reply.Copyright © 2011-2012 Allanbank Consulting, Inc.. All Rights Reserved.