org.bdware.doip.cluster.callback.RouteCallback Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
package org.bdware.doip.cluster.callback;
import com.google.gson.JsonObject;
import org.bdware.doip.audit.EndpointConfig;
import org.bdware.doip.cluster.client.DoaClusterClient;
import org.bdware.doip.cluster.util.RouteJoinUtil;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.codec.operations.BasicOperations;
import org.bdware.doip.endpoint.client.DoipMessageCallback;
import org.bdware.sc.bean.ForkInfo;
import org.bdware.sc.bean.JoinInfo;
import wrp.jdk.nashorn.api.scripting.NashornScriptEngineUtil;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Map;
public class RouteCallback extends CookieJSResultCallback {
private final NashornScriptEngineUtil engineUtil;
private final JoinInfo ddoJoinInfo;
private final ForkInfo ddoForkInfo;
private final JsonObject appendixes;
private DoipMessage doipMessage;
private DoipMessageCallback doipMessageCallback;
private DoaClusterClient client;
public RouteCallback(Map cookie, DoaClusterClient doaClusterClient, DoipMessage msg, DoipMessageCallback doipMessageCallback, EndpointConfig routerConfig, BasicOperations operation, NashornScriptEngineUtil engineUtil, JoinInfo joinInfo, ForkInfo forkInfo, JsonObject appendixes) {
super(cookie);
this.doipMessage = msg;
this.doipMessageCallback = doipMessageCallback;
this.client = doaClusterClient;
this.engineUtil = engineUtil;
this.ddoJoinInfo = joinInfo;
this.ddoForkInfo = forkInfo;
this.appendixes = appendixes;
}
@Override
public void onResult(String[] targetDOIDs) {
//TODO 第二次onReult时需要报错。
try {
if (targetDOIDs == null || targetDOIDs.length == 0) {
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
builder.createResponse(DoipResponseCode.MoreThanOneErrors, doipMessage);
builder.setBody("target doid is empty!".getBytes());
doipMessageCallback.onResult(builder.create());
} else
RouteJoinUtil.ddoSendMsgAndJoin(this.cookie, client, engineUtil, doipMessage, ddoJoinInfo, ddoForkInfo, targetDOIDs, doipMessageCallback, appendixes);
} catch (Exception e) {
DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
builder.createResponse(DoipResponseCode.MoreThanOneErrors, doipMessage);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(bo));
builder.setBody(bo.toByteArray());
doipMessageCallback.onResult(builder.create());
}
}
}