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: function_queue class description: this class represent a function queue, functions can be put into it and take out from it, since this is a queue, they follow FIFO (first in first out) rules. 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 26th, 1998 known bugs: JDK version: 1.1.5 side effects: */ public class function_queue { public final static int OK = 0; public final static int QUEUE_OVERFLOW = 1; public final static int NULL_RPC_FUNCTION = 2; private Vector functions; private int max_number_functions; /** this is just used for debugging */ Debug debug; /** method description: this constructor will create a function queue object, the maximum number of functions can be contained in this object is specified by the parameter uses the services of class(es): input parameter(s): max_number_functions -- this specified at most how many functions this queue can store debug -- used for debugging output parameter(s): none return value: none synchronization: none */ public function_queue(int max_number_functions, Debug debug) { this.debug = debug; functions = new Vector(); if (max_number_functions > 0) { this.max_number_functions = max_number_functions; return; } debug.dumpTrace("Class:function_queue Method:constructor Max_number_functions isn't greater than 0."); this.max_number_functions = 100; // default value return; } /** method description: this method will take a function from the head of this queue uses the services of class(es): none input parameter(s): none output parameter(s): none return value: a rpc_function object -- this is the function at the head position before this method is called null -- the queue is empty when this method is called synchronization: synchronized */ public synchronized rpc_function get_next_function() { if (functions.size() == 0) { return null; } rpc_function rf = (rpc_function)functions.firstElement(); functions.removeElementAt(0); return rf; } /** method description: this method will tell how many functions currently are contained in this object. uses the services of class(es): none input parameter(s): none output parameter(s): none return value: an integer specifies the current number of functions in this queue synchronization: none */ public int get_number_functions() { return functions.size(); } /** method description: this method will put the specified function to the end of the queue represented by this object uses the services of class(es): none input parameter(s): none output parameter(s): none return value: OK -- the function has been entered successfully QUEUE_OVERFLOW -- the function is not entered because the upper limit of the queue has been reached NULL_RPC_FUNCTION -- the parameter rf is null synchronization: synchronized */ public synchronized int enter_function(rpc_function rf) { if (rf == null) { return NULL_RPC_FUNCTION; } if (functions.size() >= max_number_functions) { debug.dumpTrace("class function_queue, method enter_function, queue overflowed"); return QUEUE_OVERFLOW; } functions.addElement(rf); return OK; } }