@Override public void onMessage(Message m, AckToken token) { if (m instanceof PutDocumentMessage) { appendSingleOpToPendingList(((PutDocumentMessage)m).getDocumentPut(), token); } else if (m instanceof RemoveDocumentMessage) { appendSingleOpToPendingList(((RemoveDocumentMessage)m).getDocumentRemove(), token); } else { throw new UnsupportedOperationException( String.format("Expected put/remove message, got '%s' of type %s", m.toString(), m.getClass().toString())); } }
@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); }
private Document createPutDocument(PutDocumentMessage msg) { Document document = msg.getDocumentPut().getDocument(); String typeName = document.getDataType().getName(); ContainerDocumentConfig.Doctype typeConfig = getDocumentConfig(typeName); if (typeConfig == null) { return document; } return createConcreteDocument(document, typeConfig); }
@Override protected boolean doEncode(DocumentMessage obj, DocumentSerializer buf) { PutDocumentMessage msg = (PutDocumentMessage)obj; if (msg.getSerializedBuffer() != null) { buf.put(null, msg.getSerializedBuffer()); } else { msg.getDocumentPut().getDocument().serialize(buf); buf.putLong(null, msg.getTimestamp()); encodeTasCondition(buf, (TestAndSetMessage) obj); } return true; } }
@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); } }
return selector.accepts(((PutDocumentMessage)msg).getDocumentPut()) == Result.TRUE;
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); } }