timerrequesthandler.java

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

JAVA
850
字号
package com.ibm.staf.service.timer;import com.ibm.staf.service.STAFServiceInterfaceLevel30;/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002, 2004, 2005                                  *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************//****************************************************************************///// Class: TimerRequestHandler//// Logical Name: TimerRequestHandler.java//// Description: This class performs the requested actions of STAF commands//              after they have been parsed.////// History://// DATE       DEVELOPER   CHANGE DESCRIPTION// ---------- ----------- -----------------------------------// 02/01/2000 C Alkov     Original Program// 04/05/2000 C Alkov     Update version to 1.01 (def:3610,3622)// 04/27/2004 S Lucas     Updated version to 3.0.0///****************************************************************************/import com.ibm.staf.*;import com.ibm.staf.wrapper.STAFLog;import java.util.Map;public class TimerRequestHandler{    private int minFrequency;    boolean unregisterOnNoHandle;    boolean unregisterOnNoPath;    int failCountLimit;    String sName;    STAFHandle sHandle;    String sWatchType;    STAFMapClassDefinition fTimerMapClass;    STAFMapClassDefinition fTimerLongMapClass;    STAFMapClassDefinition fWatchMapClass;    STAFMapClassDefinition fWatchLongMapClass;    STAFMapClassDefinition fSettingsMapClass;    String LINESEP;    private final static String UNEXPECTEDVARRESULT =        "Unexpected Result from call to VAR service";    private final static String VERSION = "3.0.2";    TimerList timerList;    WatchList watchList;    Timer timer;    TimerManager tManager;    WatchManager wManager;    /****************************************************************************///// Method://   Constructor//// Description://   Constructor method for the TimerRequestHandler class.//// Input://   name - The STAF name of this service.//   handle - The STAFHandle of this service.//   aTimer - reference to the main Timer object//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public TimerRequestHandler(String name, STAFHandle handle, Timer aTimer){    sName = name;    sHandle = handle;    timer = aTimer;    sWatchType = "STAF/Service/" + sName + "/Watch";        // Construct map class for a LIST TIMERS request.    fTimerMapClass = new STAFMapClassDefinition(        "STAF/Service/Timer/Timer");    fTimerMapClass.addKey("type", "Type");    fTimerMapClass.addKey("machine", "Machine");    fTimerMapClass.addKey("notifyBy", "Notify By");    fTimerMapClass.setKeyProperty("notifyBy", "display-short-name", "Notify");    fTimerMapClass.addKey("notifiee", "Notifiee");    fTimerMapClass.addKey("key", "Key");    fTimerMapClass.addKey("lastTimestamp", "Last Fired Date-Time");    fTimerMapClass.setKeyProperty("lastTimestamp", "display-short-name",                                  "Last Date-Time");    fTimerMapClass.addKey("frequency", "Frequency");    fTimerMapClass.setKeyProperty("frequency", "display-short-name", "Freq");    // Construct map class for a LIST TIMERS LONG request.    fTimerLongMapClass = new STAFMapClassDefinition(        "STAF/Service/Timer/TimerLong");    fTimerLongMapClass.addKey("type", "Type");    fTimerLongMapClass.addKey("machine", "Machine");    fTimerLongMapClass.addKey("notifyBy", "Notify By");    fTimerLongMapClass.addKey("notifiee", "Notifiee");    fTimerLongMapClass.addKey("key", "Key");    fTimerLongMapClass.addKey("lastTimestamp", "Last Fired Date-Time");    fTimerLongMapClass.addKey("frequency", "Frequency");    fTimerLongMapClass.addKey("priority", "Priority");    fTimerLongMapClass.addKey("unRegOnNoPath", "Unregister On No Path");    fTimerLongMapClass.addKey("unRegOnNoHandle", "Unregister On No Handle");    // Construct map class for a LIST WATCHES request.    fWatchMapClass = new STAFMapClassDefinition(        "STAF/Service/Timer/Watch");    fWatchMapClass.addKey("machine", "Machine To Watch");    fWatchMapClass.addKey("status", "Status");    fWatchMapClass.addKey("lastTimestamp", "Last Fired Date-Time");    fWatchMapClass.setKeyProperty("lastTimestamp", "display-short-name",                                  "Last Date-Time");    fWatchMapClass.addKey("frequency", "Frequency");    fWatchMapClass.setKeyProperty("frequency", "display-short-name", "Freq");    fWatchMapClass.addKey("margin", "Margin");    // Construct map-class for LIST SETTINGS information    fSettingsMapClass = new STAFMapClassDefinition(        "STAF/Service/Timer/Settings");    fSettingsMapClass.addKey("directory", "Directory");    // Resolve the line separator variable for the local machine    STAFResult res = STAFUtil.resolveInitVar("{STAF/Config/Sep/Line}", sHandle);    if (res.rc == STAFResult.Ok)        LINESEP = res.result;    else        LINESEP = "/";    // Read in timer and watch list, except if we are not using persistent    // storage    if (!(timer.tListFileName == null))    {        // If tListFileName is null, so is wListFileName        timerList = TimerUtils.readTimerList(this, timer.tListFileName);        watchList = TimerUtils.readWatchList(this, timer.wListFileName);    }        // No timer list create new list     if (timerList == null)    {        timerList = new TimerList(this);        watchList = new WatchList(this);    }    if (watchList == null)    {        watchList = new WatchList(this);    }    // Start TimerManager thread    tManager = new TimerManager(timerList);    tManager.start();    // Start WatchMangager thread    wManager = new WatchManager(watchList);    wManager.start();}/****************************************************************************///// Method://   help//// Description://   Handler method for help request.//// Input://   machine - name of machine making the request//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult help(String serviceName){    String HELP =      "Timer Service Help"+ LINESEP+LINESEP+      "REGISTER   TYPE <Type> FREQUENCY <Milliseconds> [PRIORITY <Level>] [KEY <Key>]"+      LINESEP +      "           [BYNAME] [UNREGONNOPATH <1 | 0>] [UNREGONNOHANDLE <1 | 0>]" +      LINESEP +      "UNREGISTER TYPE <Type> [KEY] [BYNAME |" + LINESEP +      "           <MACHINE <Machine> HANDLE <Handle #> | NAME <Handle Name>>]" +      LINESEP +      "WATCH      MACHINE <Machine> FREQUENCY <Milliseconds> [MARGIN <Milliseconds>]"+      LINESEP +      "UNWATCH    MACHINE <Machine>" +      LINESEP +      "LIST       <TIMERS [LONG]> | WATCHES | SETTINGS" +      LINESEP +      "REFRESH" +       LINESEP +      "VERSION" +      LINESEP +      "HELP";    STAFResult result = new STAFResult(STAFResult.Ok, HELP);    return result;}/****************************************************************************///// Method://   listSettings//// Description://   Handler method for listing the operational settings for the Timer service//// Input://   STAFServiceInterfaceLevel30//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult listSettings(STAFServiceInterfaceLevel30.RequestInfo info){    // LIST SETTINGS    STAFMarshallingContext mc = new STAFMarshallingContext();    mc.setMapClassDefinition(fSettingsMapClass);    Map outputMap = fSettingsMapClass.createInstance();    outputMap.put("directory", timer.fDataDir);    mc.setRootObject(outputMap);    return new STAFResult(STAFResult.Ok, mc.marshall());}/****************************************************************************///// Method://   listTimers//// Description://   Handler method for list timers request.//// Input://   STAFServiceInterfaceLevel30//   format - boolean specifying whether to format output//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult listTimers(STAFServiceInterfaceLevel30.RequestInfo info,                             boolean format){    return new STAFResult(STAFResult.Ok, timerList.listTimers(format));}/****************************************************************************///// Method://   listWatches//// Description://   Handler method for list timers request.//// Input://   STAFServiceInterfaceLevel30//   format - boolean specifying whether to format output//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult listWatches(STAFServiceInterfaceLevel30.RequestInfo info){    return new STAFResult(STAFResult.Ok, watchList.listWatches());}/****************************************************************************///// Method://   refresh//// Description://   Handler method for refresh request.//// Input://   STAFServiceInterfaceLevel30.RequestInfo//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public STAFResult refresh(){    String where = "LOCAL";    String service = "VAR";    STAFResult res;    STAFResult result = new STAFResult(STAFResult.Ok);    // Resolve the MinFrequency variable for the local machine    res = STAFUtil.resolveInitVar("{STAF/Service/Timer/MinFrequency}", sHandle);    if (res.rc == STAFResult.Ok)    {        try        {            minFrequency = Integer.parseInt(res.result);            if (minFrequency < 0)            {                // Set to default                minFrequency = 1000;                timer.log.log(STAFLog.Warning, "Invalid value specified "+                    "for MinFrequency, using default value (1000)");            }        }        catch (NumberFormatException e)        {            // Set to default            minFrequency = 1000;            timer.log.log(STAFLog.Warning, "Invalid value specified "+                    "for MinFrequency, using default value (1000)");        }    }    else if (res.rc == STAFResult.VariableDoesNotExist)    {        // Set to default        minFrequency = 1000;    }    else    {        // Unexpected Result shouldn't ever go here        result = new STAFResult(res.rc, UNEXPECTEDVARRESULT);        timer.log.log(STAFLog.Warning, "Unexpected error attempting to "+                    "resolve MinFrequency, using default value (1000)");        minFrequency = 1000;    }    // Resolve the UnregisterOnNoHandle variable for the local machine    res = STAFUtil.resolveInitVar(        "{STAF/Service/Timer/UnregisterOnNoHandle}", sHandle);    if (res.rc == STAFResult.Ok)    {        try        {            int iunregisterOnNoHandle = Integer.parseInt(res.result);            if (iunregisterOnNoHandle == 0)            {                unregisterOnNoHandle = false;            }            else            {                unregisterOnNoHandle = true;            }        }        catch (NumberFormatException e)        {            // Set to default            unregisterOnNoHandle = true;            timer.log.log(STAFLog.Warning, "Invalid value specified "+                "for UnregisterOnNoHandle, using default value (true)");        }    }    else if (res.rc == STAFResult.VariableDoesNotExist)    {        // Set to default        unregisterOnNoHandle = 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 UnregisterOnNoHandle, using default value (true)");        unregisterOnNoHandle = true;    }    // Resolve the UnregisterOnNoPath variable for the local machine    res = STAFUtil.resolveInitVar(

⌨️ 快捷键说明

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