1 package org.tanukisoftware.wrapper.test; 2 3 45 46 import org.tanukisoftware.wrapper.WrapperManager; 47 import org.tanukisoftware.wrapper.WrapperListener; 48 49 54 public class TestAction 55 extends AbstractActionApp 56 implements WrapperListener 57 { 58 private ActionRunner m_actionRunner; 59 60 63 private TestAction() { 64 } 65 66 69 public Integer start(String [] args) { 70 Thread actionThread; 71 72 System.out.println("start()"); 73 74 if (args.length <= 0) 75 printHelp("Missing action parameter."); 76 77 prepareSystemOutErr(); 78 79 m_actionRunner = new ActionRunner(args[0]); 81 actionThread = new Thread (m_actionRunner); 82 actionThread.start(); 83 84 return null; 85 } 86 87 public int stop(int exitCode) { 88 System.out.println("stop(" + exitCode + ")"); 89 90 if (isNestedExit()) 91 { 92 System.out.println("calling System.exit(" + exitCode + ") within stop."); 93 System.exit(exitCode); 94 } 95 96 return exitCode; 97 } 98 99 public void controlEvent(int event) { 100 System.out.println("controlEvent(" + event + ")"); 101 if (event == WrapperManager.WRAPPER_CTRL_C_EVENT) { 102 104 if (m_actionRunner != null) { 106 m_actionRunner.endThread(); 107 } 108 } 109 } 110 111 114 private class ActionRunner implements Runnable { 115 private String m_action; 116 private boolean m_alive; 117 118 public ActionRunner(String action) { 119 m_action = action; 120 m_alive = true; 121 } 122 123 public void run() { 124 try { 126 Thread.sleep(5000); 127 } catch (InterruptedException e) {} 128 129 if (!TestAction.this.doAction(m_action)) { 130 printHelp("\"" + m_action + "\" is an unknown action."); 131 WrapperManager.stop(0); 132 return; 133 } 134 135 while (m_alive) { 136 try { 138 Thread.sleep(500); 139 } catch (Exception e) { 140 e.printStackTrace(); 141 } 142 } 143 } 144 145 public void endThread( ) { 146 m_alive = false; 147 } 148 } 149 150 155 private static void printHelp(String error_msg) { 156 System.err.println( "USAGE" ); 157 System.err.println( "" ); 158 System.err.println( "TestAction <action>" ); 159 System.err.println( "" ); 160 System.err.println( "[ACTIONS]" ); 161 System.err.println( " Actions which should cause the Wrapper to exit cleanly:" ); 162 System.err.println( " stop0 : Calls WrapperManager.stop(0)" ); 163 System.err.println( " exit0 : Calls System.exit(0)" ); 164 System.err.println( " stopimmediate0 : Calls WrapperManager.stopImmediate(0)" ); 165 System.err.println( " stopandreturn0 : Calls WrapperManager.stopAndReturn(0)" ); 166 System.err.println( " Actions which should cause the Wrapper to exit in an error state:" ); 167 System.err.println( " stop1 : Calls WrapperManager.stop(1)" ); 168 System.err.println( " exit1 : Calls System.exit(1)" ); 169 System.err.println( " nestedexit1 : Calls System.exit(1) within WrapperListener.stop(1) callback" ); 170 System.err.println( " stopimmediate1 : Calls WrapperManager.stopImmediate(1)" ); 171 System.err.println( " Actions which should cause the Wrapper to restart the JVM:" ); 172 System.err.println( " access_violation : Calls WrapperManager.accessViolation" ); 173 System.err.println( " access_violation_native : Calls WrapperManager.accessViolationNative()" ); 174 System.err.println( " appear_hung : Calls WrapperManager.appearHung()" ); 175 System.err.println( " halt0 : Calls Runtime.getRuntime().halt(0)" ); 176 System.err.println( " halt1 : Calls Runtime.getRuntime().halt(1)" ); 177 System.err.println( " restart : Calls WrapperManager.restart()" ); 178 System.err.println( " restartandreturn : Calls WrapperManager.restartAndReturn()" ); 179 System.err.println( " Additional Tests:" ); 180 System.err.println( " dump : Calls WrapperManager.requestThreadDump()" ); 181 System.err.println( " deadlock_out : Deadlocks the JVM's System.out and err streams." ); 182 System.err.println( " users : Start polling the current and interactive users." ); 183 System.err.println( " groups : Start polling the current and interactive users with groups." ); 184 System.err.println( " console : Prompt for actions in the console." ); 185 System.err.println( " idle : Do nothing just run in idle mode." ); 186 System.err.println( " properties : Dump all System Properties to the console." ); 187 System.err.println( " configuration : Dump all Wrapper Configuration Properties to the console." ); 188 System.err.println( "" ); 189 System.err.println( "[EXAMPLE]" ); 190 System.err.println( " TestAction access_violation_native " ); 191 System.err.println( "" ); 192 System.err.println( "ERROR: " + error_msg ); 193 System.err.println( "" ); 194 195 System.exit( -1 ); 196 } 197 198 201 public static void main(String [] args) { 202 System.out.println("Initializing..."); 203 204 WrapperManager.start(new TestAction(), args); 209 } 210 } 211 212 | Popular Tags |