/**
  * 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();
    }