1 package org.apache.fulcrum.yaafi.cli; 2 3 19 20 import org.apache.avalon.framework.logger.ConsoleLogger; 21 import org.apache.avalon.framework.logger.Logger; 22 import org.apache.fulcrum.yaafi.framework.container.ServiceConstants; 23 import org.apache.fulcrum.yaafi.framework.container.ServiceContainer; 24 import org.apache.fulcrum.yaafi.framework.container.ServiceContainerImpl; 25 import org.apache.fulcrum.yaafi.framework.factory.ServiceManagerFactory; 26 27 28 33 34 public class Main 35 { 36 37 private ServiceContainer manager; 38 39 40 private String componentRoleValue; 41 42 43 private String componentConfigValue; 44 45 46 private String componentParametersValue; 47 48 49 private Thread shutdownThread; 50 51 52 private boolean isServerMode; 53 54 55 private Logger logger; 56 57 60 private Main() 61 { 62 this.isServerMode = false; 63 this.componentRoleValue = ServiceConstants.COMPONENT_ROLE_VALUE; 64 this.componentConfigValue = ServiceConstants.COMPONENT_CONFIG_VALUE; 65 this.componentParametersValue = ServiceConstants.COMPONENT_PARAMETERS_VALUE; 66 67 this.logger = new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG ); 68 } 69 70 75 public static void main( String [] args ) throws Exception 76 { 77 Main impl = new Main(); 78 79 81 impl.initialize(); 82 83 boolean terminateNow = ( impl.isServerMode ? false : true ); 84 85 while( terminateNow == false ) 86 { 87 try 88 { 89 Thread.currentThread().sleep(1000); 90 } 91 catch (InterruptedException e) 92 { 93 terminateNow = true; 94 } 95 } 96 97 impl.dispose(); 98 } 99 100 protected void initialize() throws Exception 101 { 102 104 this.manager = ServiceManagerFactory.create( 105 new ConsoleLogger(), 106 this.componentRoleValue, 107 this.componentConfigValue, 108 this.componentParametersValue 109 ); 110 111 113 Shutdown shutdown = new Shutdown ( this.getManager(), this.getLogger() ); 114 this.shutdownThread = new Thread (shutdown); 115 Runtime.getRuntime().addShutdownHook(shutdownThread); 116 } 117 118 protected synchronized void dispose() throws Exception 119 { 120 if( this.getManager() != null ) 121 { 122 this.getManager().dispose(); 123 } 124 } 125 126 129 protected Logger getLogger() 130 { 131 return logger; 132 } 133 134 138 141 public ServiceContainer getManager() 142 { 143 return manager; 144 } 145 148 public void setManager(ServiceContainerImpl manager) 149 { 150 this.manager = manager; 151 } 152 155 public String getComponentConfigValue() 156 { 157 return this.componentConfigValue; 158 } 159 162 public void setComponentConfigValue(String componentConfigValue) 163 { 164 this.componentConfigValue = componentConfigValue; 165 } 166 169 public String getComponentRoleValue() 170 { 171 return this.componentRoleValue; 172 } 173 176 public void setComponentRoleValue(String componentRoleValue) 177 { 178 this.componentRoleValue = componentRoleValue; 179 } 180 } 181 | Popular Tags |