1 /*****************************************************************************/ 2 /* Software Testing Automation Framework (STAF) */ 3 /* (C) Copyright IBM Corp. 2002 */ 4 /* */ 5 /* This software is licensed under the Eclipse Public License (EPL) V1.0. */ 6 /*****************************************************************************/ 7 8 package com.ibm.staf.service.stax; 9 import com.ibm.staf.*; 10 import java.util.*; 11 12 public class TestProcess implements Runnable 13 { 14 private STAFHandle handle = null; 15 private int counter; 16 private int loopCounter; 17 private int incrementSeconds; 18 private int returnCode; 19 main(String[] args)20 public static void main(String[] args) 21 { 22 if (args.length < 3) 23 { 24 System.out.println("Usage: java TestProcess loopCount" + 25 " incrementSeconds returnCode"); 26 System.exit(1); 27 } 28 29 try 30 { 31 int loopCounter = (new Integer(args[0])).intValue(); 32 int incrementSeconds = (new Integer(args[1])).intValue(); 33 int returnCode = (new Integer(args[2])).intValue(); 34 TestProcess testProcess = new TestProcess(loopCounter, 35 incrementSeconds, 36 returnCode); 37 } 38 catch(Exception e) 39 { 40 e.printStackTrace(); 41 } 42 } 43 TestProcess(int loopCounter, int incrementSeconds, int returnCode)44 public TestProcess(int loopCounter, int incrementSeconds, 45 int returnCode) 46 { 47 this.loopCounter = loopCounter; 48 this.incrementSeconds = incrementSeconds; 49 this.returnCode = returnCode; 50 this.run(); 51 } 52 run()53 public void run() 54 { 55 try 56 { 57 // register with STAF 58 handle = new STAFHandle("TestProcess"); 59 } 60 catch(STAFException e) 61 { 62 System.out.println("Error registering with STAF"); 63 terminate(); 64 } 65 66 for (int i=0; i < loopCounter; i++) 67 { 68 STAFResult result = handle.submit2("local", "monitor", 69 "log message " + 70 STAFUtil.wrapData("Loop #" 71 + String.valueOf(i))); 72 73 // System.out.println("Loop #" + String.valueOf(i)); 74 75 try 76 { 77 Thread.sleep(incrementSeconds * 1000); 78 } 79 catch(InterruptedException e) 80 { 81 e.printStackTrace(); 82 } 83 } 84 85 terminate(); 86 } 87 terminate()88 public void terminate() 89 { 90 try 91 { 92 if (handle != null) 93 { 94 handle.submit2("local", "monitor", "log message " + 95 STAFUtil.wrapData("Terminating ")); 96 97 // unregister 98 handle.unRegister(); 99 } 100 } 101 catch(STAFException e) 102 { 103 /* do nothing */ 104 } 105 finally 106 { 107 System.exit(returnCode); 108 } 109 } 110 }