All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fluxcapacitor.javaclient.persisting.eventsourcing.EventSourcedModel Maven / Gradle / Ivy

There is a newer version: 0.1015.0
Show newest version
package io.fluxcapacitor.javaclient.persisting.eventsourcing;

import io.fluxcapacitor.javaclient.common.Message;
import io.fluxcapacitor.javaclient.modeling.Aggregate;
import lombok.Builder;
import lombok.Value;
import lombok.experimental.Accessors;

import java.time.Instant;

import static java.lang.String.format;

@Value
@Builder(toBuilder = true)
@Accessors(fluent = true)
public class EventSourcedModel implements Aggregate {
    String id;
    @Builder.Default long sequenceNumber = -1L;
    String lastEventId;
    @Builder.Default Instant timestamp = Instant.now();
    T model;

    @Override
    public T get() {
        return model;
    }

    @Override
    public Aggregate apply(Message eventMessage) {
        throw new UnsupportedOperationException(format("Not allowed to apply a %s. The model is readonly.",
                                                       eventMessage));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy