/** * Perform a synchronous sending of a message. This method block until the message is successfuly sent and a * corresponding reply has been received. * * @param msg The message to send. * @return The reply received. */ public Reply syncSend(Message msg) { return syncSend(msg, defaultTimeout); }
private void syncSendPutDocumentMessage(PutDocumentMessage putDocumentMessage) { Reply reply = syncSend(putDocumentMessage); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply), reply.getErrorCodes()); } } }
private boolean remove(RemoveDocumentMessage msg) { Reply reply = syncSend(msg); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply)); } if (reply.getType() != DocumentProtocol.REPLY_REMOVEDOCUMENT) { throw new DocumentAccessException("Received unknown response: " + reply); } return ((RemoveDocumentReply)reply).wasFound(); }
@Override public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) { UpdateDocumentMessage msg = new UpdateDocumentMessage(update); msg.setPriority(pri); Reply reply = syncSend(msg); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply), reply.getErrorCodes()); } if (reply.getType() != DocumentProtocol.REPLY_UPDATEDOCUMENT) { throw new DocumentAccessException("Received unknown response: " + reply); } return ((UpdateDocumentReply)reply).wasFound(); }
@Override public Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority pri, Duration timeout) { GetDocumentMessage msg = new GetDocumentMessage(id, fieldSet); msg.setPriority(pri); Reply reply = syncSend(msg, timeout != null ? timeout : defaultTimeout); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply)); } if (reply.getType() != DocumentProtocol.REPLY_GETDOCUMENT) { throw new DocumentAccessException("Received unknown response: " + reply); } GetDocumentReply docReply = ((GetDocumentReply)reply); Document doc = docReply.getDocument(); if (doc != null) { doc.setLastModified(docReply.getLastModified()); } return doc; }