// Path: src/cc/osint/graphd/processes/InboundChannelProcess.java
// public class InboundChannelProcess implements Callback<JSONObject> {
//     final private Fiber fiber;
//     final private String clientId;
//     final private org.jboss.netty.channel.Channel nettyChannel;
//     final private Channel<JSONObject> channel;
//     
//     public InboundChannelProcess(String clientId,
//                                  Fiber fiber, 
//                                  Channel channel,
//                                  org.jboss.netty.channel.Channel nettyChannel) {
//         this.clientId = clientId;
//         this.fiber = fiber;
//         this.channel = channel;
//         this.nettyChannel = nettyChannel;
//         log("setup: " + clientId + " fiber = " + 
//             fiber + ", channel = " + channel);
//     }
//     
//     public void kill() throws Exception {
//         fiber.dispose();
//         log("kill");
//     }
//     
//     public void publish(JSONObject msg) throws Exception {
//         channel.publish(msg);
//     }
//     
//     public Channel getChannel() {
//         return channel;
//     }
//     
//     public org.jboss.netty.channel.Channel getNettyChannel() {
//         return nettyChannel;
//     }
//     
//     public void log(String s) {
//         try {
//             Thread t = Thread.currentThread();
//             System.out.println(t.getId() + ": " +
//                                clientId + ": InboundChannelProcess: " + s);
//         } catch (Exception ex) {
//             ex.printStackTrace();
//         }
//     }
//     
//     public void onMessage(JSONObject msg1) {
//         try {
//             String from = msg1.getString("from");
//             JSONObject msg = msg1.getJSONObject("msg");
//             nettyChannel.write("! " +
//                                from + " " +
//                                msg.toString() + "\n");
//         } catch (Exception ex) {
//             ex.printStackTrace();
//             try {
//                 kill();
//             } catch (Exception ex1) {
//                 ex1.printStackTrace();
//             }
//         }
//     }
//     
//     public String getClientId() {
//         return clientId;
//     }    
// }


import java.lang.*;
import java.lang.ref.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.*;
import org.jboss.netty.channel.Channel;
import org.jgrapht.traverse.*;
import cc.osint.graphd.graph.*;
import cc.osint.graphd.processes.InboundChannelProcess;
                
                String batchCmdResponse =
                    execute(responseChannel,
                            clientId, 
                            clientState,
                            inboundChannelProcess,
                            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;
        }
        
        /*
         * graph commands
         *
        */
        
        // CREATE VERTEX: cvert <key> <json>
        if (cmd.equals(GraphServerProtocol.CMD_CVERT)) {
            String key = args[0];
            String json = request.substring(request.indexOf(GraphServerProtocol.SPACE + key) +
                (key.length()+1)).trim(); // remainder of line
            JSONObject jo = null;
// Path: src/cc/osint/graphd/processes/InboundChannelProcess.java
// public class InboundChannelProcess implements Callback<JSONObject> {
//     final private Fiber fiber;
//     final private String clientId;
//     final private org.jboss.netty.channel.Channel nettyChannel;
//     final private Channel<JSONObject> channel;
//     
//     public InboundChannelProcess(String clientId,
//                                  Fiber fiber, 
//                                  Channel channel,
//                                  org.jboss.netty.channel.Channel nettyChannel) {
//         this.clientId = clientId;
//         this.fiber = fiber;
//         this.channel = channel;
//         this.nettyChannel = nettyChannel;
//         log("setup: " + clientId + " fiber = " + 
//             fiber + ", channel = " + channel);
//     }
//     
//     public void kill() throws Exception {
//         fiber.dispose();
//         log("kill");
//     }
//     
//     public void publish(JSONObject msg) throws Exception {
//         channel.publish(msg);
//     }
//     
//     public Channel getChannel() {
//         return channel;
//     }
//     
//     public org.jboss.netty.channel.Channel getNettyChannel() {
//         return nettyChannel;
//     }
//     
//     public void log(String s) {
//         try {
//             Thread t = Thread.currentThread();
//             System.out.println(t.getId() + ": " +
//                                clientId + ": InboundChannelProcess: " + s);
//         } catch (Exception ex) {
//             ex.printStackTrace();
//         }
//     }
//     
//     public void onMessage(JSONObject msg1) {
//         try {
//             String from = msg1.getString("from");
//             JSONObject msg = msg1.getJSONObject("msg");
//             nettyChannel.write("! " +
//                                from + " " +
//                                msg.toString() + "\n");
//         } catch (Exception ex) {
//             ex.printStackTrace();
//             try {
//                 kill();
//             } catch (Exception ex1) {
//                 ex1.printStackTrace();
//             }
//         }
//     }
//     
//     public String getClientId() {
//         return clientId;
//     }    
// }


// Path: src/cc/osint/graphd/server/GraphCommandExecutor.java
import java.lang.*;
import java.lang.ref.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.*;
import org.jboss.netty.channel.Channel;
import org.jgrapht.traverse.*;
import cc.osint.graphd.graph.*;
import cc.osint.graphd.processes.InboundChannelProcess;

                
                String batchCmdResponse =
                    execute(responseChannel,
                            clientId, 
                            clientState,
                            inboundChannelProcess,
                            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;
        }
        
        /*
         * graph commands
         *
        */
        
        // CREATE VERTEX: cvert <key> <json>
        if (cmd.equals(GraphServerProtocol.CMD_CVERT)) {
            String key = args[0];
            String json = request.substring(request.indexOf(GraphServerProtocol.SPACE + key) +
                (key.length()+1)).trim(); // remainder of line
            JSONObject jo = null;
            try {