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

org.bdware.doip.cluster.callback.RouteCallback Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
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());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy