public void register(ContainerConfiguration configuration) throws JMSException { URI uri = configuration.getUri(); if (containers.containsKey(uri)) { throw new JMSException("Container already registered: " + uri); } ConnectionFactory factory = configuration.getFactory(); TransactionType type = configuration.getType(); String clientId = configuration.getClientId(); boolean durable = configuration.isDurable(); int cacheLevel = configuration.getCacheLevel(); boolean cacheConnection = cacheLevel >= CACHE_CONNECTION; // set the receive timeout to half of the trx timeout int receiveTimeout = transactionTimeout / 2; ContainerStatistics statistics = new ContainerStatistics(); ConnectionManager connectionManager = new ConnectionManager(factory, uri, clientId, cacheConnection, durable, containerMonitor); UnitOfWork transactionHelper = new UnitOfWork(uri, type, transactionTimeout, tm, statistics); AdaptiveMessageContainer container = new AdaptiveMessageContainer( configuration, receiveTimeout, connectionManager, transactionHelper, statistics, executorService, containerMonitor); containers.put(uri, container); try { String encodedName = encodeName(uri); String encodedGroup = encodeGroup(uri); managementService.export(encodedName, encodedGroup, "JMS message container", container); } catch (ManagementException e) { throw new JMSException(e.getMessage()); } if (started) { container.initialize(); managerMonitor.registerListener(uri); } }
private void construct(ContainerConfiguration c) throws PlexusContainerException { if (c.getParentContainer() != null) { this.parentContainer = c.getParentContainer(); this.loggerManager = parentContainer.getLoggerManager(); this.containerRealm = getChildRealm(getName(), name, c.getParentContainer().getContainerRealm()); } this.name = c.getName(); // ---------------------------------------------------------------------------- // ClassWorld // ---------------------------------------------------------------------------- this.classWorld = c.getClassWorld(); // Make sure we have a valid ClassWorld if (this.classWorld == null) { this.classWorld = new ClassWorld(DEFAULT_REALM_NAME, Thread.currentThread().getContextClassLoader()); } containerRealm = c.getRealm(); if (containerRealm == null) { try { containerRealm = this.classWorld.getRealm(DEFAULT_REALM_NAME); } catch (NoSuchRealmException e) { List realms = new LinkedList(this.classWorld.getRealms()); containerRealm = (ClassRealm) realms.get(0); if (containerRealm == null) { System.err.println("No container realm! Expect errors."); new Throwable().printStackTrace(); } } } setLookupRealm(containerRealm); // ---------------------------------------------------------------------------- // Context // ---------------------------------------------------------------------------- this.containerContext = new DefaultContext(); if (c.getContext() != null) { for (Iterator it = c.getContext().entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); addContextValue(entry.getKey(), entry.getValue()); } } // ---------------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------------- // TODO: just store reference to the configuration in a String and use that in the configuration // initialization InputStream in = null; if (c.getContainerConfiguration() != null) { in = toStream(c.getContainerConfiguration()); } try { if (c.getContainerConfigurationURL() != null) { in = c.getContainerConfigurationURL().openStream(); } } catch (IOException e) { throw new PlexusContainerException("Error reading configuration URL", e); } try { this.configurationReader = in == null ? null : ReaderFactory.newXmlReader(in); } catch (IOException e) { throw new PlexusContainerException("Error reading configuration file", e); } try { // XXX this will set up the configuration and process it initialize(); // XXX this will wipe out the configuration field - is this needed? If so, // why? can we remove the need to have a configuration field then? start(); } finally { IOUtil.close(this.configurationReader); } }