@Override public Document doUpcast( SerializedObject<Document> intermediateRepresentation, UpcastingContext context) { // here, we convert the XML format of the old event to that of the new event Document data = intermediateRepresentation.getData(); Element rootElement = data.getRootElement(); // change the name of the root element to reflect the changed class name rootElement.setName(NewToDoItemWithDeadlineCreatedEvent.class.getName()); // and add an element for the new "deadline" field rootElement .addElement("deadline") // we set the value of the field to the default value: one day after the event was created .setText(context.getTimestamp().plusDays(1).toString()); // we return the modified Document return data; }
/** * Initialized a DispatchMessage for the given <code>commandMessage</code>, to be serialized using * given <code>serializer</code>. <code>expectReply</code> indicates whether the sender will be * expecting a reply. * * @param commandMessage The message to send to the remote segment * @param serializer The serialize to serialize the message payload and metadata with * @param expectReply whether or not the sender is waiting for a reply. */ public DispatchMessage( CommandMessage<?> commandMessage, Serializer serializer, boolean expectReply) { this.commandIdentifier = commandMessage.getIdentifier(); this.expectReply = expectReply; SerializedObject<byte[]> payload = serializePayload(commandMessage, serializer, byte[].class); SerializedObject<byte[]> metaData = serializeMetaData(commandMessage, serializer, byte[].class); payloadType = payload.getType().getName(); payloadRevision = payload.getType().getRevision(); serializedPayload = payload.getData(); serializedMetaData = metaData.getData(); commandName = commandMessage.getCommandName(); }
private EventEntry(Serializer serializer, DomainEventMessage event) { this.eventIdentifier = event.getIdentifier(); Class<?> serializationTarget = String.class; if (serializer.canSerializeTo(DBObject.class)) { serializationTarget = DBObject.class; } SerializedObject serializedPayloadObject = serializePayload(event, serializer, serializationTarget); SerializedObject serializedMetaDataObject = serializeMetaData(event, serializer, serializationTarget); this.serializedPayload = serializedPayloadObject.getData(); this.payloadType = serializedPayloadObject.getType().getName(); this.payloadRevision = serializedPayloadObject.getType().getRevision(); this.serializedMetaData = serializedMetaDataObject.getData(); this.sequenceNumber = event.getSequenceNumber(); this.timestamp = event.getTimestamp().toEpochMilli(); }