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

io.snice.protocol.ResponseSupport Maven / Gradle / Ivy

package io.snice.protocol;

import java.util.Optional;

public class ResponseSupport extends TransactionSupport implements Response {

    private final boolean isFinal;

    protected ResponseSupport(final TransactionId transactionId, final O owner, final boolean isFinal, final Optional payload) {
        super(transactionId, owner, payload);
        this.isFinal = isFinal;
    }

    protected ResponseSupport(final TransactionId transactionId, final O owner, final boolean isFinal) {
        super(transactionId, owner);
        this.isFinal = isFinal;
    }

    protected ResponseSupport(final TransactionId transactionId, final O owner) {
        super(transactionId, owner);
        this.isFinal = true;
    }

    @Override
    public boolean isFinal() {
        return isFinal;
    }

    public static class BuilderSupport implements Response.Builder {

        private final TransactionId transactionId;
        private final O owner;
        private final Optional payload;

        private boolean isFinal = true;

        protected BuilderSupport(final TransactionId transactionId, final O owner, final Optional payload) {
            this.transactionId = transactionId;
            this.owner = owner;
            this.payload = payload;
        }

        @Override
        public Builder isFinal(final boolean value) {
            this.isFinal = value;
            return this;
        }

        @Override
        public final Response build() {
            return internalBuild(transactionId, owner, payload, isFinal);
        }

        /**
         * Meant for sub-classes to override in order to return a more specific {@link Response} class.
         *
         * @param id
         * @param owner
         * @param payload
         * @param isFinal
         * @return
         */
        protected Response internalBuild(final TransactionId id, final O owner, final Optional payload, final boolean isFinal) {
            return new ResponseSupport(id, owner, isFinal, payload);
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy