cn.keayuan.util.flow.Node Maven / Gradle / Ivy
package cn.keayuan.util.flow;
class Node implements INode
, Runnable {
private final String tag;
private final IProcess
process;
private final boolean isMain;
Node next;
private Object params;
private final FlowProcess> flowProcess;
private volatile boolean isCallNext;
Node(Object arg, FlowProcess> fp) {
this.tag = null;
process = null;
isMain = true;
params = arg;
flowProcess = fp;
}
Node(String tag, IProcess p, boolean main, FlowProcess> fp) {
this.tag = tag;
process = p;
isMain = main;
this.flowProcess = fp;
}
@Override
public void run() {
if (flowProcess.isClose) return;
if (process != null) {
process.process(this);
}
}
@SuppressWarnings("unchecked")
@Override
public P getParams() {
return (P) params;
}
void setParams(P p) {
params = p;
}
@Override
public String getTag() {
return tag;
}
@Override
public boolean isMain() {
return isMain;
}
@Override
public void next(String tag, Object t) {
if (isCallNext) {
throw new IllegalStateException("already call next()");
}
isCallNext = true;
flowProcess.next(tag, t);
}
@Override
public void next(T t) {
next(null, t);
}
@Override
public void next() {
next(null);
}
@Override
public void close() {
flowProcess.close();
}
@Override
public void remove(String tag) {
flowProcess.remove(tag);
}
}