@Override public Document get(DocumentId id) { return get(id, null); }
@Override public void put(DocumentPut documentPut) { put(documentPut, DocumentProtocol.Priority.NORMAL_3); }
/** * 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); }
@Override public boolean remove(DocumentRemove documentRemove) { RemoveDocumentMessage msg = new RemoveDocumentMessage(documentRemove.getId()); msg.setCondition(documentRemove.getCondition()); return remove(msg); }
@Override public boolean update(DocumentUpdate update) { return update(update, DocumentProtocol.Priority.NORMAL_2); }
@Override public MessageBusSyncSession createSyncSession(SyncParameters parameters) { return new MessageBusSyncSession(parameters, messageBus(), this.params); }
private void setRoute(SyncSession session, Optional<String> route) throws RestApiException { if (! (session instanceof MessageBusSyncSession)) { // Not sure if this ever could happen but better be safe. throw new RestApiException(Response.createErrorResponse( 400, "Can not set route since the API is not using message bus.", RestUri.apiErrorCodes.NO_ROUTE_WHEN_NOT_PART_OF_MESSAGEBUS)); } ((MessageBusSyncSession) session).setRoute(route.orElse("default")); }
@Override public void put(DocumentPut documentPut, DocumentProtocol.Priority priority) { PutDocumentMessage msg = new PutDocumentMessage(documentPut); msg.setPriority(priority); syncSendPutDocumentMessage(msg); }
@Override public boolean remove(DocumentRemove documentRemove, DocumentProtocol.Priority pri) { RemoveDocumentMessage msg = new RemoveDocumentMessage(documentRemove.getId()); msg.setPriority(pri); msg.setCondition(documentRemove.getCondition()); return remove(msg); }
private void syncSendPutDocumentMessage(PutDocumentMessage putDocumentMessage) { Reply reply = syncSend(putDocumentMessage); if (reply.hasErrors()) { throw new DocumentAccessException(MessageBusAsyncSession.getErrorMessage(reply), reply.getErrorCodes()); } } }
@Override public Document get(DocumentId id, String fieldSet, DocumentProtocol.Priority pri) { return get(id, fieldSet, pri, null); }
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 Document get(DocumentId id, Duration timeout) { return get(id, "[all]", DocumentProtocol.Priority.NORMAL_1, timeout); }
@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; }