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

de.otto.synapse.channel.ShardResponse Maven / Gradle / Ivy

Go to download

A library used at otto.de to implement Spring Boot based event-sourcing microservices.

There is a newer version: 0.33.1
Show newest version
package de.otto.synapse.channel;

import com.google.common.collect.ImmutableList;
import de.otto.synapse.message.TextMessage;

import java.time.Duration;
import java.util.Objects;

public final class ShardResponse {
    private final Duration durationBehind;
    private final ShardPosition shardPosition;
    private final ImmutableList messages;

    private ShardResponse(final ImmutableList messages,
                          final ShardPosition shardPosition,
                          final Duration durationBehind) {

        this.shardPosition = shardPosition;
        this.messages = messages;
        this.durationBehind = durationBehind;
    }

    public static ShardResponse shardResponse(final ShardPosition shardPosition,
                                              final Duration durationBehind,
                                              final ImmutableList messages) {
        return new ShardResponse(messages, shardPosition, durationBehind);
    }

    public static ShardResponse shardResponse(final ShardPosition shardPosition,
                                              final Duration durationBehind,
                                              final TextMessage... messages) {
        return new ShardResponse(messages != null
                ? ImmutableList.copyOf(messages)
                : ImmutableList.of(), shardPosition, durationBehind);
    }

    public String getShardName() {
        return shardPosition.shardName();
    }

    public ShardPosition getShardPosition() {
        return shardPosition;
    }

    public Duration getDurationBehind() {
        return durationBehind;
    }

    public ImmutableList getMessages() {
        return messages;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ShardResponse that = (ShardResponse) o;
        return Objects.equals(durationBehind, that.durationBehind) &&
                Objects.equals(shardPosition, that.shardPosition) &&
                Objects.equals(messages, that.messages);
    }

    @Override
    public int hashCode() {
        return Objects.hash(durationBehind, shardPosition, messages);
    }

    @Override
    public String toString() {
        return "ShardResponse{" +
                "durationBehind=" + durationBehind +
                ", shardPosition=" + shardPosition +
                ", messages=" + messages +
                '}';
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy