/** * Factory method for a {@link CachingSupplier} that delegates to the given {@code supplier} when asked to supply a * value. If the given {@code supplier} is a {@link CachingSupplier} the instance is returned as is, if not a new * {@link CachingSupplier} instance is created. * * @param supplier supplier for which to cache the result * @param <T> the type of results supplied by this supplier * @return a {@link CachingSupplier} based on given {@code supplier} */ public static <T> CachingSupplier<T> of(Supplier<T> supplier) { if (supplier instanceof CachingSupplier) { return (CachingSupplier<T>) supplier; } return new CachingSupplier<>(supplier); }
/** * Java Serialization API Method that ensures that an instance of this class can be serialized by first invoking * {@link #get()}. */ private void writeObject(ObjectOutputStream stream) throws IOException { get(); stream.defaultWriteObject(); }
/** * Initializes a {@link GenericEventMessage} with given message as delegate and given {@code timestamp}. The * given message will be used supply the payload, metadata and identifier of the resulting event message. * * @param delegate the message that will be used used as delegate * @param timestamp the timestamp of the resulting event message */ protected GenericEventMessage(Message<T> delegate, Instant timestamp) { this(delegate, CachingSupplier.of(timestamp)); }
/** * Constructor to reconstruct an EventMessage using existing data. The timestamp of the event is supplied lazily to * prevent unnecessary deserialization of the timestamp. * * @param delegate The message containing payload, identifier and metadata * @param timestampSupplier Supplier for the timestamp of the Message creation */ public GenericEventMessage(Message<T> delegate, Supplier<Instant> timestampSupplier) { super(delegate); this.timestampSupplier = CachingSupplier.of(timestampSupplier); }
/** * Factory method for a {@link CachingSupplier} that will supply the given {@code value}. * <p> * This factory method should be used when the value is already available. Used this way this supplier can be * serialized. * * @param value the value to supply * @param <T> the type of results supplied by this supplier * @return a {@link CachingSupplier} that supplies the given value */ public static <T> CachingSupplier<T> of(T value) { return new CachingSupplier<>(value); }
/** * Java Serialization API Method that ensures that an instance of this class can be serialized by first invoking * {@link #get()}. */ private void writeObject(ObjectOutputStream stream) throws IOException { get(); stream.defaultWriteObject(); }
metaData = new LazyDeserializingObject<>(eventData.getMetaData(), serializer); eventIdentifier = eventData.getEventIdentifier(); timestamp = CachingSupplier.of(eventData::getTimestamp); if (eventData instanceof DomainEventData<?>) { DomainEventData<?> domainEventData = (DomainEventData<?>) eventData;
/** * Factory method for a {@link CachingSupplier} that will supply the given {@code value}. * <p> * This factory method should be used when the value is already available. Used this way this supplier can be * serialized. * * @param value the value to supply * @param <T> the type of results supplied by this supplier * @return a {@link CachingSupplier} that supplies the given value */ public static <T> CachingSupplier<T> of(T value) { return new CachingSupplier<>(value); }
/** * Java Serialization API Method that ensures that an instance of this class can be serialized by first invoking * {@link #get()}. */ private void writeObject(ObjectOutputStream stream) throws IOException { get(); stream.defaultWriteObject(); }
/** * Constructor to reconstruct an EventMessage using existing data. The timestamp of the event is supplied lazily to * prevent unnecessary deserialization of the timestamp. * * @param delegate The message containing payload, identifier and metadata * @param timestampSupplier Supplier for the timestamp of the Message creation */ public GenericEventMessage(Message<T> delegate, Supplier<Instant> timestampSupplier) { super(delegate); this.timestampSupplier = CachingSupplier.of(timestampSupplier); }
/** * Factory method for a {@link CachingSupplier} that will supply the given {@code value}. * <p> * This factory method should be used when the value is already available. Used this way this supplier can be * serialized. * * @param value the value to supply * @param <T> the type of results supplied by this supplier * @return a {@link CachingSupplier} that supplies the given value */ public static <T> CachingSupplier<T> of(T value) { return new CachingSupplier<>(value); }
/** * Initializes a {@link GenericEventMessage} with given message as delegate and given {@code timestamp}. The * given message will be used supply the payload, metadata and identifier of the resulting event message. * * @param delegate the message that will be used used as delegate * @param timestamp the timestamp of the resulting event message */ protected GenericEventMessage(Message<T> delegate, Instant timestamp) { this(delegate, CachingSupplier.of(timestamp)); }
/** * Factory method for a {@link CachingSupplier} that delegates to the given {@code supplier} when asked to supply a * value. If the given {@code supplier} is a {@link CachingSupplier} the instance is returned as is, if not a new * {@link CachingSupplier} instance is created. * * @param supplier supplier for which to cache the result * @param <T> the type of results supplied by this supplier * @return a {@link CachingSupplier} based on given {@code supplier} */ public static <T> CachingSupplier<T> of(Supplier<T> supplier) { if (supplier instanceof CachingSupplier) { return (CachingSupplier<T>) supplier; } return new CachingSupplier<>(supplier); }
/** * Initializes a {@link GenericEventMessage} with given message as delegate and given {@code timestamp}. The * given message will be used supply the payload, metadata and identifier of the resulting event message. * * @param delegate the message that will be used used as delegate * @param timestamp the timestamp of the resulting event message */ protected GenericEventMessage(Message<T> delegate, Instant timestamp) { this(delegate, CachingSupplier.of(timestamp)); }
/** * Factory method for a {@link CachingSupplier} that delegates to the given {@code supplier} when asked to supply a * value. If the given {@code supplier} is a {@link CachingSupplier} the instance is returned as is, if not a new * {@link CachingSupplier} instance is created. * * @param supplier supplier for which to cache the result * @param <T> the type of results supplied by this supplier * @return a {@link CachingSupplier} based on given {@code supplier} */ public static <T> CachingSupplier<T> of(Supplier<T> supplier) { if (supplier instanceof CachingSupplier) { return (CachingSupplier<T>) supplier; } return new CachingSupplier<>(supplier); }
/** * Constructor to reconstruct an EventMessage using existing data. The timestamp of the event is supplied lazily to * prevent unnecessary deserialization of the timestamp. * * @param delegate The message containing payload, identifier and metadata * @param timestampSupplier Supplier for the timestamp of the Message creation */ public GenericEventMessage(Message<T> delegate, Supplier<Instant> timestampSupplier) { super(delegate); this.timestampSupplier = CachingSupplier.of(timestampSupplier); }
metaData = new LazyDeserializingObject<>(eventData.getMetaData(), serializer); eventIdentifier = eventData.getEventIdentifier(); timestamp = CachingSupplier.of(eventData::getTimestamp); if (eventData instanceof DomainEventData<?>) { DomainEventData<?> domainEventData = (DomainEventData<?>) eventData;
metaData = new LazyDeserializingObject<>(eventData.getMetaData(), serializer); eventIdentifier = eventData.getEventIdentifier(); timestamp = CachingSupplier.of(eventData::getTimestamp); if (eventData instanceof DomainEventData<?>) { DomainEventData<?> domainEventData = (DomainEventData<?>) eventData;