Program: 39461
Project: 39461
Buggy source:
protected String execute(Channel responseChannel,String clientId,ConcurrentHashMap<String,String> clientState,String request,String cmd,String[] args) throws Exception {
  StringBuffer rsb=new StringBuffer();
  if (null == clientState.get(GraphServerHandler.ST_DB)) {
    rsb.append(GraphServerProtocol.R_ERR);
    rsb.append("String_Node_Str");
    return rsb.toString();
  }
  Graph gr=graphRef.get();
  if (null == gr) {
    GraphCommand killCmd=new GraphCommand();
    killCmd.poisonPill=true;
    graphCommandQueue.clear();
    graphCommandQueue.put(killCmd);
    return GraphServerProtocol.R_ERR + GraphServerProtocol.SPACE + "String_Node_Str";
  }
  if (request.indexOf("String_Node_Str") != -1 && request.indexOf("String_Node_Str") != -1) {
    String query=request.substring(request.indexOf("String_Node_Str") + 2,request.indexOf("String_Node_Str"));
    String prefix=request.substring(0,request.indexOf("String_Node_Str")).trim();
    String suffix=request.substring(request.indexOf("String_Node_Str") + 2).trim();
    log.info("String_Node_Str" + prefix + "String_Node_Str"+ query+ "String_Node_Str"+ suffix+ "String_Node_Str");
    List<JSONObject> selectorResults=gr.queryGraphIndex(query);
    for (    JSONObject selectorResult : selectorResults) {
      String batchRequestKey=selectorResult.getString(Graph.KEY_FIELD);
      String batchRequest=prefix + "String_Node_Str" + batchRequestKey+ "String_Node_Str"+ suffix;
      String batchCmd;
      String[] batchArgs;
      if (batchRequest.indexOf(GraphServerProtocol.SPACE) != -1) {
        batchCmd=batchRequest.substring(0,batchRequest.indexOf(GraphServerProtocol.SPACE)).trim().toLowerCase();
        batchArgs=batchRequest.substring(batchRequest.indexOf(GraphServerProtocol.SPACE)).trim().split(GraphServerProtocol.SPACE);
      }
 else {
        batchCmd=batchRequest.trim().toLowerCase();
        batchArgs=new String[0];
      }
      String batchCmdResponse=execute(responseChannel,clientId,clientState,batchRequest,batchCmd,batchArgs);
      String responseParts[]=batchCmdResponse.split(GraphServerProtocol.NL);
      for (      String responsePart : responseParts) {
        if (responsePart.charAt(0) != '-') {
          responseChannel.write(responsePart.trim() + GraphServerProtocol.NL);
        }
      }
    }
    return GraphServerProtocol.R_BATCH_OK;
  }
  if (cmd.equals(GraphServerProtocol.CMD_CVERT)) {
    String key=args[0];
    String json=request.substring(request.indexOf(GraphServerProtocol.SPACE + key) + (key.length() + 1)).trim();
    JSONObject jo=null;
    try {
      jo=new JSONObject(json);
      gr.addVertex(key,jo);
      rsb.append(GraphServerProtocol.R_OK);
    }
 catch (    org.json.JSONException jsonEx) {
      jsonEx.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append("String_Node_Str");
      rsb.append(jsonEx.getMessage());
    }
catch (    Exception ex) {
      ex.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append(GraphServerProtocol.SPACE);
      rsb.append(ex.getMessage());
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CEDGE)) {
    String key=args[0];
    String vFromKey=args[1];
    String vToKey=args[2];
    String rel=args[3];
    double weight=1.0;
    String json;
    if (args[4].charAt(0) == '{') {
      json=request.substring(request.indexOf(GraphServerProtocol.SPACE + rel) + (rel.length() + 1)).trim();
    }
 else {
      weight=Double.parseDouble(args[4]);
      json=request.substring(request.indexOf(GraphServerProtocol.SPACE + args[4]) + (args[4].length() + 1)).trim();
    }
    JSONObject jo=null;
    try {
      jo=new JSONObject(json);
      jo.put(Graph.EDGE_SOURCE_FIELD,vFromKey);
      jo.put(Graph.EDGE_TARGET_FIELD,vToKey);
      jo.put(Graph.WEIGHT_FIELD,weight);
      jo.put(Graph.RELATION_FIELD,rel);
      gr.addEdge(key,jo,vFromKey,vToKey,rel,weight);
      rsb.append(GraphServerProtocol.R_OK);
    }
 catch (    org.json.JSONException jsonEx) {
      jsonEx.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append("String_Node_Str");
      rsb.append(jsonEx.getMessage());
    }
catch (    Exception ex) {
      ex.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append(GraphServerProtocol.SPACE);
      rsb.append(ex.getMessage());
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_DEL)) {
    String key=args[0];
    JSONObject obj=gr.getGraphObject(key);
    if (null == obj) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      String _type=obj.getString(Graph.TYPE_FIELD);
      if (_type.equals(Graph.VERTEX_TYPE)) {
        JSONVertex jv=gr.getVertex(key);
        gr.removeVertex(jv);
        rsb.append(GraphServerProtocol.R_OK);
      }
 else       if (_type.equals(Graph.EDGE_TYPE)) {
        JSONEdge je=gr.getEdge(key);
        gr.removeEdge(je);
        rsb.append(GraphServerProtocol.R_OK);
      }
 else {
        rsb.append(GraphServerProtocol.R_ERR);
        rsb.append(GraphServerProtocol.SPACE);
        rsb.append(GraphServerProtocol.R_UNKNOWN_OBJECT_TYPE);
      }
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EXISTS)) {
    String key=args[0];
    rsb.append(gr.exists(key) + "String_Node_Str" + key);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_GET)) {
    String key=args[0];
    JSONObject jo=gr.getGraphObject(key);
    if (jo == null) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      rsb.append(prepareResult(jo));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_Q)) {
    String q=request.substring(request.indexOf(GraphServerProtocol.SPACE)).trim();
    List<JSONObject> results=gr.queryGraphIndex(q);
    JSONArray ja=new JSONArray();
    for (    JSONObject jo : results) {
      ja.put(jo);
    }
    JSONObject res=new JSONObject();
    res.put("String_Node_Str",ja);
    rsb.append(prepareResult(res));
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_QP)) {
    String q=request.substring(request.indexOf(GraphServerProtocol.SPACE)).trim();
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SPATH)) {
    String vFromKey=args[0];
    String vToKey=args[1];
    double radius=Double.POSITIVE_INFINITY;
    if (args.length == 3) {
      radius=Double.parseDouble(args[2]);
    }
    JSONObject result=gr.getShortestPath(vFromKey,vToKey,radius);
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(prepareResult(result));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SET)) {
    String key=args[0];
    String attr=args[1];
    String val;
    if (args.length == 2) {
      val=null;
    }
 else {
      val=request.substring(request.indexOf(GraphServerProtocol.SPACE + args[1]) + (args[1].length() + 1)).trim();
    }
    if (attr.startsWith("String_Node_Str") && !attr.equals(Graph.WEIGHT_FIELD)) {
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append("String_Node_Str");
    }
 else {
      JSONObject obj=gr.getGraphObject(key);
      if (null == obj) {
        rsb.append(GraphServerProtocol.R_NOT_FOUND);
      }
 else {
        String _type=obj.getString(Graph.TYPE_FIELD);
        if (_type.equals(Graph.VERTEX_TYPE)) {
          JSONVertex jv=gr.getVertex(key);
          if (null != val) {
            jv.put(attr,val);
          }
 else {
            jv.remove(attr);
          }
          gr.indexObject(key,_type,jv);
          rsb.append(GraphServerProtocol.R_OK);
        }
 else         if (_type.equals(Graph.EDGE_TYPE)) {
          JSONEdge je=gr.getEdge(key);
          if (null != val) {
            je.put(attr,val);
          }
 else {
            je.remove(attr);
          }
          if (attr.equals(Graph.WEIGHT_FIELD)) {
            gr.setEdgeWeight(je,Double.parseDouble(val));
          }
          gr.indexObject(key,_type,je.asJSONObject().getJSONObject(Graph.DATA_FIELD));
          rsb.append(GraphServerProtocol.R_OK);
        }
 else {
          rsb.append(GraphServerProtocol.R_ERR);
          rsb.append(GraphServerProtocol.R_UNKNOWN_OBJECT_TYPE);
        }
      }
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_INCW)) {
    String key=args[0];
    double w_amt=Double.parseDouble(args[1]);
    JSONEdge je=gr.getEdge(key);
    if (null == je) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      double weight=gr.getEdgeWeight(je);
      weight+=w_amt;
      gr.setEdgeWeight(je,weight);
      je.put(Graph.WEIGHT_FIELD,"String_Node_Str" + weight);
      gr.indexObject(key,Graph.EDGE_TYPE,je.asJSONObject().getJSONObject(Graph.DATA_FIELD));
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SPY)) {
    String key=args[0];
    JSONObject obj=gr.getGraphObject(key);
    if (null == obj) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      String _type=obj.getString(Graph.TYPE_FIELD);
      if (_type.equals(Graph.EDGE_TYPE)) {
        JSONEdge je=gr.getEdge(key);
        if (null == je) {
          rsb.append(GraphServerProtocol.R_NOT_FOUND);
        }
 else {
          rsb.append(je.asClientJSONObject().toString(4) + GraphServerProtocol.NL);
          rsb.append(GraphServerProtocol.R_OK);
        }
      }
 else       if (_type.equals(Graph.VERTEX_TYPE)) {
        JSONVertex jv=gr.getVertex(key);
        if (null == jv) {
          rsb.append(GraphServerProtocol.R_NOT_FOUND);
        }
 else {
          rsb.append(jv.toString(4) + GraphServerProtocol.NL);
          rsb.append(GraphServerProtocol.R_OK);
        }
      }
 else {
        rsb.append(GraphServerProtocol.R_ERR);
        rsb.append(GraphServerProtocol.R_UNKNOWN_OBJECT_TYPE);
      }
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_KSPATH)) {
    String vFromKey=args[0];
    String vToKey=args[1];
    int k=Integer.parseInt(args[2]);
    int maxHops=0;
    if (args.length > 3) {
      maxHops=Integer.parseInt(args[3]);
    }
    JSONObject result=gr.getKShortestPaths(vFromKey,vToKey,k,maxHops);
    rsb.append(prepareResult(result));
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_HC)) {
    List<JSONVertex> results=gr.getHamiltonianCycle();
    if (null == results) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      JSONObject res=new JSONObject();
      JSONArray cycle=new JSONArray();
      for (      JSONVertex jo : results) {
        cycle.put(jo);
      }
      res.put("String_Node_Str",cycle);
      rsb.append(prepareResult(res));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EC)) {
    List<JSONVertex> results=gr.getEulerianCircuit();
    if (null == results) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      JSONObject res=new JSONObject();
      JSONArray circuit=new JSONArray();
      for (      JSONVertex jo : results) {
        circuit.put(jo);
      }
      res.put("String_Node_Str",circuit);
      rsb.append(prepareResult(res));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EKMF)) {
    String vSourceKey=args[0];
    String vSinkKey=args[1];
    JSONObject flowResult=gr.getEKMF(vSourceKey,vSinkKey);
    if (null == flowResult) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(flowResult.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CN)) {
    JSONObject result=new JSONObject();
    result.put("String_Node_Str",gr.getChromaticNumber());
    rsb.append(result.toString());
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_KMST)) {
    JSONObject result=gr.getKMST();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_VCG)) {
    JSONObject result=gr.getGreedyVertexCover();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_VC2A)) {
    JSONObject result=gr.get2ApproximationVertexCover();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CSETV)) {
    String key=args[0];
    JSONVertex v=gr.getVertex(key);
    if (null == v) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      JSONObject result=gr.getConnectedSetByVertex(v);
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CSETS)) {
    JSONObject result=gr.getConnectedSets();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_ISCON)) {
    rsb.append("String_Node_Str" + gr.isConnected());
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_UPATHEX)) {
    JSONVertex vFrom=gr.getVertex(args[0]);
    JSONVertex vTo=gr.getVertex(args[1]);
    if (null == vFrom || null == vTo) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      rsb.append("String_Node_Str" + gr.pathExists(vFrom,vTo));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_FAMC)) {
    JSONObject result=gr.getAllMaximalCliques();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_FBMC)) {
    JSONObject result=gr.getBiggestMaximalCliques();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_ASPV)) {
    JSONObject result=gr.getAllShortestPathsFrom(gr.getVertex(args[0]));
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_GCYC)) {
    JSONObject result=gr.getGraphCycles();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_VCYC)) {
    JSONObject result=gr.getGraphCyclesContainingVertex(gr.getVertex(args[0]));
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_QSIM)) {
    String q=request.substring(request.indexOf(GraphServerProtocol.SPACE)).trim();
    List<JSONObject> results=gr.querySimIndex(q);
    JSONArray ja=new JSONArray();
    for (    JSONObject jo : results) {
      ja.put(jo);
    }
    JSONObject res=new JSONObject();
    res.put("String_Node_Str",ja);
    rsb.append(prepareResult(res));
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_DEFINE_UDF)) {
    String udfKey=args[0];
    String udfType=args[1];
    String udfURL=args[2];
    gr.defineUDF(udfKey,udfType,udfURL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SPROC)) {
    String objKey=args[0];
    String udfKey=args[1];
    String processName;
    if (args.length == 3) {
      processName=args[2];
    }
 else {
      processName=objKey + "String_Node_Str" + udfKey;
    }
    gr.startProcess(objKey,udfKey,processName);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EMIT)) {
    String key=args[0];
    String processName=args[1];
    String json=request.substring(request.indexOf(GraphServerProtocol.SPACE + processName) + (processName.length() + 1)).trim();
    JSONObject jo=null;
    jo=new JSONObject(json);
    gr.emit(key,processName,jo);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CCHAN)) {
    String channelName=args[0];
    String pid=gr.createEndpointChannel(channelName);
    if (null == pid) {
      rsb.append(GraphServerProtocol.R_ALREADY_EXIST);
    }
 else {
      rsb.append(pid);
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_PUBLISH)) {
    String channelName=args[0];
    String json=request.substring(request.indexOf(GraphServerProtocol.SPACE + channelName) + (channelName.length() + 1)).trim();
    gr.publishToEndpointByName(channelName,new JSONObject(json));
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SUBSCRIBE)) {
    String channelName=args[0];
    gr.subscribeToEndpointByName(channelName,getInboundChannelProcess(clientId).getChannel());
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_UNSUBSCRIBE)) {
    String channelName=args[0];
    gr.unsubscribeToEndpointByName(channelName,getInboundChannelProcess(clientId).getChannel());
    rsb.append(GraphServerProtocol.R_OK);
  }
  return rsb.toString();
}

Fixed version (ground truth):
protected String execute(Channel responseChannel,String clientId,ConcurrentHashMap<String,String> clientState,String request,String cmd,String[] args) throws Exception {
  StringBuffer rsb=new StringBuffer();
  if (null == clientState.get(GraphServerHandler.ST_DB)) {
    rsb.append(GraphServerProtocol.R_ERR);
    rsb.append("String_Node_Str");
    return rsb.toString();
  }
  Graph gr=graphRef.get();
  if (null == gr) {
    GraphCommand killCmd=new GraphCommand();
    killCmd.poisonPill=true;
    graphCommandQueue.clear();
    graphCommandQueue.put(killCmd);
    return GraphServerProtocol.R_ERR + GraphServerProtocol.SPACE + "String_Node_Str";
  }
  if (request.indexOf("String_Node_Str") != -1 && request.indexOf("String_Node_Str") != -1) {
    String query=request.substring(request.indexOf("String_Node_Str") + 2,request.indexOf("String_Node_Str"));
    String prefix=request.substring(0,request.indexOf("String_Node_Str")).trim();
    String suffix=request.substring(request.indexOf("String_Node_Str") + 2).trim();
    log.info("String_Node_Str" + prefix + "String_Node_Str"+ query+ "String_Node_Str"+ suffix+ "String_Node_Str");
    List<JSONObject> selectorResults=gr.queryGraphIndex(query);
    for (    JSONObject selectorResult : selectorResults) {
      String batchRequestKey=selectorResult.getString(Graph.KEY_FIELD);
      String batchRequest=prefix + "String_Node_Str" + batchRequestKey+ "String_Node_Str"+ suffix;
      String batchCmd;
      String[] batchArgs;
      if (batchRequest.indexOf(GraphServerProtocol.SPACE) != -1) {
        batchCmd=batchRequest.substring(0,batchRequest.indexOf(GraphServerProtocol.SPACE)).trim().toLowerCase();
        batchArgs=batchRequest.substring(batchRequest.indexOf(GraphServerProtocol.SPACE)).trim().split(GraphServerProtocol.SPACE);
      }
 else {
        batchCmd=batchRequest.trim().toLowerCase();
        batchArgs=new String[0];
      }
      String batchCmdResponse=execute(responseChannel,clientId,clientState,batchRequest,batchCmd,batchArgs);
      String responseParts[]=batchCmdResponse.split(GraphServerProtocol.NL);
      for (      String responsePart : responseParts) {
        if (responsePart.charAt(0) != '-') {
          responseChannel.write(responsePart.trim() + GraphServerProtocol.NL);
        }
      }
    }
    return GraphServerProtocol.R_BATCH_OK;
  }
  if (cmd.equals(GraphServerProtocol.CMD_CVERT)) {
    String key=args[0];
    String json=request.substring(request.indexOf(GraphServerProtocol.SPACE + key) + (key.length() + 1)).trim();
    JSONObject jo=null;
    try {
      jo=new JSONObject(json);
      gr.addVertex(key,jo);
      rsb.append(GraphServerProtocol.R_OK);
    }
 catch (    org.json.JSONException jsonEx) {
      jsonEx.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append("String_Node_Str");
      rsb.append(jsonEx.getMessage());
    }
catch (    Exception ex) {
      ex.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append(GraphServerProtocol.SPACE);
      rsb.append(ex.getMessage());
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CEDGE)) {
    String key=args[0];
    String vFromKey=args[1];
    String vToKey=args[2];
    String rel=args[3];
    double weight=1.0;
    String json;
    if (args[4].charAt(0) == '{') {
      json=request.substring(request.indexOf(GraphServerProtocol.SPACE + rel) + (rel.length() + 1)).trim();
    }
 else {
      weight=Double.parseDouble(args[4]);
      json=request.substring(request.indexOf(GraphServerProtocol.SPACE + args[4]) + (args[4].length() + 1)).trim();
    }
    JSONObject jo=null;
    try {
      jo=new JSONObject(json);
      jo.put(Graph.EDGE_SOURCE_FIELD,vFromKey);
      jo.put(Graph.EDGE_TARGET_FIELD,vToKey);
      jo.put(Graph.WEIGHT_FIELD,weight);
      jo.put(Graph.RELATION_FIELD,rel);
      gr.addEdge(key,jo,vFromKey,vToKey,rel,weight);
      rsb.append(GraphServerProtocol.R_OK);
    }
 catch (    org.json.JSONException jsonEx) {
      jsonEx.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append("String_Node_Str");
      rsb.append(jsonEx.getMessage());
    }
catch (    Exception ex) {
      ex.printStackTrace();
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append(GraphServerProtocol.SPACE);
      rsb.append(ex.getMessage());
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_DEL)) {
    String key=args[0];
    JSONObject obj=gr.getGraphObject(key);
    if (null == obj) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      String _type=obj.getString(Graph.TYPE_FIELD);
      if (_type.equals(Graph.VERTEX_TYPE)) {
        JSONVertex jv=gr.getVertex(key);
        gr.removeVertex(jv);
        rsb.append(GraphServerProtocol.R_OK);
      }
 else       if (_type.equals(Graph.EDGE_TYPE)) {
        JSONEdge je=gr.getEdge(key);
        gr.removeEdge(je);
        rsb.append(GraphServerProtocol.R_OK);
      }
 else {
        rsb.append(GraphServerProtocol.R_ERR);
        rsb.append(GraphServerProtocol.SPACE);
        rsb.append(GraphServerProtocol.R_UNKNOWN_OBJECT_TYPE);
      }
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EXISTS)) {
    String key=args[0];
    rsb.append(gr.exists(key) + "String_Node_Str" + key);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_GET)) {
    String key=args[0];
    JSONObject jo=gr.getGraphObject(key);
    if (jo == null) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      rsb.append(prepareResult(jo));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_Q)) {
    String q=request.substring(request.indexOf(GraphServerProtocol.SPACE)).trim();
    List<JSONObject> results=gr.queryGraphIndex(q);
    JSONArray ja=new JSONArray();
    for (    JSONObject jo : results) {
      ja.put(jo);
    }
    JSONObject res=new JSONObject();
    res.put("String_Node_Str",ja);
    rsb.append(prepareResult(res));
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_QP)) {
    String q=request.substring(request.indexOf(GraphServerProtocol.SPACE)).trim();
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SPATH)) {
    String vFromKey=args[0];
    String vToKey=args[1];
    double radius=Double.POSITIVE_INFINITY;
    if (args.length == 3) {
      radius=Double.parseDouble(args[2]);
    }
    JSONObject result=gr.getShortestPath(vFromKey,vToKey,radius);
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(prepareResult(result));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SET)) {
    String key=args[0];
    String attr=args[1];
    String val;
    if (args.length == 2) {
      val=null;
    }
 else {
      val=request.substring(request.indexOf(GraphServerProtocol.SPACE + args[1]) + (args[1].length() + 1)).trim();
    }
    if (attr.startsWith("String_Node_Str") && !attr.equals(Graph.WEIGHT_FIELD)) {
      rsb.append(GraphServerProtocol.R_ERR);
      rsb.append("String_Node_Str");
    }
 else {
      JSONObject obj=gr.getGraphObject(key);
      if (null == obj) {
        rsb.append(GraphServerProtocol.R_NOT_FOUND);
      }
 else {
        String _type=obj.getString(Graph.TYPE_FIELD);
        if (_type.equals(Graph.VERTEX_TYPE)) {
          JSONVertex jv=gr.getVertex(key);
          if (null != val) {
            jv.put(attr,val);
          }
 else {
            jv.remove(attr);
          }
          gr.indexObject(key,_type,jv);
          rsb.append(GraphServerProtocol.R_OK);
        }
 else         if (_type.equals(Graph.EDGE_TYPE)) {
          JSONEdge je=gr.getEdge(key);
          if (null != val) {
            je.put(attr,val);
          }
 else {
            je.remove(attr);
          }
          if (attr.equals(Graph.WEIGHT_FIELD)) {
            gr.setEdgeWeight(je,Double.parseDouble(val));
          }
          gr.indexObject(key,_type,je.asJSONObject().getJSONObject(Graph.DATA_FIELD));
          rsb.append(GraphServerProtocol.R_OK);
        }
 else {
          rsb.append(GraphServerProtocol.R_ERR);
          rsb.append(GraphServerProtocol.R_UNKNOWN_OBJECT_TYPE);
        }
      }
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_INCW)) {
    String key=args[0];
    double w_amt=Double.parseDouble(args[1]);
    JSONEdge je=gr.getEdge(key);
    if (null == je) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      double weight=gr.getEdgeWeight(je);
      weight+=w_amt;
      gr.setEdgeWeight(je,weight);
      je.put(Graph.WEIGHT_FIELD,"String_Node_Str" + weight);
      gr.indexObject(key,Graph.EDGE_TYPE,je.asJSONObject().getJSONObject(Graph.DATA_FIELD));
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SPY)) {
    String key=args[0];
    JSONObject obj=gr.getGraphObject(key);
    if (null == obj) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      String _type=obj.getString(Graph.TYPE_FIELD);
      if (_type.equals(Graph.EDGE_TYPE)) {
        JSONEdge je=gr.getEdge(key);
        if (null == je) {
          rsb.append(GraphServerProtocol.R_NOT_FOUND);
        }
 else {
          rsb.append(je.asClientJSONObject().toString() + GraphServerProtocol.NL);
          rsb.append(GraphServerProtocol.R_OK);
        }
      }
 else       if (_type.equals(Graph.VERTEX_TYPE)) {
        JSONVertex jv=gr.getVertex(key);
        if (null == jv) {
          rsb.append(GraphServerProtocol.R_NOT_FOUND);
        }
 else {
          rsb.append(jv.toString() + GraphServerProtocol.NL);
          rsb.append(GraphServerProtocol.R_OK);
        }
      }
 else {
        rsb.append(GraphServerProtocol.R_ERR);
        rsb.append(GraphServerProtocol.R_UNKNOWN_OBJECT_TYPE);
      }
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_KSPATH)) {
    String vFromKey=args[0];
    String vToKey=args[1];
    int k=Integer.parseInt(args[2]);
    int maxHops=0;
    if (args.length > 3) {
      maxHops=Integer.parseInt(args[3]);
    }
    JSONObject result=gr.getKShortestPaths(vFromKey,vToKey,k,maxHops);
    rsb.append(prepareResult(result));
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_HC)) {
    List<JSONVertex> results=gr.getHamiltonianCycle();
    if (null == results) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      JSONObject res=new JSONObject();
      JSONArray cycle=new JSONArray();
      for (      JSONVertex jo : results) {
        cycle.put(jo);
      }
      res.put("String_Node_Str",cycle);
      rsb.append(prepareResult(res));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EC)) {
    List<JSONVertex> results=gr.getEulerianCircuit();
    if (null == results) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      JSONObject res=new JSONObject();
      JSONArray circuit=new JSONArray();
      for (      JSONVertex jo : results) {
        circuit.put(jo);
      }
      res.put("String_Node_Str",circuit);
      rsb.append(prepareResult(res));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EKMF)) {
    String vSourceKey=args[0];
    String vSinkKey=args[1];
    JSONObject flowResult=gr.getEKMF(vSourceKey,vSinkKey);
    if (null == flowResult) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(flowResult.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CN)) {
    JSONObject result=new JSONObject();
    result.put("String_Node_Str",gr.getChromaticNumber());
    rsb.append(result.toString());
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_KMST)) {
    JSONObject result=gr.getKMST();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_VCG)) {
    JSONObject result=gr.getGreedyVertexCover();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_VC2A)) {
    JSONObject result=gr.get2ApproximationVertexCover();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CSETV)) {
    String key=args[0];
    JSONVertex v=gr.getVertex(key);
    if (null == v) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      JSONObject result=gr.getConnectedSetByVertex(v);
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CSETS)) {
    JSONObject result=gr.getConnectedSets();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_ISCON)) {
    rsb.append("String_Node_Str" + gr.isConnected());
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_UPATHEX)) {
    JSONVertex vFrom=gr.getVertex(args[0]);
    JSONVertex vTo=gr.getVertex(args[1]);
    if (null == vFrom || null == vTo) {
      rsb.append(GraphServerProtocol.R_NOT_FOUND);
    }
 else {
      rsb.append("String_Node_Str" + gr.pathExists(vFrom,vTo));
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_FAMC)) {
    JSONObject result=gr.getAllMaximalCliques();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_FBMC)) {
    JSONObject result=gr.getBiggestMaximalCliques();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_ASPV)) {
    JSONObject result=gr.getAllShortestPathsFrom(gr.getVertex(args[0]));
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_GCYC)) {
    JSONObject result=gr.getGraphCycles();
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_VCYC)) {
    JSONObject result=gr.getGraphCyclesContainingVertex(gr.getVertex(args[0]));
    if (null == result) {
      rsb.append(GraphServerProtocol.R_NOT_EXIST);
    }
 else {
      rsb.append(result.toString());
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_QSIM)) {
    String q=request.substring(request.indexOf(GraphServerProtocol.SPACE)).trim();
    List<JSONObject> results=gr.querySimIndex(q);
    JSONArray ja=new JSONArray();
    for (    JSONObject jo : results) {
      ja.put(jo);
    }
    JSONObject res=new JSONObject();
    res.put("String_Node_Str",ja);
    rsb.append(prepareResult(res));
    rsb.append(GraphServerProtocol.NL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_DEFINE_UDF)) {
    String udfKey=args[0];
    String udfType=args[1];
    String udfURL=args[2];
    gr.defineUDF(udfKey,udfType,udfURL);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SPROC)) {
    String objKey=args[0];
    String udfKey=args[1];
    String processName;
    if (args.length == 3) {
      processName=args[2];
    }
 else {
      processName=objKey + "String_Node_Str" + udfKey;
    }
    gr.startProcess(objKey,udfKey,processName);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_EMIT)) {
    String key=args[0];
    String processName=args[1];
    String json=request.substring(request.indexOf(GraphServerProtocol.SPACE + processName) + (processName.length() + 1)).trim();
    JSONObject jo=null;
    jo=new JSONObject(json);
    gr.emit(key,processName,jo);
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_CCHAN)) {
    String channelName=args[0];
    String pid=gr.createEndpointChannel(channelName);
    if (null == pid) {
      rsb.append(GraphServerProtocol.R_ALREADY_EXIST);
    }
 else {
      rsb.append(pid);
      rsb.append(GraphServerProtocol.NL);
      rsb.append(GraphServerProtocol.R_OK);
    }
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_PUBLISH)) {
    String channelName=args[0];
    String json=request.substring(request.indexOf(GraphServerProtocol.SPACE + channelName) + (channelName.length() + 1)).trim();
    gr.publishToEndpointByName(channelName,new JSONObject(json));
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_SUBSCRIBE)) {
    String channelName=args[0];
    gr.subscribeToEndpointByName(channelName,getInboundChannelProcess(clientId).getChannel());
    rsb.append(GraphServerProtocol.R_OK);
  }
 else   if (cmd.equals(GraphServerProtocol.CMD_UNSUBSCRIBE)) {
    String channelName=args[0];
    gr.unsubscribeToEndpointByName(channelName,getInboundChannelProcess(clientId).getChannel());
    rsb.append(GraphServerProtocol.R_OK);
  }
  return rsb.toString();
}