📄 timerobject.java
字号:
package com.ibm.staf.service.timer;/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2002, 2005 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************//****************************************************************************///// Class: TimerObject//// Logical Name: TimerObject.java//// Description: This class represents the actual timers.////// History://// DATE DEVELOPER CHANGE DESCRIPTION// ---------- ----------- -----------------------------------// 02/01/2000 C Alkov Original Program///****************************************************************************/import java.util.Date;import com.ibm.staf.*;import com.ibm.staf.wrapper.STAFLog;import java.io.Serializable;import java.io.ObjectInputStream;import java.util.Map;import java.util.HashMap;public class TimerObject implements Runnable, Serializable { private String name; private String timerString; private long frequency; private long priority; private String machine; private int handle; private String handleName; private String key; private Date lastFireTime; private Date nextFireTime; private boolean unregisterOnNoPath; private boolean unregisterOnNoHandle; private boolean noPathVarSet; private boolean noHandleVarSet; private boolean byname; private int failCount; /* Do not serialize (transient) this instance variable since reference will be different from run to run */ private transient TimerRequestHandler reqHandler; /****************************************************************************///// Method: // Constructor//// Description:// Constructor method for TimerObject class.//// Input:// fName - The String Name (Type) of this timer.// fMachine - The machine name (endpoint) this timer should notify.// fHandle - The Handle # of the process on the machine this// timer should notify.// fHandleName - The handle name of the process this timer should notify.// fKey - The key of this timer (or "" if none was specified)// fFrequency - The frequency of this timer.// fPriority - The priority of the Queue message this timer should// send to the registered machine.// rHandler - The requestHandlerObject which created this Timer.// fUnregOnNoPath - int representing the timer specific variable for// UnregisterOnNoPath// fUnregOnNoHandle - int representing the timer specific variable for// UnregisterOnNoHandle// fByname - Boolean that specifies if the BYNAME parameter was specified.//// Exceptions Thrown:// none//// Notes:// none///****************************************************************************/public TimerObject(String fName, String fMachine, int fHandle, String fHandleName, String fKey, long fFrequency, long fPriority, TimerRequestHandler rHandler, int fUnregOnNoPath, int fUnregOnNoHandle, boolean fByname) { name = fName; machine = fMachine; handle = fHandle; handleName = fHandleName; key = fKey; frequency = fFrequency; priority = fPriority; lastFireTime = null; reqHandler = rHandler; noHandleVarSet = false; noPathVarSet = false; byname = fByname; failCount = 0; /* Set timer specific values for unregister on no path/handle */ 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; } /* create timer string for key */ if (byname) { timerString = TimerUtils.createTimerString( name, machine, handleName, key); } else { timerString = TimerUtils.createTimerString( name, machine, handle, key); } /* find first fire time */ nextFireTime = this.findNextFireTime(); /* add to timer list */ reqHandler.timerList.put(timerString, this); reqHandler.tManager.wakeUpManager(); }public String getMachine(){ return machine;}/****************************************************************************///// Method: // findNextFireTime//// Description:// Calculates the next time this timer should fire a message.//// Input:// none //// Exceptions Thrown:// none//// Notes:// none///****************************************************************************/private Date findNextFireTime() { Date currentDate = new Date(); long fireTime = currentDate.getTime() + frequency; return new Date(fireTime); }/****************************************************************************///// Method: // fire//// Description:// This method starts a thread which will fire the message// to the process on the machine which was registered for// this timer.//// Input:// none//// Exceptions Thrown:// none//// Notes:// synchronized method///****************************************************************************/public synchronized void fire() { /* Store this fire time and calculate next fire time */ Date currentTime = new Date(); lastFireTime = currentTime; nextFireTime = new Date(currentTime.getTime() + frequency); /* Start thread to send message, using STAF QUEUE service */ Thread thisThread = new Thread(this, timerString); thisThread.start(); }/****************************************************************************///// Method: // getNextFireTime//// Description:// Returns the nextFireTime for this timer.//// Input:// none//// Exceptions Thrown:// none//// Notes:// synchronized method///****************************************************************************/public synchronized Date getNextFireTime() { return this.nextFireTime; }/****************************************************************************///// Method: // getProperties//// Description:// Returns the properties of this timer in a marshalled map for use in the// LIST TIMERS request.//// Input:// longFormat - boolean set to true if LONG is specified in the LIST request// so that more detailed information on each timer is provided//// Exceptions Thrown:// none//// Notes:// synchronized method///****************************************************************************/public synchronized Map getProperties(boolean longFormat) { Map properties; if (longFormat) properties = reqHandler.fTimerLongMapClass.createInstance(); else properties = reqHandler.fTimerMapClass.createInstance(); properties.put("type", name); properties.put("frequency", String.valueOf(frequency)); properties.put("machine", machine); if (byname) { properties.put("notifyBy", "Name"); properties.put("notifiee", handleName); } else { properties.put("notifyBy", "Handle"); properties.put("notifiee", String.valueOf(handle)); } properties.put("key", key); if (lastFireTime != null) properties.put("lastTimestamp", TimerUtils.formatTime(lastFireTime)); if (longFormat) { properties.put("priority", String.valueOf(priority)); if (noPathVarSet) properties.put("unRegOnNoPath", String.valueOf(unregisterOnNoPath)); else properties.put("unRegOnNoPath", "global"); if (noHandleVarSet) properties.put("unRegOnNoHandle", String.valueOf(unregisterOnNoHandle)); else properties.put("unRegOnNoHandle", "global"); } return properties;}/****************************************************************************///// Method: // run//// Description:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -