⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timerobject.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//   The run method of the TimerObject class.  Causes the timer//   to send a message to the process on the machine which//   registered the timer.//// Input://   none//// Exceptions Thrown://   none//// Notes://   synchronized method///****************************************************************************/public synchronized void run() {    String where = machine;    String service = "QUEUE";    Date currentTime = new Date();    String formattedTime = TimerUtils.formatTime(currentTime);    String queueType = "STAF/Service/Timer";    // Create a marshalled map containing the message    Map messageMap = new HashMap();    messageMap.put("timerServiceName", reqHandler.sName);    messageMap.put("type", name);    messageMap.put("timestamp", formattedTime);    messageMap.put("key", key);    STAFMarshallingContext mc = new STAFMarshallingContext();    mc.setRootObject(messageMap);    String message = mc.marshall();    String request;        if (byname)     {        request = "QUEUE NAME " + handleName + " PRIORITY " + priority +            " TYPE " + STAFUtil.wrapData(queueType) +            " MESSAGE " + STAFUtil.wrapData(message);    }    else     {        request = "QUEUE HANDLE " + handle + " PRIORITY " + priority +            " TYPE " + STAFUtil.wrapData(queueType) +            " MESSAGE " + STAFUtil.wrapData(message);    }        try     {        String result = reqHandler.sHandle.submit(where, service, request);        // If this timer is registered byname, see if any processes were        // available to receive messages on target machine. If not, handle        // as if HandleDoesNotExist.                   if (byname)         {            if (Integer.parseInt(result) == 0)             {                // No processes registered to this handle name                // See if we should unregister                if (!this.noHandleVarSet)                 {                    // Use global variable                    if (reqHandler.unregisterOnNoHandle)                     {                        // unregister and log                         reqHandler.timer.log.log(                            STAFLog.Info, "No processes registered to " +                            "handle name " + handleName +                            ", unregistering timer: " +  this.timerString);                        reqHandler.unregister(timerString);                        return;                    }                }                else if (this.unregisterOnNoHandle)                 {                    // Use timer specified variable                    // Unregister and log                    reqHandler.timer.log.log(                        STAFLog.Info, "No processes registered to " +                        "handle name " + handleName +                        ", unregistering timer: " + this.timerString);                    reqHandler.unregister(timerString);                    return;                }                                // Did not unregister the timer, log error and continue                reqHandler.timer.log.log(                    STAFLog.Warning, "No processes registered to handle " +                    "name " + handleName + " for timer: " + this.timerString);                return;            }        }    }    catch (STAFException e)     {        // STAF threw exception, see what problem was and handle appropriately                if(e.rc == STAFResult.HandleDoesNotExist)         {            // Handle does not exist.  See if we should unregister timer.            if (!this.noHandleVarSet)             {                // Use global variable                if (reqHandler.unregisterOnNoHandle)                 {                    // Unregister and log                    reqHandler.timer.log.log(                        STAFLog.Info, "Registered handle does not exist, " +                        "unregistering timer: " + this.timerString);                    reqHandler.unregister(timerString);                    return;                }            }            else if (this.unregisterOnNoHandle)             {                // Use timer specific variable                // Unregister and log                reqHandler.timer.log.log(                    STAFLog.Info, "Registered handle does not exist, " +                    "unregistering timer: " + this.timerString);                reqHandler.unregister(timerString);                return;            }                        // Did not unregister the timer, log error and continue            reqHandler.timer.log.log(                STAFLog.Warning, "Registered handle does not exist for " +                "timer: " + this.timerString);            return;        }        else if (e.rc == STAFResult.NoPathToMachine ||                  e.rc == STAFResult.CommunicationError)          {            // No path to machine.  See if we should unregister timer.            if (!this.noPathVarSet)             {                // Use global variable                if(reqHandler.unregisterOnNoPath)                 {                    failCount++; // increment failCount                                        if (failCount >= reqHandler.failCountLimit)                     {                        // Unregister and log                        reqHandler.timer.log.log(                            STAFLog.Info,                             "Not able to contact registered machine, "+                            "unregistering timer: "+this.timerString);                        reqHandler.unregister(timerString);                        return;                    }                    else                     {                        // Do not unregister, just log                        reqHandler.timer.log.log(                            STAFLog.Info,                             "Not able to contact registered machine, "+                            "for timer: "+this.timerString+" This is attempt:"                            +failCount);                        return;                    }                }            }            else if (this.unregisterOnNoPath)             {                // Use timer specific variable                failCount++; // increment failCount                                if (failCount >= reqHandler.failCountLimit)                 {                    // Unregister and log                    reqHandler.timer.log.log(                        STAFLog.Info,                         "Not able to contact registered machine, "+                        "unregistering timer: "+this.timerString);                    reqHandler.unregister(timerString);                    return;                }                else                 {                    // Do not unregister, just log                    reqHandler.timer.log.log(                        STAFLog.Info,                         "Not able to contact registered machine, "+                        "for timer: "+this.timerString+" This is attempt:"+                        failCount);                    return;                }            }            // Did not unregister the timer, log error and continue            reqHandler.timer.log.log(                STAFLog.Warning,                 "Not able to contact registered machine, "+                "for timer: "+this.timerString);        }        else         {            /* Log error */            reqHandler.timer.log.log(                STAFLog.Info,                 "Unexpected error sending message "+                "for timer: "+this.timerString+"  RC="+e.rc);        }    }}/****************************************************************************///// Method: //   setReqHandler//// Description://   Sets the RequestHandler for the TimerObject.//// Input://   aReqHandler - Reference to the current RequestHandler//// Exceptions Thrown://   none//// Notes://   none///****************************************************************************/public void setReqHandler(TimerRequestHandler aReqHandler) {    reqHandler = aReqHandler;}/****************************************************************************///// Method: //   update//// Description://   Updates the frequency and priority of the Timer.//// Input://   newFrequency - The new frequency of the timer.//   newPriority - The new priority of the timer.//   fUnregOnNoPath - specifies a timer specific variable for unregisterOnNoPath//                    a value of -1 means use the global variable (not timer specific)//   fUnregOnNoHandle - specifies a timer specific variable for unregisterOnNoHandle//                      a value of -1 means use the global variable (not timer specific)//// Exceptions Thrown://   none//// Notes://   synchronized method///****************************************************************************/public synchronized void update(long newFrequency, long newPriority,                                 int fUnregOnNoPath, int fUnregOnNoHandle) {    frequency = newFrequency;    priority = newPriority;    noHandleVarSet = false;    noPathVarSet = false;    // Set timer specific values for unregister on no path/handle.    // A value of -1 means to use global value for variable.    if (fUnregOnNoPath == 1)     {        unregisterOnNoPath = true;        noPathVarSet = true;    }    else if (fUnregOnNoPath == 0)     {        unregisterOnNoPath = false;        noPathVarSet = true;    }    if (fUnregOnNoHandle == 1)     {        unregisterOnNoHandle = true;        noHandleVarSet = true;    }    else if(fUnregOnNoHandle == 0)     {        unregisterOnNoHandle = false;        noHandleVarSet = true;    }    // Update nextFireTime    if (lastFireTime == null)     {        nextFireTime = findNextFireTime();    }    else     {        nextFireTime = new Date(lastFireTime.getTime() + frequency);    }}}

⌨️ 快捷键说明

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