* @param isError
* <code>true</code> if the result is actual an error
*/
public void sendResponse (final Session session, final CompletionToken token, final AmqpOperations operation, final Object result, final boolean isError)
{
Message message = null;
if (isError) {
// NOTE: create error message
final Error.Builder errorPayload = IdlCommon.Error.newBuilder ();
errorPayload.setToken (token);
errorPayload.setErrorMessage (result.toString ());
message = new Message (AmqpMessage.ERROR, errorPayload.build ());
} else {
switch (operation) {
case DECLARE_EXCHANGE :
case DECLARE_QUEUE :
case BIND_QUEUE :
case PUBLISH :
case GET :
case CANCEL :
case ACK :
final boolean success = ((Boolean) result).booleanValue ();
if (success) {
final Ok.Builder okPayload = IdlCommon.Ok.newBuilder ();
okPayload.setToken (token);
message = new Message (AmqpMessage.OK, okPayload.build ());
} else {
final NotOk.Builder nokPayload = IdlCommon.NotOk.newBuilder ();
nokPayload.setToken (token);
message = new Message (AmqpMessage.NOK, nokPayload.build ());
}
break;
case CONSUME :
final ConsumeReply.Builder consumePayload = AmqpPayloads.ConsumeReply.newBuilder ();
consumePayload.setToken (token);
consumePayload.setConsumerTag ((String) result);
message = new Message (AmqpMessage.CONSUME_REPLY, consumePayload.build ());
break;
default:
break;
}
}