package edu.vt.marian.server; import java.io.*; import java.net.*; import java.lang.*; import java.util.*; import edu.vt.marian.common.*; import edu.vt.marian.uip.*; //---------------------------------------------------------------------------------- // Class name: status // Class description: used by classes used to to the stress testing of Java // marian server // Author: Li Zhang // Finished time: November, 1998 // Known bugs: none // Platform: Visual J++ 6.0 under Windows 95 //---------------------------------------------------------------------------------- public class status { // used for debugging Debug debug = null; // possible status public final static int NOT_FOUND = 0; public final static int SEARCH_COLLECTION_SEND_OUT = 1; public final static int BIBLIO_QUERY_TEXT_SEND_OUT = 2; public final static int SHOW_NEXT_K_SEND_OUT = 3; // possible return value of methods public final static int OK = 0; public final static int WEBGATE_NOT_FOUND = 1; public final static int ENTRY_NOT_FOUND = -1; public final static int DUPLICATE_ADDING = -2; // this vector contains the status for all the queries of all // the users of all the webgates private Vector states = new Vector(); // constructor public status(Debug debug) { this.debug = debug; } // this method will add a new entry into the table, the entry is identified // by the specified client_uip, user_id, query_id and has the specified // state public synchronized int add(client_uip cu, int user_id, int query_id, int state) { Vector webgate = null; client_uip my_cu = null; int my_user_id, my_query_id; for (int i = 0; i < states.size(); i++) { webgate = (Vector) states.elementAt(i); my_cu = (client_uip) webgate.elementAt(0); my_user_id = ((Integer) webgate.elementAt(1)).intValue(); my_query_id = ((Integer) webgate.elementAt(2)).intValue(); if ((my_cu == cu) && (my_user_id == user_id) && (my_query_id == query_id)) { // we find a match, cann't add this entry debug.dumpTrace("class status, method add, duplicate entry found"); return DUPLICATE_ADDING; } } // this is a new entry, add it into states vector webgate = new Vector(); webgate.addElement(cu); webgate.addElement(new Integer(user_id)); webgate.addElement(new Integer(query_id)); webgate.addElement(new Integer(state)); states.addElement(webgate); return OK; } // this method will delete all the entries which has the specified client // uip from the table public synchronized int delete_webgate(client_uip cu) { client_uip my_cu = null; Vector webgate = null; int number_deleted = 0; for (int i = states.size() - 1; i >= 0; i--) { webgate = (Vector) states.elementAt(i); my_cu = (client_uip) webgate.elementAt(0); if (my_cu == cu) { // we find a match, delete it states.removeElementAt(i); number_deleted++; } } return number_deleted; } // this method will set the state for the entry with the specified client // uip, user_id and query_id public synchronized int set(client_uip cu, int user_id, int query_id, int state) { Vector webgate = null; client_uip my_cu = null; int my_user_id, my_query_id; for (int i = 0; i < states.size(); i++) { webgate = (Vector) states.elementAt(i); my_cu = (client_uip) webgate.elementAt(0); my_user_id = ((Integer) webgate.elementAt(1)).intValue(); my_query_id = ((Integer) webgate.elementAt(2)).intValue(); if ((my_cu == cu) && (my_user_id == user_id) && (my_query_id == query_id)) { // we find a match, set it's state webgate.setElementAt(new Integer(state), 3); return OK; } } // we couldn't find the corresponding entry return ENTRY_NOT_FOUND; } // this method will return the state of the entry with the specified // client_uip, user_id and query_id public synchronized int get(client_uip cu, int user_id, int query_id) { Vector webgate = null; client_uip my_cu = null; int my_user_id, my_query_id; for (int i = 0; i < states.size(); i++) { webgate = (Vector) states.elementAt(i); my_cu = (client_uip) webgate.elementAt(0); my_user_id = ((Integer) webgate.elementAt(1)).intValue(); my_query_id = ((Integer) webgate.elementAt(2)).intValue(); if ((my_cu == cu) && (my_user_id == user_id) && (my_query_id == query_id)) { // we find a match, return it's state int state = ((Integer) webgate.elementAt(3)).intValue(); return state; } } // we couldn't find the corresponding entry return ENTRY_NOT_FOUND; } }