1 45 package org.exolab.jms.server; 46 47 import java.io.PrintStream ; 48 import javax.naming.NamingException ; 49 50 import org.apache.log4j.xml.DOMConfigurator; 51 52 import org.exolab.jms.authentication.AuthenticationMgr; 53 import org.exolab.jms.config.Configuration; 54 import org.exolab.jms.config.ConfigurationManager; 55 import org.exolab.jms.config.LoggerConfiguration; 56 import org.exolab.jms.events.BasicEventManager; 57 import org.exolab.jms.gc.GarbageCollectionService; 58 import org.exolab.jms.lease.LeaseManager; 59 import org.exolab.jms.messagemgr.DestinationManager; 60 import org.exolab.jms.messagemgr.MessageMgr; 61 import org.exolab.jms.persistence.DatabaseService; 62 import org.exolab.jms.scheduler.Scheduler; 63 import org.exolab.jms.service.ServiceException; 64 import org.exolab.jms.service.ServiceManager; 65 import org.exolab.jms.threads.ThreadPoolManager; 66 import org.exolab.jms.util.CommandLine; 67 import org.exolab.jms.util.Version; 68 69 70 80 public class JmsServer { 81 82 85 protected ServiceManager _services = null; 86 87 90 private Configuration _config; 91 92 93 99 public JmsServer(Configuration config) throws ServerException { 100 version(); 101 ConfigurationManager.setConfig(config); 102 } 103 104 111 public JmsServer(String file) throws ServerException { 112 version(); 113 114 try { 115 ConfigurationManager.setConfig(file); 117 _config = ConfigurationManager.getConfig(); 118 } catch (Exception exception) { 119 throw new FailedToCreateServerException( 120 "Failed to read configuration: " + file, exception); 121 } 122 } 123 124 130 public void init() throws NamingException , ServerException { 131 LoggerConfiguration log = _config.getLoggerConfiguration(); 133 134 DOMConfigurator.configure(log.getFile()); 137 138 _services = ServiceManager.instance(); 140 141 if (_config.getServerConfiguration().getEmbeddedJNDI()) { 143 EmbeddedNameService.getInstance(); 144 } 145 146 try { 148 registerServices(); 149 _services.startAll(); 150 } catch (ServiceException exception) { 151 throw new ServerException("Failed to start services", exception); 152 } 153 154 DestinationManager.instance() 156 .registerConfiguredAdministeredDestinations(); 157 158 try { 160 ConnectorService connectors = new ConnectorService(_config); 161 _services.add(connectors.getName(), connectors); 162 connectors.start(); 163 } catch (ServerException exception) { 164 throw exception; 165 } catch (ServiceException exception) { 166 throw new ServerException(exception.getMessage(), exception); 167 } 168 } 169 170 175 public static void main(String [] args) { 176 try { 177 CommandLine cmdline = new CommandLine(args); 178 179 boolean helpSet = cmdline.exists("help"); 180 boolean versionSet = cmdline.exists("version"); 181 boolean configSet = cmdline.exists("config"); 182 183 if (helpSet) { 184 usage(); 185 } else if (versionSet) { 186 version(); 187 } else if (!configSet && args.length != 0) { 188 usage(); 190 } else { 191 String config = cmdline.value("config", 192 getOpenJMSHome() 193 + "/config/openjms.xml"); 194 JmsServer server = new JmsServer(config); 195 server.init(); 196 } 197 } catch (Exception exception) { 198 exception.printStackTrace(); 199 System.exit(-1); 201 } 202 } 203 204 public static void version() { 205 System.err.println(Version.TITLE + " " + Version.VERSION); 206 System.err.println(Version.COPYRIGHT); 207 System.err.println(Version.VENDOR_URL); 208 } 209 210 213 protected static void usage() { 214 PrintStream out = System.out; 215 216 out.println("\n\n"); 217 out.println("====================================================="); 218 out.println("Usage information for org.exolab.jms.server.JmsServer"); 219 out.println("====================================================="); 220 out.println("\norg.exolab.jms.server.JmsServer"); 221 out.println(" [-config <xml config file> | -version | -help]\n"); 222 out.println("\t-config file name of xml-based config file\n"); 223 out.println("\t-version displays OpenJMS version information\n"); 224 out.println("\t-help displays this screen\n"); 225 } 226 227 230 protected void registerServices() throws ServiceException { 231 _services.add(ThreadPoolManager.instance().getName(), 233 ThreadPoolManager.instance()); 234 235 _services.add(BasicEventManager.instance().getName(), 237 BasicEventManager.instance()); 238 239 _services.add(DatabaseService.instance().getName(), 241 DatabaseService.instance()); 242 243 _services.add(Scheduler.createInstance().getName(), 245 Scheduler.instance()); 246 247 _services.add(LeaseManager.instance().getName(), 249 LeaseManager.instance()); 250 251 255 _services.add(GarbageCollectionService.instance().getName(), 257 GarbageCollectionService.instance()); 258 259 _services.add(AuthenticationMgr.createInstance().getName(), 261 AuthenticationMgr.instance()); 262 263 267 _services.add(MessageMgr.createInstance().getName(), 269 MessageMgr.instance()); 270 } 271 272 278 private static String getOpenJMSHome() { 279 return System.getProperty("openjms.home", 280 System.getProperty("user.dir")); 281 } 282 283 } 284 | Popular Tags |