@Override protected boolean doEncode(DocumentMessage obj, DocumentSerializer buf) { RemoveDocumentMessage msg = (RemoveDocumentMessage)obj; msg.getDocumentId().serialize(buf); encodeTasCondition(buf, (TestAndSetMessage) obj); return true; } }
@Override public void onMessage(Message m, AckToken token) { if (m instanceof PutDocumentMessage) { PutDocumentMessage pm = (PutDocumentMessage)m; onDocument(pm.getDocumentPut().getDocument(), pm.getTimestamp()); } else if (m instanceof RemoveDocumentMessage) { RemoveDocumentMessage rm = (RemoveDocumentMessage)m; onRemove(rm.getDocumentId()); } else { throw new UnsupportedOperationException("Received unsupported message " + m.toString() + " to dump visitor data handler. This handler only accepts Put and Remove"); } ack(token); }
public List<Processing> fromMessage(Message message) { List<Processing> processings = new ArrayList<>(); switch (message.getType()) { case DocumentProtocol.MESSAGE_PUTDOCUMENT: { PutDocumentMessage putMessage = (PutDocumentMessage) message; DocumentPut putOperation = new DocumentPut(createPutDocument(putMessage)); putOperation.setCondition(putMessage.getCondition()); processings.add(createProcessing(putOperation, message)); break; } case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: { UpdateDocumentMessage updateMessage = (UpdateDocumentMessage) message; DocumentUpdate updateOperation = updateMessage.getDocumentUpdate(); updateOperation.setCondition(updateMessage.getCondition()); processings.add(createProcessing(updateOperation, message)); break; } case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: { RemoveDocumentMessage removeMessage = (RemoveDocumentMessage) message; DocumentRemove removeOperation = new DocumentRemove(removeMessage.getDocumentId()); removeOperation.setCondition(removeMessage.getCondition()); processings.add(createProcessing(removeOperation, message)); break; } } return processings; }
@SuppressWarnings("deprecation") private BucketId getBucketId(Message msg) { switch (msg.getType()) { case DocumentProtocol.MESSAGE_PUTDOCUMENT: return factory.getBucketId(((PutDocumentMessage)msg).getDocumentPut().getDocument().getId()); case DocumentProtocol.MESSAGE_GETDOCUMENT: return factory.getBucketId(((GetDocumentMessage)msg).getDocumentId()); case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: return factory.getBucketId(((RemoveDocumentMessage)msg).getDocumentId()); case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: return factory.getBucketId(((UpdateDocumentMessage)msg).getDocumentUpdate().getId()); case DocumentProtocol.MESSAGE_GETBUCKETLIST: return ((GetBucketListMessage)msg).getBucketId(); case DocumentProtocol.MESSAGE_STATBUCKET: return ((StatBucketMessage)msg).getBucketId(); case DocumentProtocol.MESSAGE_CREATEVISITOR: return ((CreateVisitorMessage)msg).getBuckets().get(0); case DocumentProtocol.MESSAGE_REMOVELOCATION: return ((RemoveLocationMessage)msg).getBucketId(); default: log.log(LogLevel.ERROR, "Message type '" + msg.getType() + "' not supported."); return null; } }
private static Response toError(Reply reply, long reqId) { Message msg = reply.getMessage(); String err = getErrorMessage(reply); switch (msg.getType()) { case DocumentProtocol.MESSAGE_PUTDOCUMENT: return new DocumentResponse(reqId, ((PutDocumentMessage)msg).getDocumentPut().getDocument(), err, false); case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: return new DocumentUpdateResponse(reqId, ((UpdateDocumentMessage)msg).getDocumentUpdate(), err, false); case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: return new DocumentIdResponse(reqId, ((RemoveDocumentMessage)msg).getDocumentId(), err, false); case DocumentProtocol.MESSAGE_GETDOCUMENT: return new DocumentIdResponse(reqId, ((GetDocumentMessage)msg).getDocumentId(), err, false); default: return new Response(reqId, err, false); } }
if (removeMsg.getDocumentId().hasDocType()) { return selector.accepts(removeMsg.getDocumentRemove()) != Result.FALSE; } else {
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); } }