📄 staxtimeraction.java
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2002 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/package com.ibm.staf.service.stax;public class STAXTimerAction implements STAXAction, STAXTimedEventListener{ static final int INIT = 0; static final int CALLED_ACTION = 1; static final int COMPLETE = 2; static final String INIT_STRING = "INIT"; static final String CALLED_ACTION_STRING = "CALLED_ACTION"; static final String COMPLETE_STRING = "COMPLETE"; static final String STATE_UNKNOWN_STRING = "UNKNOWN"; private STAXTimerAction() { /* Do Nothing */ } public STAXTimerAction(String durationString, STAXAction action) { fUnevalDurationString = durationString; fDurationString = durationString; fAction = action; } public String getStateAsString() { switch (fState) { case INIT: return INIT_STRING; case CALLED_ACTION: return CALLED_ACTION_STRING; case COMPLETE: return COMPLETE_STRING; default: return STATE_UNKNOWN_STRING; } } public String getXMLInfo() { return "<timer duration=\"" + fDurationString + "\">"; } public String getInfo() { return fDurationString; } public String getDetails() { return "Duration:" + fDurationString + ";State:" + getStateAsString() + ";Action:" + fAction + ";Thread:" + fThread + ";TimedEvent:" + fTimedEvent + ";TimerExpiredCondition:" + fTimerExpiredCondition; } public void execute(STAXThread thread) { synchronized (this) { if (fState == INIT) { long multiplier = 1; String tempDurationString = null; try { // Set RC initially so if an error occurs early on that does // not terminate the job, <if expr="RC != 1"> won't fail. thread.pySetVar("RC", new Integer(-1)); fDurationString = thread.pyStringEval(fUnevalDurationString); tempDurationString = fDurationString; switch (fDurationString.charAt(fDurationString.length() - 1)) { case 's': { multiplier = 1000; break; } case 'm': { multiplier = 60000; break; } case 'h': { multiplier = 3600000; break; } case 'd': { multiplier = 24 * 3600000; break; } case 'w': { multiplier = 7 * 24 * 3600000; break; } case 'y': { multiplier = 365 * 7 * 24 * 3600000; break; } default: break; } if (multiplier != 1) { tempDurationString = fDurationString.substring(0, fDurationString.length() - 1); } fDuration = Long.parseLong(tempDurationString); fDuration *= multiplier; } catch (NumberFormatException e) { fState = COMPLETE; thread.popAction(); thread.setSignalMsgVar("STAXInvalidTimerValueMsg", getXMLInfo() + "\n\n" + e); thread.raiseSignal("STAXInvalidTimerValue"); return; } catch (STAXPythonEvaluationException e) { fState = COMPLETE; thread.popAction(); thread.setSignalMsgVar("STAXPythonEvalMsg", getXMLInfo(), e); thread.raiseSignal("STAXPythonEvaluationError"); return; } thread.pushAction(fAction.cloneAction()); fState = CALLED_ACTION; fThread = thread; fTimedEvent = new STAXTimedEvent(System.currentTimeMillis() + fDuration, this); thread.getJob().getSTAX().getTimedEventQueue().addTimedEvent( fTimedEvent); } else if (fState == CALLED_ACTION) { fState = COMPLETE; thread.getJob().getSTAX().getTimedEventQueue().removeTimedEvent( fTimedEvent); thread.popAction(); thread.pySetVar("RC", new Integer(0)); } else { fState = COMPLETE; thread.popAction(); } } } public void handleCondition(STAXThread thread, STAXCondition cond) { synchronized (this) { if (cond instanceof STAXTimerExpiredCondition) { thread.pySetVar("RC", new Integer(1)); } else if (fState == CALLED_ACTION) { thread.getJob().getSTAX().getTimedEventQueue().removeTimedEvent( fTimedEvent); } fState = COMPLETE; thread.popAction(); thread.removeCondition(fTimerExpiredCondition); } } public STAXAction cloneAction() { return new STAXTimerAction(fUnevalDurationString, fAction); } public void timedEventOccurred(STAXTimedEvent timedEvent) { synchronized (this) { if (fState != COMPLETE) { fThread.addCondition(fTimerExpiredCondition); fThread.schedule(); } } } private int fState = INIT; private String fUnevalDurationString = null; private String fDurationString = null; private long fDuration = 0; private STAXAction fAction = null; private STAXThread fThread = null; private STAXTimedEvent fTimedEvent = null; private STAXTimerExpiredCondition fTimerExpiredCondition = new STAXTimerExpiredCondition("Timer");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -