/** * Creates an empty UpdateDocumentMessage */ public static UpdateDocumentMessage createEmpty() { return new UpdateDocumentMessage(null); }
@Override protected boolean doEncode(DocumentMessage obj, DocumentSerializer buf) { UpdateDocumentMessage msg = (UpdateDocumentMessage)obj; if (msg.getSerializedBuffer() != null) { buf.put(null, msg.getSerializedBuffer()); } else { msg.getDocumentUpdate().serialize(buf); buf.putLong(null, msg.getOldTimestamp()); buf.putLong(null, msg.getNewTimestamp()); encodeTasCondition(buf, (TestAndSetMessage) obj); } return true; } }
/** * Returns the document update to perform. * * @return The update. */ public DocumentUpdate getDocumentUpdate() { deserialize(); return update; }
@Override public Result update(DocumentUpdate update, DocumentProtocol.Priority pri) { UpdateDocumentMessage msg = new UpdateDocumentMessage(update); msg.setPriority(pri); return send(msg); }
protected void decodeInto(UpdateDocumentMessage msg, DocumentDeserializer buf) { msg.setDocumentUpdate(new DocumentUpdate(buf)); msg.setOldTimestamp(buf.getLong(null)); msg.setNewTimestamp(buf.getLong(null)); decodeTasCondition(msg, buf); }
@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; } }
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; }
@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(); }
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); } }
@Override protected DocumentMessage doDecode(DocumentDeserializer buffer) { final LazyDecoder decoder = (obj, buf) -> { decodeInto((UpdateDocumentMessage) obj, buf); }; return new UpdateDocumentMessage(decoder, buffer); }
return selector.accepts(((UpdateDocumentMessage)msg).getDocumentUpdate()) != Result.FALSE;
/** * Returns the timestamp required for this update to be applied. * * @return The document timestamp. */ public long getOldTimestamp() { deserialize(); return oldTime; }
private static DocumentMessage newMessage(DocumentOperation documentOperation) { final TestAndSetMessage message; if (documentOperation instanceof DocumentPut) { message = new PutDocumentMessage(((DocumentPut)documentOperation)); } else if (documentOperation instanceof DocumentUpdate) { message = new UpdateDocumentMessage((DocumentUpdate)documentOperation); } else if (documentOperation instanceof DocumentRemove) { message = new RemoveDocumentMessage(documentOperation.getId()); } else { throw new UnsupportedOperationException(documentOperation.getClass().getName()); } message.setCondition(documentOperation.getCondition()); return message; }
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); } }
/** * Returns the timestamp to assign to the updated document. * * @return The document timestamp. */ public long getNewTimestamp() { deserialize(); return newTime; }
static DocumentOperationMessageV3 newUpdateMessage(VespaXMLFeedReader.Operation op, String operationId) { DocumentUpdate update = op.getDocumentUpdate(); update.setCondition(op.getCondition()); Message msg = new UpdateDocumentMessage(update); String id = (operationId == null) ? update.getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); }
@Override public TestAndSetCondition getCondition() { deserialize(); return update.getCondition(); }
@Override public long getSequenceId() { deserialize(); return Arrays.hashCode(update.getId().getGlobalId()); }