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

📄 staxjob.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002, 2004, 2005                                  *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf.service.stax;import com.ibm.staf.*;import com.ibm.staf.wrapper.STAFLog;import java.util.Map;import java.util.HashMap;import java.util.TreeMap;import java.util.TreeSet;import java.util.LinkedList;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.io.File;import org.python.core.Py;import org.python.core.PyObject;import org.python.core.PyCode;import org.python.core.__builtin__;/** * The representation of a STAX job.  A STAX job is created by the STAXParser * when the STAX service receives an EXECUTE request specifying a file or string * containing XML that defines a STAX job. */public class STAXJob implements STAXThreadCompleteListener,                                STAXSTAFQueueListener{    // For debugging - Counts and prints the number of cache gets/adds    static final boolean COUNT_PYCODE_CACHES = false;    static final String STAX_JOB_EVENT = new String("Job");    // Logfile types:    static final int SERVICE_LOG = 1;    /**     * Indicates to log to the STAX Job Log file     */    public static final int JOB_LOG = 2;    /**     * Indicates to log to the STAX Job User Log file     */    public static final int USER_JOB_LOG = 3;    public static final int NO_NOTIFY_ONEND = 0;    public static final int NOTIFY_ONEND_BY_HANDLE = 1;    public static final int NOTIFY_ONEND_BY_NAME = 2;    /**       * Creates a new STAXJob instance passing in a STAX object which      * represents the STAX service that is executing this job.      */    public STAXJob(STAX staxService)    {        fSTAX = staxService;        STAXThread thread = new STAXThread(this);        thread.addCompletionNotifiee(this);        fThreadMap.put(new Integer(thread.getThreadNumber()), thread);        fClearlogs = fSTAX.getClearlogs();        fLogTCElapsedTime = fSTAX.getLogTCElapsedTime();        fLogTCNumStarts   = fSTAX.getLogTCNumStarts();        fLogTCStartStop   = fSTAX.getLogTCStartStop();    }    /**     * Gets the STAX object which represents the job's STAX service     * @return an instance of the job's STAX service     */    public STAX getSTAX() { return fSTAX; }    /**     * Gets the next number for a thread in a job     * @return a number for the next thread in a job     */    public int getNextThreadNumber()    {        synchronized (fNextThreadNumberSynch)        {            return fNextThreadNumber++;        }    }    /**     * Gets the name of the function that should be called to start the     * execution of a job     * @return the name of the starting function for a job     */    public String getStartFunction() { return fStartFunction; }    /**     * Sets the name of the function that should be called to start the     * execution of a job     * @param  startFunction   the name of the starting function for a job     */    public void setStartFunction(String startFunction)    { fStartFunction = startFunction; }    public String getStartFuncArgs() { return fStartFuncArgs; }    public void setStartFuncArgs(String startFuncArgs)    { fStartFuncArgs = startFuncArgs; }    public void setExecuteAndHold()    { fExecuteAndHold = true; }    public String getJobName() { return fJobName; }    public void setJobName(String jobName) { fJobName = jobName; }    public int getJobNumber() { return fJobNumber; }    public void setJobNumber(int jobNumber) { fJobNumber = jobNumber; }        public int getNextProcNumber()    {        synchronized (fNextProcNumberSynch)        {             return fProcNumber++;        }    }        public int getNextCmdNumber()    {        synchronized (fNextCmdNumberSynch)        {            return fCmdNumber++;        }    }        public int getNextProcessKey()    {        synchronized (fNextProcessKeySynch)        {            return fProcessKey++;        }    }    public String getJobDataDir() { return fJobDataDir; }        public String getXmlMachine() { return fXmlMachine; }    public void setXmlMachine(String machName)     { fXmlMachine = machName; }    public String getXmlFile() { return fXmlFile; }    public void setXmlFile(String fileName) { fXmlFile = fileName; }    public List getScripts() { return fScripts; }    public void setScript(String script) { fScripts.add(script); }    public List getScriptFiles() { return fScriptFiles; }    public void setScriptFile(String fileName) { fScriptFiles.add(fileName); }        public String getScriptFileMachine() { return fScriptFileMachine; }    public void setScriptFileMachine(String machName)     { fScriptFileMachine = machName; }    public String getSourceMachine() { return fSourceMachine; }    public void setSourceMachine(String machName)     { fSourceMachine = machName; }    public String getSourceHandleName() { return fSourceHandleName; }    public void setSourceHandleName(String handleName)     { fSourceHandleName = handleName; }    public int getSourceHandle() { return fSourceHandle; }    public void setSourceHandle(int handle)     { fSourceHandle = handle; }    public boolean getClearlogs() { return fClearlogs; }    public String getClearLogsAsString()    {        if (fClearlogs)            return "Enabled";        else            return "Disabled";    }    public void setClearlogs(boolean clearlogs)     { fClearlogs = clearlogs; }    public int getNotifyOnEnd() { return fNotifyOnEnd; }    public String getNotifyOnEndAsString()    {        if (fNotifyOnEnd == STAXJob.NOTIFY_ONEND_BY_NAME)            return "By Name";        else if (fNotifyOnEnd == STAXJob.NOTIFY_ONEND_BY_HANDLE)            return "By Handle";        else             return "No";    }    public void setNotifyOnEnd(int notifyFlag) { fNotifyOnEnd = notifyFlag; }        public PyObject getResult() { return fResult; }    public void setResult(PyObject result)     { fResult = result; }    public STAXTimestamp getStartTimestamp() { return fStartTimestamp; }        public STAXTimestamp getEndTimestamp() { return fEndTimestamp; }        public Integer getJobNumberAsInteger() { return new Integer(fJobNumber); }    public STAFHandle getSTAFHandle() { return fHandle; }    public boolean getLogTCElapsedTime() { return fLogTCElapsedTime; }    public String getLogTCElapsedTimeAsString()    {        if (fLogTCElapsedTime)            return "Enabled";        else            return "Disabled";    }    public void setLogTCElapsedTime(boolean logTCElapsedTime)    { fLogTCElapsedTime = logTCElapsedTime; }    public boolean getLogTCNumStarts() { return fLogTCNumStarts; }    public String getLogTCNumStartsAsString()    {        if (fLogTCNumStarts)            return "Enabled";        else            return "Disabled";    }    public void setLogTCNumStarts(boolean logTCNumStarts)    { fLogTCNumStarts = logTCNumStarts; }    public boolean getLogTCStartStop() { return fLogTCStartStop; }        public String getLogTCStartStopAsString()    {        if (fLogTCStartStop)            return "Enabled";        else            return "Disabled";    }    public void setLogTCStartStop(boolean logTCStartStop)    { fLogTCStartStop = logTCStartStop; }    public STAXThread getMainThread()    {        synchronized (fThreadMap)        {            return (STAXThread)fThreadMap.get(new Integer(1));        }    }    public void addFunction(STAXFunctionAction function)    {        synchronized(this)        {                if (fFunctionMap.containsKey(function.getName()))            {                /* XXX: Do something */            }            fFunctionMap.put(function.getName(), function);        }    }    public STAXAction getFunction(String name)    {        synchronized(this)        {            return (STAXAction)fFunctionMap.get(name);        }    }        public HashMap getFunctionMap()    {        synchronized(this)        {            return fFunctionMap;        }    }    public boolean functionExists(String name)    {        synchronized(this)        {            return fFunctionMap.containsKey(name);        }    }    public void addDefaultAction(STAXAction action)    {        fDefaultActions.addFirst(action);    }    public void addCompletionNotifiee(STAXJobCompleteListener listener)    {        synchronized (fCompletionNotifiees)        {            fCompletionNotifiees.addLast(listener);        }    }    public STAFResult addCompletionNotifiee2(STAXJobCompleteNotifiee notifiee)    {        synchronized (fCompletionNotifiees)        {            // Check if the notifiee is already in the list            Iterator iter = fCompletionNotifiees.iterator();            while (iter.hasNext())            {                Object notifieeObj = iter.next();                if (notifieeObj instanceof                    com.ibm.staf.service.stax.STAXJobCompleteNotifiee)                {                    STAXJobCompleteNotifiee aNotifiee =                        (STAXJobCompleteNotifiee)notifieeObj;                    if (aNotifiee.getMachine().equals(notifiee.getMachine()) &&                        aNotifiee.getHandle() == notifiee.getHandle() &&                        aNotifiee.getHandleName().equals(notifiee.getHandleName()))                    {                        return new STAFResult(                            STAFResult.AlreadyExists,                            "A notifiee is already registered for machine=" +                            notifiee.getMachine() +                            ", handle=" + notifiee.getHandle() +                            ", handleName=" + notifiee.getHandleName());                    }                }            }            // Add to the end of the list            fCompletionNotifiees.addLast(notifiee);        }        return new STAFResult(STAFResult.Ok, "");    }    public STAFResult removeCompletionNotifiee(STAXJobCompleteNotifiee notifiee)    {        boolean found = false;        synchronized (fCompletionNotifiees)        {            // Check if notifiee exists.  If so, remove the notifiee            Iterator iter = fCompletionNotifiees.iterator();            while (iter.hasNext())            {                Object notifieeObj = iter.next();                if (notifieeObj instanceof                    com.ibm.staf.service.stax.STAXJobCompleteNotifiee)                {                    STAXJobCompleteNotifiee aNotifiee =                        (STAXJobCompleteNotifiee)notifieeObj;                                    if (aNotifiee.getMachine().equals(notifiee.getMachine()) &&                        aNotifiee.getHandle() == notifiee.getHandle() &&                        aNotifiee.getHandleName().equals(notifiee.getHandleName()))                    {                        // Remove notifiee from list                        fCompletionNotifiees.remove(aNotifiee);                        found = true;                        return new STAFResult(STAFResult.Ok, "");                    }                }            }        }                        return new STAFResult(            STAFResult.DoesNotExist,            "No notifiee registered for machine=" + notifiee.getMachine() +            ", handle=" + notifiee.getHandle() +            ", handleName=" + notifiee.getHandleName());    }    public LinkedList getCompletionNotifiees()    {        synchronized(fCompletionNotifiees)        {            return new LinkedList(fCompletionNotifiees);        }    }    // The combination of __builtin__.compile and the exec version, which    // takes a code object, is used so that if Jython code is executed    // more than once, the compiled code is cached, eliminating the need    // to recompile the string each time it is executed.    //    // Input Arguments:    //  - codeString:  must be valid Python code; however, like ordinary    //                 Python code, the existence of variables will not be    //                 checked until the code is executed.    //  - kind:        is either 'exec' if the string is made up of    //                 statements, 'eval' if it is an expression.    public PyCode getCompiledPyCode(String codeString, String kind)    {        synchronized(fCompiledPyCodeCache)        {            PyCode codeObject = (PyCode)fCompiledPyCodeCache.get(codeString);            if (codeObject == null)            {                if (COUNT_PYCODE_CACHES) fCompiledPyCodeCacheAdds++;                // XXX: Would prefer to do a "eval" instead of "exec" so that                // could remove assignment to STAXPyEvalResult, but I don't                // know how to evaluate a PyCode object in STAXThread.pyCompile()                // via a Python Interpreter as it's eval method only accepts a                // string, not a PyCode object.                if (kind.equals("eval"))                {                    // Set to avoid error of setting STAXPyEvalResult to nothing                    if (codeString.equals("")) codeString = "None";                                    codeObject = __builtin__.compile(                        "STAXPyEvalResult = " + codeString, "<pyEval string>",                        "exec");                }

⌨️ 快捷键说明

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