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

org.fiolino.common.processing.sink.StoppableChainedSink Maven / Gradle / Ivy

Go to download

General structure to easily create dynamic logic via MethodHandles and others.

There is a newer version: 1.0.10
Show newest version
package org.fiolino.common.processing.sink;

import org.fiolino.common.container.Container;

/**
 * Created by kuli on 31.03.16.
 */
public class StoppableChainedSink extends ChainedSink implements StoppableSink {
    private volatile boolean stopped;

    public StoppableChainedSink(Sink target) {
        super(target);
    }

    @Override
    public final void accept(T value, Container metadata) throws Exception {
        checkStoppedState();
        doAccept(value, metadata);
    }

    protected void doAccept(T value, Container metadata) throws Exception {
        getTarget().accept(value, metadata);
    }

    protected void checkStoppedState() {
        if (stopped) {
            throw new IllegalStateException("Sink is already stopped!");
        }
    }

    @Override
    public final void commit(Container metadata) throws Exception {
        checkStoppedState();
        doCommit(metadata);
    }

    protected void doCommit(Container metadata) throws Exception {
        super.commit(metadata);
    }

    @Override
    public final void stop() throws InterruptedException {
        stopped = true;
        doStop();
    }

    protected void doStop() throws InterruptedException {
        // By default do nothing
    }

    public boolean isStopped() {
        return stopped;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy