1 8 package org.apache.avalon.phoenix.launcher; 9 10 import com.silveregg.wrapper.WrapperListener; 11 import com.silveregg.wrapper.WrapperManager; 12 import java.util.Hashtable ; 13 import java.util.Observable ; 14 import java.util.Observer ; 15 16 23 public class DaemonLauncher 24 implements WrapperListener, Observer 25 { 26 33 private boolean m_ignoreUpdates = false; 34 35 public Integer start( final String [] args ) 36 { 37 Integer exitCodeInteger = null; 38 39 WrapperManager.signalStarting( 45000 ); 41 42 final Hashtable data = new Hashtable (); 43 data.put( Observer .class.getName(), this ); 44 45 if( WrapperManager.isDebugEnabled() ) 46 { 47 System.out.println( "DaemonLauncher: Starting up Phoenix" ); 48 } 49 50 try 51 { 52 int exitCode = Main.startup( args, data, false ); 53 if( exitCode != 0 ) 54 { 55 exitCodeInteger = new Integer ( exitCode ); 56 } 57 58 if( WrapperManager.isDebugEnabled() ) 59 { 60 System.out.println( "DaemonLauncher: Phoenix startup completed" ); 61 } 62 } 63 catch( final Exception e ) 64 { 65 e.printStackTrace(); 66 exitCodeInteger = new Integer ( 1 ); 67 } 68 69 WrapperManager.signalStarting( 2000 ); 71 72 return exitCodeInteger; 73 } 74 75 public int stop( final int exitCode ) 76 { 77 m_ignoreUpdates = true; 79 80 Main.shutdown(); 81 return exitCode; 82 } 83 84 public void controlEvent( final int event ) 85 { 86 if( WrapperManager.isControlledByNativeWrapper() ) 87 { 88 if( WrapperManager.isDebugEnabled() ) 89 { 90 System.out.println( "DaemonLauncher: controlEvent(" + event + ") - Ignored." ); 91 } 92 93 } 96 else 97 { 98 if( WrapperManager.isDebugEnabled() ) 99 { 100 System.out.println( "DaemonLauncher: controlEvent(" + event + ") - Stopping." ); 101 } 102 103 WrapperManager.stop( 0 ); 106 } 108 } 109 110 116 public void update( final Observable observable, final Object arg ) 117 { 118 if( m_ignoreUpdates ) 119 { 120 if( WrapperManager.isDebugEnabled() ) 122 { 123 System.out.println( "DaemonLauncher: " + arg 124 + " request ignored because stop already called." ); 125 System.out.flush(); 126 } 127 } 128 else 129 { 130 final String command = (null != arg) ? arg.toString() : ""; 131 if( command.equals( "restart" ) ) 132 { 133 if( WrapperManager.isDebugEnabled() ) 134 { 135 System.out.println( "DaemonLauncher: restart requested." ); 136 System.out.flush(); 137 } 138 139 WrapperManager.restart(); 140 141 if( WrapperManager.isDebugEnabled() ) 142 { 143 System.out.println( "DaemonLauncher: restart completed." ); 145 System.out.flush(); 146 } 147 } 148 else if( command.equals( "shutdown" ) ) 149 { 150 if( WrapperManager.isDebugEnabled() ) 151 { 152 System.out.println( "DaemonLauncher: shutdown requested." ); 153 System.out.flush(); 154 } 155 156 WrapperManager.stop( 0 ); 157 158 if( WrapperManager.isDebugEnabled() ) 159 { 160 System.out.println( "DaemonLauncher: shutdown completed." ); 162 System.out.flush(); 163 } 164 } 165 else 166 { 167 throw new IllegalArgumentException ( "Unknown action " + command ); 168 } 169 } 170 } 171 172 public static void main( final String [] args ) 173 { 174 WrapperManager.start( new DaemonLauncher(), args ); 175 } 176 } 177 | Popular Tags |