timerrequesthandler.java

来自「Software Testing Automation Framework (S」· Java 代码 · 共 850 行 · 第 1/2 页

JAVA
850 行
字号
        "{STAF/Service/Timer/UnregisterOnNoPath}", sHandle);    if (res.rc == STAFResult.Ok)    {        try        {            int iunregisterOnNoPath = Integer.parseInt(res.result);            if (iunregisterOnNoPath == 0)                unregisterOnNoPath = false;            else                unregisterOnNoPath = true;        }        catch (NumberFormatException e)        {            // Set to default            unregisterOnNoPath = true;            timer.log.log(STAFLog.Warning, "Invalid value specified "+                "for UnregisterOnNoPath, using default value (true)");        }    }    else if (res.rc == STAFResult.VariableDoesNotExist)    {        // Set to default        unregisterOnNoPath = true;    }    else    {        // Unexpected Result shouldn't ever go here        result = new STAFResult(res.rc, UNEXPECTEDVARRESULT);        timer.log.log(STAFLog.Warning, "Unexpected error attempting to "+            "resolve UnregisterOnNoPath, using default value (true)");        unregisterOnNoPath = true;    }    // Resolve the TotalFileAttempts variable for the local machine    res = STAFUtil.resolveInitVar(        "{STAF/Service/Timer/TotalFireAttempts}", sHandle);    if (res.rc == STAFResult.Ok)    {        try        {            failCountLimit = Integer.parseInt(res.result);            if (failCountLimit < 0)            {                timer.log.log(STAFLog.Warning, "Negative value specified for "+                    "TotalFireAttempts, using default value (3)");                failCountLimit = 3;            }        }        catch (NumberFormatException e)        {            // Set to default            failCountLimit = 3;            timer.log.log(STAFLog.Warning, "Invalid value specified "+                "for TotalFireAttempts, using default value (3)");        }    }    else if (res.rc == STAFResult.VariableDoesNotExist)    {        // Set to default        failCountLimit = 3;    }    else    {        // Unexpected Result shouldn't ever go here        result = new STAFResult(res.rc, UNEXPECTEDVARRESULT);        timer.log.log(STAFLog.Warning, "Unexpected error attempting to "+            "resolve TotalFireAttempts, using default value (3)");        failCountLimit = 3;    }    return result;}/****************************************************************************///// Method://   register//// Description://   Handler method for register request.//// Input://   name - The String Name (Type) of this timer.//   machine - The machine name this timer should notify.//   handle - The Handle of the process on the machine this//             timer should notify.//   handleName - The handle name of the process this timer should notify.//   key - The key specified for this timer (or "" if no key is specified)//   frequency - The frequency of this timer.//   priority - The priority of the Queue message this timer should//               send to the registered machine.//   unregOnNoPath - specifies a timer specific variable for unregisterOnNoPath//                   a value of -1 means use the global variable (not timer specific)//   unregOnNoHandle - specifies a timer specific variable for unregisterOnNoHandle//                     a value of -1 means use the global variable (not timer specific)//   byname - Boolean that specifies if the BYNAME parameter was specified.//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult register(String name, String machine, int handle,                           String handleName, String key,                           long frequency, long priority, int unregOnNoPath,                           int unregOnNoHandle, boolean byname){    // Check for good frequency    if (frequency < minFrequency)    {        return new STAFResult(            STAFResult.InvalidValue,            "FREQUENCY value " + frequency + " is less than the minimum " +            "allowable frequency " + minFrequency);    }    // Check for good priority    if (priority < 0 || priority > (Math.pow(2, 32)-1))    {        return new STAFResult(            STAFResult.InvalidValue,            "PRIORITY value " + priority + " is invalid.  " +            "It must be between 0 and 2^32-1");    }    // Choose which createTimerString method to call (byname)    String timerString;    if (byname)    {        timerString = TimerUtils.createTimerString(            name, machine, handleName, key);    }    else    {        timerString = TimerUtils.createTimerString(            name, machine, handle, key);    }        // Check if this timer is already registered.  If so, return an error.    if (timerList.getTimerObject(timerString) != null)    {        return new STAFResult(STAFResult.AlreadyExists, timerString);    }    // Create new timer    TimerObject timer = new TimerObject(        name, machine, handle, handleName, key, frequency,        priority, this, unregOnNoPath, unregOnNoHandle, byname);        // Don't allow update of a timer that already exists anymore.    //TimerObject timer = timerList.getTimerObject(timerString);    //timer.update(frequency, priority, unregOnNoPath, unregOnNoHandle);        return new STAFResult(STAFResult.Ok);}/****************************************************************************///// Method://   term//// Description://   Called when this service is stopped.//// Input://   none//// Exceptions Thrown://   none//// Notes://   Stops TimerManger thread, writes out TimerList, and unregisters the//   STAFHandle.///****************************************************************************/public int term(){    tManager.term();    wManager.term();    // Don't try to write if did not create a filename, no persistent storage    if (!(timer.tListFileName == null))    {         // If tListFileName is null so is wListFileName        TimerUtils.writeTimerList(timerList, timer.tListFileName);        TimerUtils.writeWatchList(watchList, timer.wListFileName);    }    try    {        sHandle.unRegister();        timer.wHandle.unRegister();    }    catch (STAFException e)    {        timer.log.log(STAFLog.Warning,                      "Error during unregister; RC = " + e.rc);        return e.rc;    }    return STAFResult.Ok;}/****************************************************************************///// Method://   unregister//// Description://   Handler method for unregister request.//// Input://   timerString - TimerString representing timer to unregister//// Exceptions Thrown://   none//// Notes://   The trust level checking is done in TimerCmdParser.parseUnregister()//   because we must know the machine the timer is running on and the//   machine submitting the request.///****************************************************************************/public STAFResult unregister(String timerString){    /* Unregister timer */    if (timerList.containsTimer(timerString))    {        timerList.remove(timerString);        return new STAFResult(STAFResult.Ok);    }    else    {        return new STAFResult(            STAFResult.DoesNotExist,            "The TYPE specified does not exist for the specified " +            "machine and handle number/name (and key if specified)");    }}/****************************************************************************///// Method://   getTimerObject//// Description://   Handler method for getting a timer object from the timer list.//// Input://   timerString - The unique String representation of the timer.//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public TimerObject getTimerObject(String timerString){    return timerList.getTimerObject(timerString);}/****************************************************************************///// Method://   unwatch//// Description://   Handler method for unregister request.//// Input://   machineToWatch - name of the machine to be unwatched//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult unwatch(String machineToWatch){    // Unregister watch        String machineUpper = machineToWatch.toUpperCase();    if (!watchList.containsWatch(machineToWatch.toUpperCase()))    {        return new STAFResult(            STAFResult.InvalidValue,            "Machine " + machineToWatch + " is not currently being watched");    }        try    {        // Unregister the timer with machineToWatch        String request = "UNREGISTER TYPE " + sWatchType +            " BYNAME KEY " + machineUpper;        timer.wHandle.submit(machineToWatch, "TIMER", request);    }    catch (STAFException e)    {        timer.log.log(STAFLog.Warning,            "Error unregistering watch. Could not unregister " +            "corresponding timer with machine: " + machineToWatch +            ". RC:"+e.rc);    }    watchList.remove(machineUpper);    return new STAFResult(STAFResult.Ok);}/****************************************************************************///// Method://   version//// Description://   Handler method for version request.//// Input://   STAFServiceInterfaceLevel30.RequestInfo//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult version(STAFServiceInterfaceLevel30.RequestInfo info){    return new STAFResult(STAFResult.Ok, VERSION);}/****************************************************************************///// Method://   watch//// Description://   Handler method for the watch request.//// Input://   machineToWatch - the name of the machine to be watched//   frequency - The frequency of this watch//   margin - the allowable error in the response time of the machine being//            watched//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult watch(String machineToWatch, long frequency, int margin){    String machineToWatchOrg = machineToWatch;    // Use uppercase for hashtable key    machineToWatch = machineToWatch.toUpperCase();    // See if watch already exists    if ((watchList != null) && (watchList.containsWatch(machineToWatch)))    {        // Watch exists, update watch        return new STAFResult(STAFResult.AlreadyExists, machineToWatchOrg);        // Don't allow update of existing watch anymore        //WatchObject watch = watchList.getWatchObject(machineToWatch);        //watch.update(frequency, margin);    }    else    {        try        {            // Create new watch            new WatchObject(machineToWatch, frequency, margin, this);        }        catch (STAFException e)        {            timer.log.log(STAFLog.Error,                "Error registering a timer with machine: " + machineToWatchOrg +                " RC:" + e.rc);            return new STAFResult(                e.rc, "Error registering a timer with machine: " +                machineToWatchOrg);        }    }    return new STAFResult(STAFResult.Ok);}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?