package edu.vt.marian.server; import java.io.*; import java.net.*; import java.util.*; import edu.vt.marian.common.*; import edu.vt.marian.uip.*; /** class name: marian_server class description: this is the main class of the system. uses the services of class(es): designer(s): Jianxin Zhao (jxzhao@csgrad.cs.vt.edu) implementator(s): Ning Chai (nchai@csgrad.cs.vt.edu) finished time: Nov 30th, 1998 known bugs: JDK version: 1.1.5 side effects: */ public class marian_server { private static long start_time; /** this object is used for debugging */ static Debug debug = null; /** these are use to do the system performance measurement */ /* public static int FIRST_BATCH_TOTAL_TIME; public static int FIRST_BATCH_PREPROCESS_TIME; public static int FIRST_BATCH_POSTPROCESS_TIME; public static int FIRST_BATCH_C_TIME; public static int SECOND_BATCH_TOTAL_TIME; public static int SECOND_BATCH_PREPROCESS_TIME; public static int SECOND_BATCH_POSTPROCESS_TIME; public static int SECOND_BATCH_C_TIME; */ /** method description: this is an empty constructor uses the services of class(es): input parameter(s): none output parameter(s): none return value: none */ /** method description: this is the main method of the system uses the services of class(es): input parameter(s): argv[] -- command input output parameter(s): none return value: none */ public static void main(String argv[]) { // Create a default Debug that will get things off the ground. Debug tempDebug = new Debug("config" + File.separator + "debug.cfg", "trace", false); // create various performance measurements /* marian_server.FIRST_BATCH_TOTAL_TIME = debug.pm.add_measurement("time spend between search_collection received from webgate and show_retrieval_coll send out to webgate"); marian_server.FIRST_BATCH_PREPROCESS_TIME = debug.pm.add_measurement("time spend between search_collection received from webgate and new_query send out to C marian server"); marian_server.FIRST_BATCH_POSTPROCESS_TIME = debug.pm.add_measurement("time spend between show_raw_retr received from c marian server and show_retrieval_coll send out to webgate"); marian_server.FIRST_BATCH_C_TIME = debug.pm.add_measurement("time spend between new_query send out to c marian server and show_raw_retr received from c marian server"); marian_server.SECOND_BATCH_TOTAL_TIME = debug.pm.add_measurement("time spend between show_next_k received from webgate and add_to_retrieval_coll send out to webgate"); marian_server.SECOND_BATCH_PREPROCESS_TIME = debug.pm.add_measurement("time spend between show_next_k received from webgate and find_next_k_docs send out to C marian server"); marian_server.SECOND_BATCH_POSTPROCESS_TIME = debug.pm.add_measurement("time spend between add_raw_retr received from c marian server and add_to_retrieval_coll send out to webgate"); marian_server.SECOND_BATCH_C_TIME = debug.pm.add_measurement("time spend between find_next_k_docs send out to c marian server and add_raw_retr received from c marian server"); */ String ConfigFilename = new String("config" + File.separator); if (argv.length != 0) { ConfigFilename += argv[0]; } else { ConfigFilename += "marian.cfg"; } // create system configuration configuration config = new configuration(ConfigFilename, tempDebug); // Now create the real Debug for this server. String DebugConfigFilename = config.get_dir("debug_config"); String DebugTraceFilename = config.get_dir("debug_trace"); debug = new Debug(DebugConfigFilename, DebugTraceFilename, false); // create system resource manager resource_manager rm = new resource_manager( config.get_dir("resource_manager"), debug); // create the session manager which will do most of the stuff session_manager sm = new session_manager( config.get_dir("session_manager"), rm, debug); // create communication classes client uip and server uip client_uip c_uip = new client_uip( config.get_dir("client_uip"), sm, debug); server_uip s_uip = new server_uip( config.get_dir("server_uip"), sm, debug); // inform session manage about the client uip and server uip sm.set_communication_classes(c_uip, s_uip); // now everything is working, we just wait the super user // to shut down the system Date date = new Date(); start_time = date.getTime(); while (!super_user_shut_down()); // shut down the system smoothly // first dump measurement results // debug.ts.dump_final_results("final", false); // first exit session manager sm.exit("Super user shut down"); debug.dumpTrace("class marian_server, main method session manager exit ok"); // then server uip which is responsible for communicate // with webgate(s) s_uip.exit("Super user shut down"); debug.dumpTrace("class marian_server, main method server_uip exit ok"); // then client uip which is responsible to communicate // with C/C++ MARIAN server c_uip.exit("Super user shut down"); debug.dumpTrace("class marian_server, main method client_uip exit ok"); // at last the resource manager of the system rm.exit("Super user shut down"); debug.dumpTrace("class marian_server, main method resource_manager exit ok"); } /** method description: this method will tell whether or not the super user want to shut down the system uses the services of class(es): input parameter(s): none output parameter(s): none return value: true -- super user want to shut down the system false -- super user don't want to shut down the system */ public static boolean super_user_shut_down() { Date date = new Date(); try { System.out.print("The system has been running for "); System.out.print((date.getTime()-start_time)/1000); System.out.println(" seconds."); System.out.println("Do you want to shut it down? Y/N"); DataInputStream dis = null; dis = new DataInputStream(System.in); String user_input = dis.readLine(); if ((user_input != null) && (user_input.equals("y") || user_input.equals("Y"))) { System.out.println("Are you sure to shut down the system? Y/N"); user_input = dis.readLine(); if ((user_input != null) && (user_input.equals("y") || user_input.equals("Y"))) { return true; } else { return false; } } else { return false; } } catch(IOException e) { debug.dumpTrace("class marian_server, method super_user_shut_down, error read data from screen"); return false; } } }