Could you say some more about this change, I'm not sure I understand it and its conflicting with some local changes i have and i don't want to break what you're trying to do when i fix that.
...ant On Feb 14, 2008 1:32 AM, <[EMAIL PROTECTED]> wrote: > Author: rfeng > Date: Wed Feb 13 17:32:08 2008 > New Revision: 627631 > > URL: http://svn.apache.org/viewvc?rev=627631&view=rev > Log: > Add the on-demand ActiveMQ broker start/stop with detection/sharing of > running brokers (toward the geronimo deployment) > > Modified: > incubator/tuscany/java/sca/itest/jms/pom.xml > > > incubator/tuscany/java/sca/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java > > > incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java > > > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java > > > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java > > > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQBroker.java > > > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java > > > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java > > > incubator/tuscany/java/sca/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSResourceFactory.java > > > incubator/tuscany/java/sca/samples/helloworld-reference-jms/src/test/java/helloworld/HelloWorldJmsClientTestCase.java > > > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/main/java/helloworld/HelloWorldServer.java > > > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCaseOff.java > > Modified: incubator/tuscany/java/sca/itest/jms/pom.xml > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/jms/pom.xml?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- incubator/tuscany/java/sca/itest/jms/pom.xml (original) > +++ incubator/tuscany/java/sca/itest/jms/pom.xml Wed Feb 13 17:32:08 2008 > @@ -47,7 +47,7 @@ > <groupId>org.apache.tuscany.sca</groupId> > <artifactId>tuscany-host-embedded</artifactId> > <version>1.2-incubating-SNAPSHOT</version> > - <scope>test</scope> > + <scope>runtime</scope> > </dependency> > > <dependency> > > Modified: > incubator/tuscany/java/sca/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java > (original) > +++ > incubator/tuscany/java/sca/itest/jms/src/test/java/org/apache/tuscany/sca/binding/jms/ExternalBrokerTestCase.java > Wed Feb 13 17:32:08 2008 > @@ -36,7 +36,7 @@ > > @Before > public void init() throws Exception { > - startBroker(); > + // startBroker(); > scaDomain = SCADomain.newInstance("http://localhost", "/", > "external/client.composite", "external/service.composite"); > } > > > Modified: > incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java > (original) > +++ > incubator/tuscany/java/sca/modules/binding-jms/src/main/java/org/apache/tuscany/sca/binding/jms/provider/JMSBindingServiceBindingProvider.java > Wed Feb 13 17:32:08 2008 > @@ -46,6 +46,7 @@ > private RuntimeComponentService service; > private JMSBinding jmsBinding; > private JMSResourceFactory jmsResourceFactory; > + private Object broker; > private MessageConsumer consumer; > > public JMSBindingServiceBindingProvider(RuntimeComponent component, > @@ -55,7 +56,6 @@ > this.jmsBinding = binding; > > jmsResourceFactory = jmsHost.createJMSResourceFactory( > binding.getConnectionFactoryName(), binding.getInitialContextFactoryName(), > binding.getJndiURL()); > - jmsResourceFactory.startBroker(); > > // if the default destination queue names is set > // set the destinate queue name to the reference name > @@ -96,6 +96,7 @@ > } > > public void start() { > + this.broker = jmsResourceFactory.startBroker(); > > try { > registerListerner(); > @@ -108,6 +109,9 @@ > try { > consumer.close(); > jmsResourceFactory.closeConnection(); > + if(this.broker!=null) { > + jmsResourceFactory.stopBroker(this.broker); > + } > } catch (Exception e) { > throw new JMSBindingException("Error stopping > JMSServiceBinding", e); > } > > Modified: > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java > (original) > +++ > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueExist.java > Wed Feb 13 17:32:08 2008 > @@ -45,6 +45,10 @@ > return d; > } > > - public void startBroker() { > + public Object startBroker() { > + return null; > + } > + > + public void stopBroker(Object broker) { > } > } > > Modified: > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java > (original) > +++ > incubator/tuscany/java/sca/modules/binding-jms/src/test/java/org/apache/tuscany/sca/binding/jms/mock/MockJMSResourceFactoryQueueNotExist.java > Wed Feb 13 17:32:08 2008 > @@ -42,6 +42,10 @@ > return null; > } > > - public void startBroker() { > + public Object startBroker() { > + return null; > + } > + > + public void stopBroker(Object broker) { > } > } > > Modified: > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQBroker.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQBroker.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQBroker.java > (original) > +++ > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQBroker.java > Wed Feb 13 17:32:08 2008 > @@ -18,6 +18,9 @@ > */ > package org.apache.tuscany.sca.host.jms.activemq; > > +import java.io.File; > +import java.util.UUID; > + > import org.apache.activemq.broker.BrokerService; > > /** > @@ -25,22 +28,33 @@ > public class ActiveMQBroker { > > public static final String CONNECTOR_URL = "tcp://localhost:61619"; > + public static final String BROKER_NAME = "ActiveMQ"; > + > private BrokerService broker; > + private String url = CONNECTOR_URL; > > public ActiveMQBroker() { > } > > + public ActiveMQBroker(String url) { > + this.url = url; > + } > + > public void start() { > broker = new BrokerService(); > + String uuid = UUID.randomUUID().toString(); > + broker.setBrokerName(BROKER_NAME + "-" + uuid); > + broker.setDataDirectory(new File("target/activemq-data/" + > uuid)); > try { > - broker.addConnector(CONNECTOR_URL); > + broker.addConnector(url); > + broker.setUseJmx(false); > broker.start(); > - } catch ( Exception e) { > + } catch (Exception e) { > e.printStackTrace(); > throw new RuntimeException(e); > } > } > - > + > public void stop() { > if (broker != null) { > try { > @@ -49,9 +63,12 @@ > e.printStackTrace(); > throw new RuntimeException(e); > } > - broker = null; > + broker = null; > } > } > > - > + public boolean isStarted() { > + return broker != null && broker.isStarted(); > + } > + > } > > Modified: > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java > (original) > +++ > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/ActiveMQModuleActivator.java > Wed Feb 13 17:32:08 2008 > @@ -19,27 +19,39 @@ > > package org.apache.tuscany.sca.host.jms.activemq; > > +import java.util.ArrayList; > +import java.util.List; > + > import org.apache.tuscany.sca.core.ExtensionPointRegistry; > import org.apache.tuscany.sca.core.ModuleActivator; > > public class ActiveMQModuleActivator implements ModuleActivator { > > - private static ActiveMQBroker activeMQHost; > + private static List<ActiveMQBroker> brokers = new > ArrayList<ActiveMQBroker>(); > > public void start(ExtensionPointRegistry registry) { > } > > public void stop(ExtensionPointRegistry registry) { > - if (activeMQHost != null) { > - activeMQHost.stop(); > - activeMQHost = null; > + for (ActiveMQBroker b : brokers) { > + if (b.isStarted()) { > + b.stop(); > + } > } > + brokers.clear(); > } > > - public static void startBroker() { > - if (activeMQHost == null) { > - activeMQHost = new ActiveMQBroker(); > - activeMQHost.start(); > - } > + public synchronized static ActiveMQBroker startBroker(String url) { > + ActiveMQBroker broker = new ActiveMQBroker(url); > + broker.start(); > + brokers.add(broker); > + return broker; > + } > + > + public synchronized static ActiveMQBroker startBroker() { > + ActiveMQBroker broker = new ActiveMQBroker(); > + broker.start(); > + brokers.add(broker); > + return broker; > } > } > > Modified: > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java > (original) > +++ > incubator/tuscany/java/sca/modules/host-jms-activemq/src/main/java/org/apache/tuscany/sca/host/jms/activemq/JMSResourceFactoryImpl.java > Wed Feb 13 17:32:08 2008 > @@ -40,7 +40,7 @@ > private String initialContextFactoryName = DEFAULT_ICFN; > private String connectionFactoryName = "ConnectionFactory"; > private String jndiURL = ActiveMQBroker.CONNECTOR_URL; > - > + > private Connection connection; > private Context context; > private boolean isConnectionStarted; > @@ -103,10 +103,17 @@ > } > } > > - public void startBroker() { > + public Object startBroker() { > if (isEmbedded()) { > // ensure the broker has been started > - ActiveMQModuleActivator.startBroker(); > + return ActiveMQModuleActivator.startBroker(jndiURL); > + } > + return null; > + } > + > + public void stopBroker(Object broker) { > + if(broker instanceof ActiveMQBroker) { > + ((ActiveMQBroker) broker).stop(); > } > } > > @@ -115,34 +122,36 @@ > * for now it always starts it if the activemq icf is being used with > our default jndiurl > */ > protected boolean isEmbedded() { > - return DEFAULT_ICFN.equals(initialContextFactoryName) && > ActiveMQBroker.CONNECTOR_URL.equals(jndiURL); > + try { > + getConnection(); > + return false; > + } catch (Exception e) { > + return true; > + } > + // return DEFAULT_ICFN.equals(initialContextFactoryName) && > ActiveMQBroker.CONNECTOR_URL.equals(jndiURL); > } > > private void createConnection() throws NamingException, JMSException { > - if (context == null) { > - createInitialContext(); > - } > - ConnectionFactory connectionFactory = > (ConnectionFactory)context.lookup(connectionFactoryName); > + ConnectionFactory connectionFactory = > (ConnectionFactory)getInitialContext().lookup(connectionFactoryName); > connection = connectionFactory.createConnection(); > } > > - private void createInitialContext() throws NamingException { > - Properties props = new Properties(); > - props.setProperty(Context.INITIAL_CONTEXT_FACTORY, > initialContextFactoryName); > - props.setProperty(Context.PROVIDER_URL, jndiURL); > + private synchronized Context getInitialContext() throws > NamingException { > + if (context == null) { > + Properties props = new Properties(); > + props.setProperty(Context.INITIAL_CONTEXT_FACTORY, > initialContextFactoryName); > + props.setProperty(Context.PROVIDER_URL, jndiURL); > > - context = new InitialContext(props); > + context = new InitialContext(props); > + } > + return context; > } > > public Destination lookupDestination(String jndiName) throws > NamingException { > - if (context == null) { > - createInitialContext(); > - } > - > Destination dest = null; > > try { > - dest = (Destination)context.lookup(jndiName); > + dest = (Destination)getInitialContext().lookup(jndiName); > } catch (NamingException ex) { > > } > > Modified: > incubator/tuscany/java/sca/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSResourceFactory.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSResourceFactory.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSResourceFactory.java > (original) > +++ > incubator/tuscany/java/sca/modules/host-jms/src/main/java/org/apache/tuscany/sca/host/jms/JMSResourceFactory.java > Wed Feb 13 17:32:08 2008 > @@ -42,5 +42,15 @@ > > Destination createDestination(String jndiName) throws NamingException; > > - void startBroker(); > + /** > + * Start a new message broker > + * @return The newly created message broker, null if no broker is > created > + */ > + Object startBroker(); > + > + /** > + * Stop the message broker > + * @param broker > + */ > + void stopBroker(Object broker); > } > > Modified: > incubator/tuscany/java/sca/samples/helloworld-reference-jms/src/test/java/helloworld/HelloWorldJmsClientTestCase.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-reference-jms/src/test/java/helloworld/HelloWorldJmsClientTestCase.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/samples/helloworld-reference-jms/src/test/java/helloworld/HelloWorldJmsClientTestCase.java > (original) > +++ > incubator/tuscany/java/sca/samples/helloworld-reference-jms/src/test/java/helloworld/HelloWorldJmsClientTestCase.java > Wed Feb 13 17:32:08 2008 > @@ -22,8 +22,6 @@ > import junit.framework.Assert; > > import org.apache.tuscany.sca.host.embedded.SCADomain; > -import org.apache.tuscany.sca.host.embedded.SCATestCaseRunner; > -import org.apache.tuscany.sca.host.jms.activemq.ActiveMQModuleActivator; > import org.junit.After; > import org.junit.Before; > import org.junit.Test; > @@ -43,7 +41,7 @@ > @Before > public void startClient() throws Exception { > try { > - ActiveMQModuleActivator.startBroker(); > + // ActiveMQModuleActivator.startBroker(); > scaServiceDomain = SCADomain.newInstance(" > helloworldjmsservice.composite"); > scaClientDomain = SCADomain.newInstance(" > helloworldjmsreference.composite"); > helloWorldService = scaClientDomain.getService( > HelloWorldService.class, "HelloWorldServiceComponent"); > > Modified: > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/main/java/helloworld/HelloWorldServer.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-service-jms/src/main/java/helloworld/HelloWorldServer.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/main/java/helloworld/HelloWorldServer.java > (original) > +++ > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/main/java/helloworld/HelloWorldServer.java > Wed Feb 13 17:32:08 2008 > @@ -21,7 +21,6 @@ > import java.io.IOException; > > import org.apache.tuscany.sca.host.embedded.SCADomain; > -import org.apache.tuscany.sca.host.jms.activemq.ActiveMQModuleActivator; > > /** > * This server program shows how to create an SCA runtime, and start it > which > @@ -31,7 +30,7 @@ > > public static void main(String[] args) { > > - ActiveMQModuleActivator.startBroker(); > + // ActiveMQModuleActivator.startBroker(); > SCADomain scaDomain = SCADomain.newInstance(" > helloworldjmsservice.composite"); > > try { > > Modified: > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCaseOff.java > URL: > http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCaseOff.java?rev=627631&r1=627630&r2=627631&view=diff > > ============================================================================== > --- > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCaseOff.java > (original) > +++ > incubator/tuscany/java/sca/samples/helloworld-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCaseOff.java > Wed Feb 13 17:32:08 2008 > @@ -24,7 +24,6 @@ > import java.io.IOException; > > import org.apache.tuscany.sca.host.embedded.SCADomain; > -import org.apache.tuscany.sca.host.jms.activemq.ActiveMQModuleActivator; > import org.junit.After; > import org.junit.Before; > import org.junit.Test; > @@ -32,21 +31,22 @@ > /** > * Tests that the helloworld server is available > */ > -public class HelloWorldJmsServerTestCaseOff{ > +public class HelloWorldJmsServerTestCaseOff { > > private SCADomain scaDomain; > > @Before > public void startServer() throws Exception { > - ActiveMQModuleActivator.startBroker(); > - scaDomain = SCADomain.newInstance(" > helloworldjmsservice.composite"); > + // ActiveMQModuleActivator.startBroker(); > + scaDomain = SCADomain.newInstance("helloworldjmsservice.composite > "); > } > > @Test > public void testServiceCall() throws IOException { > - HelloWorldService helloWorldService = scaDomain.getService( > HelloWorldService.class, "HelloWorldServiceComponent/HelloWorldService"); > + HelloWorldService helloWorldService = > + scaDomain.getService(HelloWorldService.class, > "HelloWorldServiceComponent/HelloWorldService"); > assertNotNull(helloWorldService); > - > + > assertEquals("Hello Smith", helloWorldService.getGreetings > ("Smith")); > } > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > >
