📄 staxblockactionfactory.java
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2002, 2004 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/package com.ibm.staf.service.stax;import org.w3c.dom.Node;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.NodeList;import java.util.Iterator;import java.util.Map;import java.util.TreeMap;import java.util.HashMap;import java.util.List;import java.util.ArrayList;import com.ibm.staf.*;import com.ibm.staf.service.*;public class STAXBlockActionFactory implements STAXActionFactory, STAXListRequestHandler, STAXQueryRequestHandler, STAXGenericRequestHandler, STAXJobManagementHandler{ static final String STAX_BLOCK_EVENT = new String("Block"); static final String sBlockInfoMapClassName = new String( "STAF/Service/STAX/BlockInfo"); static final String sQueryBlockMapClassName = new String( "STAF/Service/STAX/QueryBlock"); // STAX Service Error Codes static final int BlockNotHeld = 4002; static final int BlockAlreadyHeld = 4003; private static String fDTDInfo ="\n" +"<!--================= The Block Element ============================ -->\n" +"<!--\n" +" Defines a task block that can be held, released, or terminated.\n" +" Used in conjunction with the hold/terminate/release elements to\n" +" define a task block that can be held, terminated, or released.\n" +" The name attribute value is evaluated via Python.\n" +"-->\n" +"<!ELEMENT block (%task;)>\n" +"<!ATTLIST block\n" +" name CDATA #REQUIRED\n" +">\n"; public STAXBlockActionFactory(STAX staxService) { staxService.registerListHandler("BLOCKS", this); staxService.registerQueryHandler("BLOCK", "Block Name", this); staxService.registerQueryJobHandler(this); staxService.registerJobManagementHandler(this); // Set up Hold, Release, Terminate Block Parser fHRTParser.addOption("HOLD", 1, STAFCommandParser.VALUENOTALLOWED); fHRTParser.addOption("RELEASE", 1, STAFCommandParser.VALUENOTALLOWED); fHRTParser.addOption("TERMINATE", 1,STAFCommandParser.VALUENOTALLOWED); fHRTParser.addOption("JOB", 1, STAFCommandParser.VALUEREQUIRED); fHRTParser.addOption("BLOCK", 1, STAFCommandParser.VALUEREQUIRED); fHRTParser.addOptionGroup("HOLD RELEASE TERMINATE", 1, 1); fHRTParser.addOptionNeed("HOLD RELEASE TERMINATE", "JOB"); // Register as a GenericRequestHandler try { // Assign STAFServiceInterfaceLevel class that this handler uses Class serviceInterfaceClass = Class.forName(STAX.INTERFACE_LEVEL_30); int rc = staxService.registerGenericRequestHandler(this, serviceInterfaceClass); if (rc != 0) { System.out.println("STAXBlockActionFactory." + "registerGenericRequestHandler() failed"); } } catch (ClassNotFoundException e) { System.out.println("STAXBlockActionFactory: " + "registerGenericRequestHandler: " + e); } // Construct map-class for block information fBlockInfoMapClass = new STAFMapClassDefinition(sBlockInfoMapClassName); fBlockInfoMapClass.addKey("blockName", "Block Name"); fBlockInfoMapClass.addKey("state", "State"); // Construct map-class for query block information fQueryBlockMapClass = new STAFMapClassDefinition(sQueryBlockMapClassName); fQueryBlockMapClass.addKey("blockName", "Block Name"); fQueryBlockMapClass.addKey("state", "State"); fQueryBlockMapClass.addKey("threadID", "Thread ID"); fQueryBlockMapClass.addKey("startTimestamp", "Start Date-Time"); } public void initJob(STAXJob job) { if (!job.setData("blockMap", new TreeMap())) { String msg = "STAXBlockActionFactory.initJob: setData for " + "blockMap failed."; job.log(STAXJob.JOB_LOG, "error", msg); } } public void terminateJob(STAXJob job) { /* Do Nothing */ } public STAFResult handleListRequest(String type, STAXJob job, STAXRequestSettings settings) { if (type.equalsIgnoreCase("blocks")) { // LIST JOB <Job ID> BLOCKS // Create the marshalling context and set its map class definitions // and create an empty list to contain the block map entries STAFMarshallingContext mc = new STAFMarshallingContext(); mc.setMapClassDefinition(fBlockInfoMapClass); List blockOutputList = new ArrayList(); // Iterate through the block map, generating the output list TreeMap blockMap = (TreeMap)job.getData("blockMap"); synchronized (blockMap) { Iterator iter = blockMap.values().iterator(); while (iter.hasNext()) { STAXBlockAction block = (STAXBlockAction)iter.next(); Map blockOutputMap = fBlockInfoMapClass.createInstance(); blockOutputMap.put("blockName", block.getName()); blockOutputMap.put("state", block.getBlockStateAsString()); blockOutputList.add(blockOutputMap); } } mc.setRootObject(blockOutputList); return new STAFResult(STAFResult.Ok, mc.marshall()); } else return new STAFResult(STAFResult.DoesNotExist, type); } public STAFResult handleQueryRequest(String type, String key, STAXJob job, STAXRequestSettings settings) { if (type.equalsIgnoreCase("block")) { // QUERY JOB <Job ID> BLOCK <Block name> // Create the marshalling context and set its map class definitions STAFMarshallingContext mc = new STAFMarshallingContext(); mc.setMapClassDefinition(fQueryBlockMapClass); TreeMap blockMap = (TreeMap)job.getData("blockMap"); synchronized (blockMap) { if (!blockMap.containsKey(key)) return new STAFResult(STAFResult.DoesNotExist, key); else { STAXBlockAction block = (STAXBlockAction)blockMap.get(key); Map blockOutputMap = fQueryBlockMapClass.createInstance(); blockOutputMap.put("blockName", block.getName()); blockOutputMap.put("state", block.getBlockStateAsString()); blockOutputMap.put("threadID", "" + block.getOwningThread(). getThreadNumber()); blockOutputMap.put("startTimestamp", block.getStartTimestamp(). getTimestampString()); mc.setRootObject(blockOutputMap); return new STAFResult(STAFResult.Ok, mc.marshall()); } } } else return new STAFResult(STAFResult.DoesNotExist, type); } public STAFResult handleQueryJobRequest(STAXJob job, STAXRequestSettings settings) { // Provide additional information for the QUERY JOB <Job ID> result int blocksRunningState = 0; int blocksHeldState = 0; int blocksUnknownState = 0; TreeMap blockMap = (TreeMap)job.getData("blockMap"); synchronized (blockMap) { Iterator iter = blockMap.values().iterator(); while (iter.hasNext()) { STAXBlockAction block = (STAXBlockAction)iter.next(); if (block.getBlockState() == STAXBlockAction.BLOCK_RUNNING)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -