MBeanConfigurationElement shutdownLoggerConfig = (MBeanConfigurationElement)pdd.query("service", "ShutdownLogger").iterator().next(); shutdownLoggerObjectName = sc.registerAndConfigureService(shutdownLoggerConfig); sc.invoke(shutdownLoggerObjectName, "create", new Object[0], new String[0]); sc.invoke(shutdownLoggerObjectName, "start", new Object[0], new String[0]);
   public void startServerPeer(String serverPeerID,                               String defaultQueueJNDIContext,                               String defaultTopicJNDIContext) throws Exception   {      try      {         log.debug("creating ServerPeer instance");            // we are using the "default" service deployment descriptors available in         // src/etc/server/default/deploy. This will allow to test the default parameters we ship.            String mainConfigFile = "server/default/deploy/messaging-service.xml";         URL mainConfigFileURL = getClass().getClassLoader().getResource(mainConfigFile);         if (mainConfigFileURL == null)         {            throw new Exception("Cannot find " + mainConfigFile + " in the classpath");         }            String databaseType = sc.getDatabaseType();         String persistenceConfigFile =            "server/default/deploy/" + databaseType + "-persistence-service.xml";                  log.info("********* LOADING CONFIG FILE: " + persistenceConfigFile);                  URL persistenceConfigFileURL = getClass().getClassLoader().getResource(persistenceConfigFile);         if (persistenceConfigFileURL == null)         {            throw new Exception("Cannot find " + persistenceConfigFile + " in the classpath");         }            String connFactoryConfigFile = "server/default/deploy/connection-factories-service.xml";         URL connFactoryConfigFileURL = getClass().getClassLoader().getResource(connFactoryConfigFile);         if (connFactoryConfigFileURL == null)         {            throw new Exception("Cannot find " + connFactoryConfigFile + " in the classpath");         }            ServiceDeploymentDescriptor mdd = new ServiceDeploymentDescriptor(mainConfigFileURL);         ServiceDeploymentDescriptor pdd = new ServiceDeploymentDescriptor(persistenceConfigFileURL);         ServiceDeploymentDescriptor cfdd = new ServiceDeploymentDescriptor(connFactoryConfigFileURL);            MBeanConfigurationElement persistenceManagerConfig =            (MBeanConfigurationElement)pdd.query("service", "PersistenceManager").iterator().next();         persistenceManagerObjectName = sc.registerAndConfigureService(persistenceManagerConfig);         sc.invoke(persistenceManagerObjectName, "create", new Object[0], new String[0]);         sc.invoke(persistenceManagerObjectName, "start", new Object[0], new String[0]);                           MBeanConfigurationElement jmsUserManagerConfig =            (MBeanConfigurationElement)pdd.query("service", "JMSUserManager").iterator().next();         jmsUserManagerObjectName = sc.registerAndConfigureService(jmsUserManagerConfig);         sc.invoke(jmsUserManagerObjectName, "create", new Object[0], new String[0]);         sc.invoke(jmsUserManagerObjectName, "start", new Object[0], new String[0]);                    MBeanConfigurationElement shutdownLoggerConfig =            (MBeanConfigurationElement)pdd.query("service", "ShutdownLogger").iterator().next();         shutdownLoggerObjectName = sc.registerAndConfigureService(shutdownLoggerConfig);         sc.invoke(shutdownLoggerObjectName, "create", new Object[0], new String[0]);         sc.invoke(shutdownLoggerObjectName, "start", new Object[0], new String[0]);             // register server peer as a service, dependencies are injected automatically         MBeanConfigurationElement serverPeerConfig =            (MBeanConfigurationElement)mdd.query("service", "ServerPeer").iterator().next();            // overwrite the file configuration, if needed         if (serverPeerID != null)         {            serverPeerConfig.setConstructorArgumentValue(0, 0, serverPeerID);         }         if (defaultQueueJNDIContext != null)         {            serverPeerConfig.setConstructorArgumentValue(0, 1, defaultQueueJNDIContext);         }         if (defaultTopicJNDIContext != null)         {            serverPeerConfig.setConstructorArgumentValue(0, 2, defaultTopicJNDIContext);         }            serverPeerObjectName = sc.registerAndConfigureService(serverPeerConfig);            // overwrite the config file security domain         sc.setAttribute(serverPeerObjectName, "SecurityDomain",                         MockJBossSecurityManager.TEST_SECURITY_DOMAIN);            log.debug("starting JMS server");            sc.invoke(serverPeerObjectName, "create", new Object[0], new String[0]);         sc.invoke(serverPeerObjectName, "start", new Object[0], new String[0]);                  log.info("deploying post offices");                  MBeanConfigurationElement queuePostOfficeConfig =            (MBeanConfigurationElement)pdd.query("service", "QueuePostOffice").iterator().next();         queuePostOfficeObjectName = sc.registerAndConfigureService(queuePostOfficeConfig);         sc.invoke(queuePostOfficeObjectName, "create", new Object[0], new String[0]);         sc.invoke(queuePostOfficeObjectName, "start", new Object[0], new String[0]);                  MBeanConfigurationElement topicPostOfficeConfig =            (MBeanConfigurationElement)pdd.query("service", "TopicPostOffice").iterator().next();         topicPostOfficeObjectName = sc.registerAndConfigureService(topicPostOfficeConfig);         sc.invoke(topicPostOfficeObjectName, "create", new Object[0], new String[0]);         sc.invoke(topicPostOfficeObjectName, "start", new Object[0], new String[0]);                  log.info("Deployed postoffices");             log.debug("deploying connection factories");            List connFactoryElements = cfdd.query("service", "ConnectionFactory");         connFactoryObjectNames.clear();         for(Iterator i = connFactoryElements.iterator(); i.hasNext(); )         {            MBeanConfigurationElement connFactoryElement = (MBeanConfigurationElement)i.next();            ObjectName on = sc.registerAndConfigureService(connFactoryElement);            // dependencies have been automatically injected already            sc.invoke(on, "create", new Object[0], new String[0]);            sc.invoke(on, "start", new Object[0], new String[0]);            connFactoryObjectNames.add(on);         }            // bind the default JMS provider         sc.bindDefaultJMSProvider();         // bind the JCA ConnectionFactory         sc.bindJCAJMSConnectionFactory();      }      catch (Exception e)      {         log.error("Failed to start server peer", e);         throw e;      }   }