@Override protected DocumentReply doDecode(DocumentDeserializer buf) { GetDocumentReply reply = new GetDocumentReply(decoder, buf); return reply; }
/** * Returns the date the document was last modified. * * @return The date. */ public long getLastModified() { deserialize(); return lastModified; }
@Override protected boolean doEncode(DocumentReply obj, DocumentSerializer buf) { GetDocumentReply reply = (GetDocumentReply)obj; if (reply.getSerializedBuffer() != null) { buf.put(null, reply.getSerializedBuffer()); } else { Document document = reply.getDocument(); buf.putByte(null, (byte)(document == null ? 0 : 1)); if (document != null) { document.serialize(buf); } buf.putLong(null, reply.getLastModified()); } return true; } }
@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; }
public void decode(Routable obj, DocumentDeserializer buf) { GetDocumentReply reply = (GetDocumentReply)obj; Document doc = null; byte flag = buf.getByte(null); if (flag != 0) { doc = Document.createDocument(buf); reply.setDocument(doc); } long lastModified = buf.getLong(null); reply.setLastModified(lastModified); if (doc != null) { doc.setLastModified(lastModified); } } };
private boolean resourceWasFound(Reply r) { if (r instanceof RemoveDocumentReply) { return ((RemoveDocumentReply) r).wasFound(); } if (r instanceof UpdateDocumentReply) { return ((UpdateDocumentReply) r).wasFound(); } if (r instanceof GetDocumentReply) { return ((GetDocumentReply) r).getLastModified() > 0; } return false; }
private static Response toSuccess(Reply reply, long reqId) { switch (reply.getType()) { case DocumentProtocol.REPLY_GETDOCUMENT: GetDocumentReply docReply = ((GetDocumentReply) reply); Document getDoc = docReply.getDocument(); if (getDoc != null) { getDoc.setLastModified(docReply.getLastModified()); } return new DocumentResponse(reqId, getDoc); case DocumentProtocol.REPLY_REMOVEDOCUMENT: return new RemoveResponse(reqId, ((RemoveDocumentReply)reply).wasFound()); case DocumentProtocol.REPLY_UPDATEDOCUMENT: return new UpdateResponse(reqId, ((UpdateDocumentReply)reply).wasFound()); case DocumentProtocol.REPLY_PUTDOCUMENT: break; default: return new Response(reqId); } Message msg = reply.getMessage(); switch (msg.getType()) { case DocumentProtocol.MESSAGE_PUTDOCUMENT: return new DocumentResponse(reqId, ((PutDocumentMessage)msg).getDocumentPut().getDocument()); case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: return new DocumentIdResponse(reqId, ((RemoveDocumentMessage)msg).getDocumentId()); case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: return new DocumentUpdateResponse(reqId, ((UpdateDocumentMessage)msg).getDocumentUpdate()); default: return new Response(reqId); } }
@Override public DocumentReply createReply() { return new GetDocumentReply(); }
/** * Returns the document retrieved. * * @return The document. */ public Document getDocument() { deserialize(); return document; }