org.fiolino.common.processing.sink.ChainedSink Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons Show documentation
Show all versions of commons Show documentation
General structure to easily create dynamic logic via MethodHandles and others.
package org.fiolino.common.processing.sink;
import org.fiolino.common.container.Container;
/**
* Created by Michael Kuhlmann on 23.12.2015.
*/
public abstract class ChainedSink implements Sink {
private final Sink super U> target;
protected ChainedSink(Sink super U> target) {
this.target = target;
}
public Sink super U> getTarget() {
return target;
}
@Override
public void commit(Container metadata) throws Exception {
getTarget().commit(metadata);
}
protected Sink super U> targetForCloning() {
return targetForCloning(getTarget());
}
public static Sink targetForCloning(Sink target) {
if (target instanceof CloneableSink) {
return ((CloneableSink) target).createClone();
}
if (target instanceof ThreadsafeSink) {
return target;
}
throw new IllegalStateException("Target " + target + " is neither thread safe nor cloneable!");
}
}