dev.vality.woody.api.flow.WFlow Maven / Gradle / Ivy
package dev.vality.woody.api.flow;
import dev.vality.woody.api.flow.concurrent.WCallable;
import dev.vality.woody.api.flow.concurrent.WRunnable;
import dev.vality.woody.api.generator.ConfiguredSnowflakeIdGenerator;
import dev.vality.woody.api.generator.IdGenerator;
import dev.vality.woody.api.trace.TraceData;
import dev.vality.woody.api.trace.context.TraceContext;
import java.util.concurrent.Callable;
public class WFlow {
private final IdGenerator traceIdGenerator;
private final IdGenerator spanIdGenerator;
public WFlow() {
this(createDefaultIdGenerator());
}
public WFlow(IdGenerator idGenerator) {
this(idGenerator, idGenerator);
}
public WFlow(IdGenerator traceIdGenerator, IdGenerator spanIdGenerator) {
this.traceIdGenerator = traceIdGenerator;
this.spanIdGenerator = spanIdGenerator;
}
public static IdGenerator createDefaultIdGenerator() {
return new ConfiguredSnowflakeIdGenerator();
}
public static WRunnable create(Runnable runnable) {
return new WRunnable(runnable, TraceContext.getCurrentTraceData());
}
public static WRunnable create(Runnable runnable, TraceData traceData) {
return new WRunnable(runnable, traceData);
}
public static WCallable create(Callable callable) {
return new WCallable<>(callable, TraceContext.getCurrentTraceData());
}
public static WCallable create(Callable callable, TraceData traceData) {
return new WCallable<>(callable, traceData);
}
public static WRunnable createFork(Runnable runnable) {
return create(runnable, new TraceData());
}
public static WCallable createFork(Callable callable) {
return create(callable, new TraceData());
}
public static WRunnable createServiceFork(Runnable runnable, IdGenerator idGenerator) {
return create(runnable, TraceContext.initNewServiceTrace(new TraceData(), idGenerator, idGenerator));
}
public static WRunnable createServiceFork(Runnable runnable, IdGenerator traceIdGenerator,
IdGenerator spanIdGenerator) {
return create(runnable, TraceContext.initNewServiceTrace(new TraceData(), traceIdGenerator, spanIdGenerator));
}
public static WCallable createServiceFork(Callable callable, IdGenerator idGenerator) {
return create(callable, TraceContext.initNewServiceTrace(new TraceData(), idGenerator, idGenerator));
}
public static WCallable createServiceFork(Callable callable, IdGenerator traceIdGenerator,
IdGenerator spanIdGenerator) {
return create(callable, TraceContext.initNewServiceTrace(new TraceData(), traceIdGenerator, spanIdGenerator));
}
public WRunnable createServiceFork(Runnable runnable) {
return createServiceFork(runnable, traceIdGenerator, spanIdGenerator);
}
public WCallable createServiceFork(Callable callable) {
return createServiceFork(callable, traceIdGenerator, spanIdGenerator);
}
}