package edu.vt.marian.uip; import java.io.*; import java.net.*; import java.util.*; import edu.vt.marian.common.*; /** class name: rpc_function class description: this class represent a rpc (remote procedure call) function uses the services of class(es): parameter, xdr, debug designer(s): Jianxin Zhao (jxzhao@csgrad.cs.vt.edu) implementator(s): Xuelei Sun (xusun@csgrad.cs.vt.edu) finished time: December 6, 1998 known bugs: JDK version: 1.1.5 side effects: */ public class rpc_function { public final static int OK=0; public final static int ADD_PARAMETER_INVALID_PARAMETER = -1; public final static int ADD_PARAMETER_INVALID_INDEX = -2; public final static int DELETE_PARAMETER_INVALID_INDEX = -3; public final static int SET_PARAMETER_INVALID_PARAMETER = -4; public final static int SET_PARAMETER_INVALID_INDEX = -5; public final static int TO_STREAM_IN_XDR_NULL_STREAM = -6; public final static int TO_STREAM_IN_XDR_NULL_NAME = -7; public final static int TO_STREAM_IN_XDR_WRITE_FAILED = -8; public final static int TO_TREAM_IN_XDR_UNKNOWN_FUNCTION = -9; public final static int TO_STREAM_IN_XDR_INVALID_VERSION = -10; public final static int TO_STREAM_NULL_STREAM = -11; public final static int TO_STREAM_WRITE_FAILED = -12; public final static int TO_STREAM_WRITE_PARAMETER_FAILED = -13; public final static int TO_STREAM_IN_XDR_FUNCTION_NOT_VALID = -14; /** this is the max number of parameters currently supported, only effective when read out function from stream */ private final static int MAX_NUMBER_PARAMETERS = 100; /** this is the max function length */ private final static int MAX_FUNCTION_LENGTH = 10000000; /** this is just for debugging */ Debug debug; /** this vector contain the parameters of this function */ private Vector parameter_list; /** this is the name of this function */ private String name; /** this is the valid flag of this function */ private boolean valid; /** method description: this constructor will create a rpc_function object, the object is empty upon creation uses the services of class(es): Debug input parameter(s): Debug debug, debug object output parameter(s): none return value: none synchronization consideration: none */ public rpc_function(Debug debug) { //set the debug object this.debug = debug; //initialize the variables parameter_list = new Vector(); name = null; valid = true; } /** method description: this constructor will create a rpc_function object from a stream according to different versions uses the services of class(es): Debug, xdr, parameter input parameter(s): BufferedInputStream bis: input stream int version: version 1 -- hard coded function and parameters version 2 -- all the information is in xdr format Debug debug: debug object output parameter(s): none return value: none synchronization consideration: none */ public rpc_function(BufferedInputStream bis, int version, Debug debug) { //set the debug object this.debug = debug; //initialize the variables parameter_list = new Vector(); name = null; valid = true; //error checking for the bis if (bis == null) { debug.dumpTrace("Class:rpc_function, Method:Constructor from stream, BufferedInputStream is null."); valid = false; return; } xdr x = new xdr(debug); //xdr object to read from the stream //version 1: hard coded function and parameters if (version == 1) { //read out function length int length; try { length = x.read_integer_from_stream(bis); //variable declaration for version 1 parameter p; // parameter vector int i; //temporary integer value read from the stream boolean b; //temporary boolean value read from the stream String s = null; //temporary string value read from the stream Vector v = null; //temporary vector value read from the stream if ((length <= 0) || (length % 4 != 0)) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, Function length is not valid."); valid = false; return; } //read out function code int code = x.read_integer_from_stream(bis); //switch different functions switch (code) { case 1: //show_retrieval_coll(INTEGER + INTEGER + STRING + DOC_VECT + BOOL) set_name("show_retrieval_coll"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); v = p.read_doc_vect_from_stream_in_xdr(bis); if (v == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null DOC_VECT parameter."); valid = false; return; } p = new parameter(null, "DOC_VECT", v, debug); add_parameter(p); b = x.read_bool_from_stream(bis); p = new parameter(null, "BOOL", new Boolean(b), debug); add_parameter(p); return; case 2://solicit_biblio_query(INTEGER + INTEGER + STRING + STRING + INTEGER + // STRING + INTEGER + STRING + INTEGER + STRING + STRING) set_name("solicit_biblio_query"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); return; case 6://show_information(INTEGER + INTEGER + STRING) set_name("show_information"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); return; case 14://append_to_text(INTEGER + INTEGER + STRING + STRING) set_name("append_to_text"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); return; case 16://add_to_retrieval_coll(INTEGER + INTEGER + STRING + DOC_VECT + BOOL) set_name("add_to_retrieval_coll"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); v = p.read_doc_vect_from_stream_in_xdr(bis); if (v == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null DOC_VECT parameter."); valid = false; return; } p = new parameter(null, "DOC_VECT", v, debug); add_parameter(p); b = x.read_bool_from_stream(bis); p = new parameter(null, "BOOL", new Boolean(b), debug); add_parameter(p); return; case 5://biblio_query_text(INTEGER + INTEGER + STRING + STRING + INTEGER + STRING + // INTEGER + STRING + INTEGER + STRING + STRING + INTEGER) set_name("biblio_query_text"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 18://search_collection(INTEGER + INTEGER + STRING) set_name("search_collection"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); // start measure the time between search collection received // from webgate and show retrieval coll send out to webgate // debug.pm.start_measure(marian_server.FIRST_BATCH_TOTAL_TIME); // start measure the time between search clooection received // from webgate to and the time new_query send out to c marian server // debug.pm.start_measure(marian_server.FIRST_BATCH_PREPROCESS_TIME); return; case 19://end_session() set_name("end_session"); return; case 25: //show_next_k(INTEGER + INTEGER + INTEGER) set_name("show_next_k"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); // start measure the time between show next k received from webgate // and add to retrieval retrieval coll send out to webgate // debug.pm.start_measure(marian_server.SECOND_BATCH_TOTAL_TIME); // start measure the time between show next k received from webgate // and find_next_k_docs send out to c marian server // debug.pm.start_measure(marian_server.SECOND_BATCH_PREPROCESS_TIME); return; case 31: //get_circulation_info(INTEGER + INTEGER + DOC_ID_VECT) set_name("get_circulation_info"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); v = p.read_doc_id_vect_from_stream_in_xdr(bis); if (v == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null DOC_ID_VECT parameter."); valid = false; return; } p = new parameter(null, "DOC_ID_VECT", v, debug); add_parameter(p); return; case 0://new_session(INTEGER + INTEGER) set_name("new_session"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 101://query_token(INTEGER + INTEGER + INTEGER + INTEGER + STRING) set_name("query_token"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); return; case 102://close_session(INTEGER) set_name("close_session"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 103://new_query(INTEGER + INTEGER + INTEGER + INTEGER) set_name("new_query"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 104://find_next_k_docs(INTEGER + INTEGER + INTEGER) set_name("find_next_k_docs"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 105://start_processing(INTEGER + INTEGER + INTEGER + INTEGER + INTEGER + INTEGER) set_name("start_processing"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 106://end_processing(INTEGER + INTEGER + INTEGER + INTEGER + INTEGER + INTEGER) set_name("end_processing"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 107://error_for_session_manager(INTEGER + INTEGER + INTEGER + STRING + INTEGER + INTEGER) set_name("error_for_session_manager"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; case 110: //show_information_query(INTEGER + INTEGER + STRING) set_name("show_information_query"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); return; case 111: //show_information_1(INTEGER + STRING) set_name("show_information_1"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); s = x.read_string_from_stream(bis); if (s == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null string parameter."); valid = false; return; } p = new parameter(null, "STRING", s, debug); add_parameter(p); return; case 112: //show_raw_retr(INTEGER + INTEGER + OBJ_VECT + RAW_DOC_VECT + BOOL) set_name("show_raw_retr"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); v = p.read_obj_vect_from_stream_in_xdr(bis); if (v == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null OBJ_VECT parameter."); valid = false; return; } p = new parameter(null, "OBJ_VECT", v, debug); add_parameter(p); v = p.read_raw_doc_vect_from_stream_in_xdr(bis); if (v == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null RAW_DOC_VECT parameter."); valid = false; return; } p = new parameter(null, "RAW_DOC_VECT", v, debug); add_parameter(p); b = x.read_bool_from_stream(bis); p = new parameter(null, "BOOL", new Boolean(b), debug); add_parameter(p); // start measure the time between show_raw_retr received from c marian server // and show retrieval retrieval coll send out to webgate // debug.pm.start_measure(marian_server.FIRST_BATCH_POSTPROCESS_TIME); // end measure the time between new_query send out to c marian server // and show_raw_retr received from c marian server // debug.pm.end_measure(marian_server.FIRST_BATCH_C_TIME); return; case 113://add_raw_retr(INTEGER + INTEGER + OBJ_VECT + RAW_DOC_VECT + BOOL) set_name("add_raw_retr"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); v = p.read_obj_vect_from_stream_in_xdr(bis); if (v == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null OBJ_VECT parameter."); valid = false; return; } p = new parameter(null, "OBJ_VECT", v, debug); add_parameter(p); v = p.read_raw_doc_vect_from_stream_in_xdr(bis); if (v == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null RAW_DOC_VECT parameter."); valid = false; return; } p = new parameter(null, "RAW_DOC_VECT", v, debug); add_parameter(p); b = x.read_bool_from_stream(bis); p = new parameter(null, "BOOL", new Boolean(b), debug); add_parameter(p); // start measure the time between add_raw_retr received from c marian server // and add to retrieval retrieval coll send out to webgate // debug.pm.start_measure(marian_server.SECOND_BATCH_POSTPROCESS_TIME); // end measure the time between find_next_k_docs send out to c marian server // and add_raw_retr received from c marian server // debug.pm.end_measure(marian_server.SECOND_BATCH_C_TIME); return; case 114://startup_notify(INTEGER) set_name("startup_notify"); i = x.read_integer_from_stream(bis); p = new parameter(null, "INTEGER", new Integer(i), debug); add_parameter(p); return; default: // in this case we need to skip the function debug.dumpTrace("class rpc_function, constructor 2, identified an unknown function, try to skip it"); if (length > MAX_FUNCTION_LENGTH) { // probably this is a invalid function debug.dumpTrace("class rpc_function, constructor 2, function length is too large"); valid = false; return; } // after length checking we are sure not out of memory // exception will be throw out length -= 8; if (length < 0) { debug.dumpTrace("class rpc_function, constructor from stream, function length is too small"); valid = false; return; } byte[] b1 = new byte[length]; try { i = length; // left string length to read int j = 0; // offset to begin reading int k; // character number read this time while (i > 0) { // the whole string has not been read out k = bis.read(b1, j, i); if (k == -1) { debug.dumpTrace("class rpc_function, constructor 2, socket is closed by marian server"); return; } i -= k; j += k; } } catch (Exception e) { debug.dumpTrace("class rpc_function, constructor 2, read data from stream error"); valid = false; return; } return; }//end of switch } catch (Exception e) { debug.dumpTrace("class rpc_function, constructor 2, error reading integer or bool from stream"); valid = false; return; } }//end of if (version == 1) else if (version == 2) { parameter p; //temporary parameter read from stream //read the function name String s2 = x.read_string_from_stream(bis); //error checking if (s2 == null) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, null function name."); valid = false; return; } //function name is "NULL" if ( s2.equals("NULL") ) { set_name(null); } else { set_name(s2); } //read the number of parameters int number_parameters; try { number_parameters = x.read_integer_from_stream(bis); } catch (Exception e) { debug.dumpTrace("class rpc_function, constructor 2, error reading number parameters from stream"); valid = false; return; } //error checking if ( number_parameters < 0 ) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, negative number of parameters"); valid = false; return; } if (number_parameters > MAX_NUMBER_PARAMETERS) { // too many parameters, probably something goes wrong debug.dumpTrace("class rpc_function, constructor 2, too many parameters"); valid = false; return; } //read parameters for (int loop = 1; loop <= number_parameters; loop++) { p = new parameter(bis, version, debug); if(add_parameter(p) != OK) { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, invalid paramter"); valid = false; return; } } return; }//end if (version == 2) else { debug.dumpTrace("Class: rpc_function, Method: Constructor from stream, invalid version number" + Integer.toString(version)); valid = false; return; } }//end of constructor /** method description: this method will add the parameter to the function the parameter will be added at the end of the parameter list uses the services of class(es): Debug input parameter(s): parameter p, the parameter to be added output parameter(s): none return value: OK ADD_PARAMETER_INVALID_PARAMETER synchronization consideration: synchroized */ public synchronized int add_parameter(parameter p) { //error checking for parameter if (p == null) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, null parameter"); return ADD_PARAMETER_INVALID_PARAMETER; } //valid checking for parameter if ( !p.is_valid()) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, invalid parameter"); return ADD_PARAMETER_INVALID_PARAMETER; } //add the parameter else { parameter_list.addElement(p); return OK; } } /** method description: this method will add the parameter to the function the parameter will be added at the place of index uses the services of class(es): Debug input parameter(s): int index, the index indicats the location for adding the parameter parameter p, the parameter to be added output parameter(s): none return value: OK ADD_PARAMETER_INVALID_INDEX ADD_PARAMETER_INVALID_PARAMETER synchronization consideration: synchronized */ public synchronized int add_parameter(int index, parameter p) { //error checking for index if ( (index < 0) || (index > parameter_list.size()) ) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, invalide index number"); return ADD_PARAMETER_INVALID_INDEX; } //error checking for parameter if (p == null) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, null parameter"); return ADD_PARAMETER_INVALID_PARAMETER; } //valid checking for parameter if ( !p.is_valid()) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, invalid parameter"); return ADD_PARAMETER_INVALID_PARAMETER; } //add the parameter else { parameter_list.insertElementAt(p, index); return OK; } } /** method description: this method will delete the parameter at the index position uses the services of class(es): Debug input parameter(s): int index, the index indicats the location for deleting the parameter output parameter(s): none return value: OK DELETE_PARAMETER_INVALID_INDEX synchronization consideration: synchroized */ public synchronized int delete_parameter(int index) { //check the index if ( (index < 0) || (index >= parameter_list.size()) ) { debug.dumpTrace("Class: rpc_function, Method: delete_parameter, invalid index number"); return DELETE_PARAMETER_INVALID_INDEX; } //delete the parameter parameter_list.removeElementAt(index); return OK; } /** method description: this method will return the name of the function uses the services of class(es): none input parameter(s): none output parameter(s): none return value: String name of the function synchronization consideration: none */ public String get_name() { return name; } /** method description: this method will return the number of the parameters in the function uses the services of class(es): none input parameter(s): none output parameter(s): none return value: integer, number of parameters of the function synchronization consideration: none */ public int get_number_parameters () { return parameter_list.size(); } /** method description: this method will return the parameter which locates at the index position uses the services of class(es): Debug input parameter(s): int index, the position of the parameter output parameter(s): none return value: parameter, the parameter object synchronization consideration: synchronized */ public synchronized parameter get_parameter(int index) { //check for the index if ( (index < 0) || (index >= parameter_list.size()) ) { debug.dumpTrace("Class: rpc_function, Method: get_parameter, invalid index number"); return null; } //return the parameter return (parameter) parameter_list.elementAt(index); } /** method description: this method will set the name of the function uses the services of class(es): none input parameter(s): String name, the name which will be set output parameter(s): none return value: OK 0; synchronization consideration: none */ public int set_name(String name) { this.name = name; return OK; } /** method description: this method will set the parameter at position index uses the services of class(es): Debug input parameter(s): int index, the position of the parameter parameter p, the parameter which will be set output parameter(s): none return value: OK SET_PARAMETER_INVALID_PARAMETER SET_PARAMETER_INVALID_INDEX synchronization consideration: synchronized */ public synchronized int set_parameter(int index, parameter p) { //error checking for parameter if (p == null) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, null parameter"); return ADD_PARAMETER_INVALID_PARAMETER; } //valid checking for parameter if ( !p.is_valid()) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, invalid parameter"); return ADD_PARAMETER_INVALID_PARAMETER; } //error checking for index if ( (index < 0) || (index >= parameter_list.size()) ) { debug.dumpTrace("Class: rpc_function, Method: add_parameter, invalide index number"); return ADD_PARAMETER_INVALID_INDEX; } //add the parameter else { parameter_list.setElementAt(p,index); return OK; } } /** method description: this method will write the function into the stream in xdr format uses the services of class(es): Debug, xdr, parameter input parameter(s): BufferedOutputStream bos, output stream int version, version number output parameter(s): none return value: OK TO_STREAM_IN_XDR_NULL_STREAM TO_STREAM_IN_XDR_NULL_NAME TO_STREAM_IN_XDR_WRITE_FAILED TO_TREAM_IN_XDR_UNKNOWN_FUNCTION TO_STREAM_IN_XDR_INVALID_VERSION synchronization consideration: synchronized */ public synchronized int to_stream_in_xdr(BufferedOutputStream bos, int version) { int i; //loop variable xdr x = new xdr(debug); //xdr object to output the data; parameter p = null; //temporary paramter //error checking for the stream if (bos == null) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, null stream"); return TO_STREAM_IN_XDR_NULL_STREAM; } if (! valid) { // we cann't write an invalid function to stream otherwise the other // side will not be able to recongnize it debug.dumpTrace("class rpc_function, method to_stream_in_xdr, function is not valid"); return TO_STREAM_IN_XDR_FUNCTION_NOT_VALID; } if ((version != 1) && (version != 2)) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, invalide version number" + Integer.toString(version)); return TO_STREAM_IN_XDR_INVALID_VERSION; } // do some measurement based on the function name /* if (name.equals("show_retrieval_coll")) { // function show_retrieval_coll is just send out // end measure the time between search collection received // from webgate and show retrieval coll send out to webgate debug.pm.end_measure(marian_server.FIRST_BATCH_TOTAL_TIME); // end measure the time between show_raw_retr received from // c marian server and show_retrieval_coll send out to webgate debug.pm.end_measure(marian_server.FIRST_BATCH_POSTPROCESS_TIME); } else if (name.equals("add_to_retrieval_coll")) { // function add_to_retrieval_coll is just send out // end measure the time between show next k received from webgate // and add to retrieval retrieval coll send out to webgate debug.pm.end_measure(marian_server.SECOND_BATCH_TOTAL_TIME); // end measure the time between add_raw_retr received from // c marian server and add_to_retrieval_coll send out to webgate debug.pm.end_measure(marian_server.SECOND_BATCH_POSTPROCESS_TIME); } else if (name.equals("new_query")) { // function new_query is just send out // end measure the time between search_collection received from // webgate and new_query send out to c marian server debug.pm.end_measure(marian_server.FIRST_BATCH_PREPROCESS_TIME); // start measure the time between new_query send out to c marian // server and show_raw_retr received from c marian server debug.pm.start_measure(marian_server.FIRST_BATCH_C_TIME); } else if (name.equals("find_next_k_docs")) { // function find_next_k_docs is just send out // end measure the time between show_next_k received from // webgate and find_next_k_docs send out to c marian server debug.pm.end_measure(marian_server.SECOND_BATCH_PREPROCESS_TIME); // start measure the time between find_next_k_docs send out to c marian // server and add_raw_retr received from c marian server debug.pm.start_measure(marian_server.SECOND_BATCH_C_TIME); } */ if (version == 1) { //check the name if (name == null) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, null function name"); return TO_STREAM_IN_XDR_NULL_NAME; } //write the length of the function int func_length = 2 * x.get_integer_size(); for (i = 0; i < parameter_list.size(); i++) { p = (parameter) parameter_list.elementAt(i); func_length += p.get_size_in_xdr(); } if (x.integer_to_stream_in_xdr(func_length, bos) != x.OK) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, write function failed"); return TO_STREAM_IN_XDR_WRITE_FAILED; } //write the function code int func_code = -1; if ( name.equals("show_retrieval_coll") ) { func_code = 1; } else if ( name.equals("solicit_biblio_query") ) { func_code = 2; } else if ( name.equals("show_information") ) { func_code = 6; } else if ( name.equals("append_to_text") ) { func_code = 14; } else if ( name.equals("add_to_retrieval_coll") ) { func_code = 16; } else if ( name.equals("biblio_query_text") ) { func_code = 5; } else if ( name.equals("search_collection") ) { func_code = 18; } else if ( name.equals("end_session") ) { func_code = 19; } else if ( name.equals("show_next_k") ) { func_code = 25; } else if ( name.equals("get_circulation_info") ) { func_code = 31; } else if ( name.equals("new_session") ) { func_code = 0; } else if ( name.equals("query_token") ) { func_code = 101; } else if ( name.equals("close_session") ) { func_code = 102; } else if ( name.equals("new_query") ) { func_code = 103; } else if ( name.equals("find_next_k_docs") ) { func_code = 104; } else if ( name.equals("start_processing") ) { func_code = 105; } else if ( name.equals("end_processing") ) { func_code = 106; } else if ( name.equals("error_for_session_manager") ) { func_code = 107; } else if ( name.equals("show_information_query") ) { func_code = 110; } else if ( name.equals("show_information_1") ) { func_code = 111; } else if ( name.equals("show_raw_retr") ) { func_code = 112; } else if ( name.equals("add_raw_retr") ) { func_code = 113; } else if ( name.equals("startup_notify") ) { func_code = 114; } if (func_code == -1) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, unknown function name"); return TO_TREAM_IN_XDR_UNKNOWN_FUNCTION; } if (x.integer_to_stream_in_xdr(func_code, bos) != x.OK) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, write function failed"); return TO_STREAM_IN_XDR_WRITE_FAILED; } }//end if (version == 1) else { //version is 2 here, write the name if (name == null) { if ( x.string_to_stream_in_xdr("NULL", bos) != x.OK) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, write function failed"); return TO_STREAM_IN_XDR_WRITE_FAILED; } } else { if (x.string_to_stream_in_xdr(name, bos) != x.OK) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, write function failed"); return TO_STREAM_IN_XDR_WRITE_FAILED; } } //write the parameter number if ( x.integer_to_stream_in_xdr(parameter_list.size(), bos) != x.OK ) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, write function failed"); return TO_STREAM_IN_XDR_WRITE_FAILED; } //write each parameter in the stream for (i = 0; i < parameter_list.size(); i++) { p = (parameter) parameter_list.elementAt(i); if (p.to_stream_in_xdr(version, bos) != p.OK) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, write function failed"); return TO_STREAM_IN_XDR_WRITE_FAILED; } } try { bos.flush(); } catch (Exception e) { debug.dumpTrace("class rpc_function, method to_stream_in_xdr, error flushing the stream"); return TO_STREAM_IN_XDR_WRITE_FAILED; } return OK; } //write the parameters for (i = 0; i < parameter_list.size(); i++) { p = (parameter) parameter_list.elementAt(i); if (p.to_stream_in_xdr(version, bos) != p.OK) { debug.dumpTrace("Class: rpc_function, Method: to_stream_in_xdr, write function failed"); return TO_STREAM_IN_XDR_WRITE_FAILED; } } try { bos.flush(); } catch (Exception e) { debug.dumpTrace("class rpc_function, method to_stream_in_xdr, error flushing the stream"); return TO_STREAM_IN_XDR_WRITE_FAILED; } return OK; }//end of to_stream_in_xdr /** method description: this method will write the function into the stream in readable format uses the services of class(es): Debug, xdr, parameter input parameter(s): int detail_level PrintWriter pw; output parameter(s): none return value: OK TO_STREAM_NULL_STREAM TO_STREAM_WRITE_FAILED TO_STREAM_WRITE_PARAMETER_FAILED synchronization consideration: synchronized */ public synchronized int to_stream (int detail_level, PrintWriter pw) { //check the stream if (pw == null) { debug.dumpTrace("Class: rpc_function, Methods: to_stream, null output stream"); return TO_STREAM_NULL_STREAM; } //check the detail level if (detail_level < 2) { return OK; } //print the name pw.print("name = "); pw.println(name); //check the detail level if (detail_level < 3) { pw.flush(); return OK; } //print the number of parameters pw.print("number parameters = "); pw.println(parameter_list.size()); parameter p; //temporary parameter object for (int i = 0; i < parameter_list.size(); i++) { p = (parameter) parameter_list.elementAt(i); if (p.to_stream(detail_level, pw) != p.OK) { debug.dumpTrace("Class: rpc_function, Methods: to_stream, write parameter failed"); return TO_STREAM_WRITE_PARAMETER_FAILED; } } pw.flush(); return OK; }//end of to_stream /** method description: this method will return the valid value uses the services of class(es): none input parameter(s): none output parameter(s): none return value: boolean valid value synchronization consideration: none */ public boolean is_valid() { return valid; } }//end of rpc_function class