[jboss-cvs] JBoss Messaging SVN: r5592 - in branches/WIP_Bridge_in_standalone_JBM2: examples/jms and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 7 09:11:25 EST 2009
Author: jmesnil
Date: 2009-01-07 09:11:25 -0500 (Wed, 07 Jan 2009)
New Revision: 5592
Added:
branches/WIP_Bridge_in_standalone_JBM2/examples/jms/src/org/jboss/jms/example/BridgeExample.java
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeServiceMBean.java
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapter.java
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapterMBean.java
branches/WIP_Bridge_in_standalone_JBM2/tests/src/org/jboss/messaging/tests/integration/jms/bridge/
branches/WIP_Bridge_in_standalone_JBM2/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java
Removed:
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeMBean.java
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java
Modified:
branches/WIP_Bridge_in_standalone_JBM2/.classpath
branches/WIP_Bridge_in_standalone_JBM2/build-messaging.xml
branches/WIP_Bridge_in_standalone_JBM2/build.xml
branches/WIP_Bridge_in_standalone_JBM2/examples/jms/build.xml
branches/WIP_Bridge_in_standalone_JBM2/src/config/jbm-standalone-beans.xml
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/JMSManagementService.java
branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/impl/JMSManagementServiceImpl.java
Log:
refactored bridge to remove dependencies to JMX and JBoss AS classes so that the bridge can be run in a standalone JBM2 service without additional service
Modified: branches/WIP_Bridge_in_standalone_JBM2/.classpath
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/.classpath 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/.classpath 2009-01-07 14:11:25 UTC (rev 5592)
@@ -49,6 +49,7 @@
<classpathentry kind="lib" path="thirdparty/jboss/integration/lib/jboss-transaction-spi.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/jboss-jaspi-api/lib/jboss-jaspi-api.jar"/>
<classpathentry kind="lib" path="thirdparty/slf4j/api/lib/slf4j-api-1.4.3.jar"/>
+ <classpathentry kind="lib" path="thirdparty/jboss/jnpserver/lib/jnpserver.jar" sourcepath="thirdparty/jboss/jnpserver/lib/jnpserver-sources.jar"/>
<classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/>
<classpathentry kind="var" path="ANT_HOME/lib/ant-junit.jar"/>
<classpathentry kind="lib" path="thirdparty/jboss/common/lib/jboss-common.jar"/>
Modified: branches/WIP_Bridge_in_standalone_JBM2/build-messaging.xml
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/build-messaging.xml 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/build-messaging.xml 2009-01-07 14:11:25 UTC (rev 5592)
@@ -296,6 +296,8 @@
<path refid="javassist.classpath"/>
<path refid="jboss.jbossxb.classpath"/>
<path refid="apache.xerces.classpath"/>
+ <path refid="jboss.jnpserver.classpath"/>
+ <path refid="apache.logging.classpath"/>
</path>
<path id="jms.test.execution.classpath">
@@ -613,6 +615,8 @@
<include name="org/jboss/messaging/core/message/**/*.class"/>
<include name="org/jboss/messaging/core/version/**/*.class"/>
<include name="org/jboss/messaging/core/management/**/*.class"/>
+ <!-- FIXME classes on the client side also inherits from MessagingComponent -> moved to a proper package -->
+ <include name="org/jboss/messaging/core/server/MessagingComponent.class"/>
<!-- FIXME - why are these classes in the client jar ??? -->
<include name="org/jboss/messaging/core/server/MessagingComponent.class"/>
<include name="org/jboss/messaging/core/server/JournalType.class"/>
@@ -1308,6 +1312,10 @@
</target>
<!-- Examples -->
+ <target name="bridgeExample" depends="jar-client, jar-transports, jar-jms">
+ <ant dir="${examples.dir}/jms" antfile="build.xml" target="bridgeExample"/>
+ </target>
+
<target name="queueExample" depends="jar-client, jar-transports, jar-jms">
<ant dir="${examples.dir}/jms" antfile="build.xml" target="queueExample"/>
</target>
Modified: branches/WIP_Bridge_in_standalone_JBM2/build.xml
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/build.xml 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/build.xml 2009-01-07 14:11:25 UTC (rev 5592)
@@ -260,6 +260,10 @@
<ant antfile="build-messaging.xml" target="durSubExample"/>
</target>
+ <target name="bridgeExample" depends="createthirdparty">
+ <ant antfile="build-messaging.xml" target="bridgeExample"/>
+ </target>
+
<target name="wildcardExample" depends="createthirdparty">
<ant antfile="build-messaging.xml" target="wildcardExample"/>
</target>
Modified: branches/WIP_Bridge_in_standalone_JBM2/examples/jms/build.xml
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/examples/jms/build.xml 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/examples/jms/build.xml 2009-01-07 14:11:25 UTC (rev 5592)
@@ -110,6 +110,17 @@
</java>
</target>
+ <target name="bridgeExample" depends="compile" description="-> Bridge example using 2 queues">
+ <echo>*****************************************************************</echo>
+ <echo>make sure you have uncommented the Bridge, JBM_2_Provider and TransactionManager beans</echo>
+ <echo>in src/config/jbm-standalone-beans.xml</echo>
+ <echo>*****************************************************************</echo>
+
+ <java classname="org.jboss.jms.example.BridgeExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
<target name="topicExample" depends="compile" description="-> publish/subscribe example using a topic">
<java classname="org.jboss.jms.example.TopicExample" fork="true">
<classpath refid="runtime.classpath"/>
Added: branches/WIP_Bridge_in_standalone_JBM2/examples/jms/src/org/jboss/jms/example/BridgeExample.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/examples/jms/src/org/jboss/jms/example/BridgeExample.java (rev 0)
+++ branches/WIP_Bridge_in_standalone_JBM2/examples/jms/src/org/jboss/jms/example/BridgeExample.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.naming.InitialContext;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * A simple JMS Bridge example that creates a producer on the source queue and consumer on the target queue.
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class BridgeExample
+{
+ final static Logger log = Logger.getLogger(BridgeExample.class);
+
+ public static void main(final String[] args)
+ {
+ Connection sourceConnection = null;
+ Connection targetConnection = null;
+ try
+ {
+ InitialContext initialContext = new InitialContext();
+
+ Queue sourceQueue = (Queue)initialContext.lookup("/queue/A");
+ Queue targetQueue = (Queue)initialContext.lookup("/queue/B");
+ ConnectionFactory sourceCF = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+ ConnectionFactory targetCF = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+ sourceConnection = sourceCF.createConnection();
+ Session sourceSession = sourceConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = sourceSession.createProducer(sourceQueue);
+ TextMessage message = sourceSession.createTextMessage("" + System.currentTimeMillis());
+
+ log.info("sending message to source queue " + sourceQueue.getQueueName() + " : " + message.getText());
+ producer.send(message);
+
+ targetConnection = targetCF.createConnection();
+ Session targetSession = targetConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer messageConsumer = targetSession.createConsumer(targetQueue);
+ targetConnection.start();
+ TextMessage message2 = (TextMessage)messageConsumer.receive(5000);
+ log.info("message received from queue " + targetQueue.getQueueName());
+ log.info("message : " + message2.getText());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if (sourceConnection != null)
+ {
+ try
+ {
+ sourceConnection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ if (targetConnection != null)
+ {
+ try
+ {
+ targetConnection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
Modified: branches/WIP_Bridge_in_standalone_JBM2/src/config/jbm-standalone-beans.xml
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/config/jbm-standalone-beans.xml 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/config/jbm-standalone-beans.xml 2009-01-07 14:11:25 UTC (rev 5592)
@@ -161,4 +161,60 @@
factoryMethod="getPlatformMBeanServer"/>
</bean>
+ <!-- To run the bridgeExample: -->
+ <!-- uncomment the Bridge, JBM_2_Provider & TransactionManager beans -->
+
+ <!--
+ <bean name="Bridge" class="org.jboss.messaging.jms.bridge.BridgeService">
+ <constructor>
+ <parameter>TestBridge</parameter>
+ <parameter>
+ <inject bean="JMSManagementService"/>
+ </parameter>
+ </constructor>
+ <property name="sourceProvider">
+ <inject bean="JBM_2_Provider"/>
+ </property>
+ <property name="targetProvider">
+ <inject bean="JBM_2_Provider"/>
+ </property>
+ <property name="sourceDestinationLookup">/queue/A</property>
+ <property name="targetDestinationLookup">/queue/B</property>
+ <property name="failureRetryInterval">-1</property>
+ <property name="maxRetries">-1</property>
+ <property name="maxBatchSize">1</property>
+ <property name="maxBatchTime">-1</property>
+ <property name="qualityOfServiceMode">2</property>
+ <property name="transactionManager">
+ <inject bean="TransactionManager" />
+ </property>
+ </bean>
+
+ <bean name="JBM_2_Provider" class="org.jboss.messaging.jms.bridge.JMSProviderAdapter">
+ <constructor>
+ <parameter>JBoss Messaging 2 Adapter</parameter>
+ <parameter>
+ <map class="java.util.Properties" keyClass="java.lang.String" valueClass="java.lang.String">
+ <entry>
+ <key>java.naming.factory.initial</key>
+ <value>org.jnp.interfaces.NamingContextFactory</value>
+ </entry>
+ <entry>
+ <key>java.naming.provider.url</key>
+ <value>jnp://localhost:1099</value>
+ </entry>
+ <entry>
+ <key>java.naming.factory.url.pkgs</key>
+ <value>org.jboss.naming:org.jnp.interfaces"</value>
+ </entry>
+ </map>
+ </parameter>
+ <parameter>/ConnectionFactory</parameter>
+ </constructor>
+ </bean>
+
+ <bean name="TransactionManager" class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple">
+ </bean>
+ -->
+
</deployment>
\ No newline at end of file
Deleted: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeMBean.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeMBean.java 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeMBean.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -1,114 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.jms.bridge;
-
-import javax.management.ObjectName;
-
-
-/**
- * A BridgeMBean
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public interface BridgeMBean
-{
- // JMX attributes
-
- void setSourceProviderLoader(ObjectName sourceProviderLoader);
-
- ObjectName getSourceProviderLoader();
-
- void setTargetProviderLoader(ObjectName targetProviderLoader);
-
- ObjectName getTargetProviderLoader();
-
- String getSourceDestinationLookup();
-
- String getTargetDestinationLookup();
-
- void setSourceDestinationLookup(String lookup);
-
- void setTargetDestinationLookup(String lookup);
-
- String getSourceUsername();
-
- String getSourcePassword();
-
- void setSourceUsername(String name);
-
- void setSourcePassword(String pwd);
-
- String getTargetUsername();
-
- String getTargetPassword();
-
- void setTargetUsername(String name);
-
- void setTargetPassword(String pwd);
-
- int getQualityOfServiceMode();
-
- void setQualityOfServiceMode(int mode);
-
- String getSelector();
-
- void setSelector(String selector);
-
- int getMaxBatchSize();
-
- void setMaxBatchSize(int size);
-
- long getMaxBatchTime();
-
- void setMaxBatchTime(long time);
-
- String getSubName();
-
- void setSubName(String subname);
-
- String getClientID();
-
- void setClientID(String clientID);
-
- long getFailureRetryInterval();
-
- void setFailureRetryInterval(long interval);
-
- int getMaxRetries();
-
- void setMaxRetries(int retries);
-
- boolean isFailed();
-
- boolean isPaused();
-
- // JMX operations
-
- void pause() throws Exception;
-
- void resume() throws Exception;
-}
Deleted: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -1,394 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.jms.bridge;
-
-import javax.management.ObjectName;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.MessagingComponent;
-import org.jboss.messaging.jms.bridge.impl.BridgeImpl;
-
-/**
- * A BridgeService
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision: 1.1 $</tt>
- *
- * $Id$
- *
- */
-public class BridgeService implements BridgeMBean
-{
- private static final Logger log = Logger.getLogger(BridgeService.class);
- private Bridge bridge;
-
- private String sourceDestinationLookup;
-
- private String targetDestinationLookup;
-
- private ObjectName sourceProviderLoader;
-
- private ObjectName targetProviderLoader;
-
-
- public BridgeService()
- {
- bridge = new BridgeImpl();
- }
-
- // JMX attributes ----------------------------------------------------------------
-
- public synchronized ObjectName getSourceProviderLoader()
- {
- return sourceProviderLoader;
- }
-
- public synchronized void setSourceProviderLoader(ObjectName sourceProvider)
- {
- if (bridge.isStarted())
- {
- log.warn("Cannot set SourceProvider when bridge is started");
- return;
- }
- this.sourceProviderLoader = sourceProvider;
- }
-
- public synchronized ObjectName getTargetProviderLoader()
- {
- return targetProviderLoader;
- }
-
- public synchronized void setTargetProviderLoader(ObjectName targetProvider)
- {
- if (bridge.isStarted())
- {
- log.warn("Cannot set TargetProvider when bridge is started");
- return;
- }
- this.targetProviderLoader = targetProvider;
- }
-
- public String getSourceDestinationLookup()
- {
- return sourceDestinationLookup;
- }
-
- public String getTargetDestinationLookup()
- {
- return targetDestinationLookup;
- }
-
- public void setSourceDestinationLookup(String lookup)
- {
- if (bridge.isStarted())
- {
- log.warn("Cannot set SourceDestinationLookup when bridge is started");
- return;
- }
- this.sourceDestinationLookup = checkAndTrim(lookup);
- }
-
- public void setTargetDestinationLookup(String lookup)
- {
- if (bridge.isStarted())
- {
- log.warn("Cannot set TargetDestinationLookup when bridge is started");
- return;
- }
- this.targetDestinationLookup = checkAndTrim(lookup);
- }
-
- public String getSourceUsername()
- {
- return bridge.getSourceUsername();
- }
-
- public String getSourcePassword()
- {
- return bridge.getSourcePassword();
- }
-
- public void setSourceUsername(String name)
- {
- bridge.setSourceUsername(name);
- }
-
- public void setSourcePassword(String pwd)
- {
- bridge.setSourcePassword(pwd);
- }
-
- public String getTargetUsername()
- {
- return bridge.getTargetUsername();
- }
-
- public String getTargetPassword()
- {
- return bridge.getTargetPassword();
- }
-
- public void setTargetUsername(String name)
- {
- bridge.setTargetUsername(name);
- }
-
- public void setTargetPassword(String pwd)
- {
- bridge.setTargetPassword(pwd);
- }
-
- public int getQualityOfServiceMode()
- {
- return bridge.getQualityOfServiceMode().intValue();
- }
-
- public void setQualityOfServiceMode(int mode)
- {
- bridge.setQualityOfServiceMode(QualityOfServiceMode.valueOf(mode));
- }
-
- public String getSelector()
- {
- return bridge.getSelector();
- }
-
- public void setSelector(String selector)
- {
- bridge.setSelector(selector);
- }
-
- public int getMaxBatchSize()
- {
- return bridge.getMaxBatchSize();
- }
-
- public void setMaxBatchSize(int size)
- {
- bridge.setMaxBatchSize(size);
- }
-
- public long getMaxBatchTime()
- {
- return bridge.getMaxBatchTime();
- }
-
- public void setMaxBatchTime(long time)
- {
- bridge.setMaxBatchTime(time);
- }
-
- public String getSubName()
- {
- return bridge.getSubscriptionName();
- }
-
- public void setSubName(String subname)
- {
- bridge.setSubscriptionName(subname);
- }
-
- public String getClientID()
- {
- return bridge.getClientID();
- }
-
- public void setClientID(String clientID)
- {
- bridge.setClientID(clientID);
- }
-
- public long getFailureRetryInterval()
- {
- return bridge.getFailureRetryInterval();
- }
-
- public void setFailureRetryInterval(long interval)
- {
- bridge.setFailureRetryInterval(interval);
- }
-
- public int getMaxRetries()
- {
- return bridge.getMaxRetries();
- }
-
- public void setMaxRetries(int retries)
- {
- bridge.setMaxRetries(retries);
- }
-
- public boolean isAddMessageIDInHeader()
- {
- return bridge.isAddMessageIDInHeader();
- }
-
- public void setAddMessageIDInHeader(boolean value)
- {
- bridge.setAddMessageIDInHeader(value);
- }
-
- public boolean isFailed()
- {
- return bridge.isFailed();
- }
-
- public boolean isPaused()
- {
- return bridge.isPaused();
- }
-
- public boolean isStarted()
- {
- return bridge.isStarted();
- }
-
- public MessagingComponent getInstance()
- {
- return bridge;
- }
-
- // JMX operations ----------------------------------------------------------------
-
- public void pause() throws Exception
- {
- bridge.pause();
- }
-
- public void resume() throws Exception
- {
- bridge.resume();
- }
-
- // ServiceMBeanSupport overrides --------------------------------------------------
-
- protected void startService() throws Exception
- {
- if (log.isTraceEnabled()) { log.trace("Starting bridge"); }
-
- //super.startService();
-
- if (this.sourceProviderLoader == null)
- {
- throw new IllegalArgumentException("sourceProvider cannot be null");
- }
-
- if (this.targetProviderLoader == null)
- {
- throw new IllegalArgumentException("targetProvider cannot be null");
- }
-
- if (sourceDestinationLookup == null)
- {
- throw new IllegalArgumentException("Source destination lookup cannot be null");
- }
-
- if (targetDestinationLookup == null)
- {
- throw new IllegalArgumentException("Target destination lookup cannot be null");
- }
-
- boolean sameSourceAndTarget = sourceProviderLoader.equals(targetProviderLoader);
-
- // Properties sourceProps = (Properties)server.getAttribute(sourceProviderLoader, "Properties");
-
- // Properties targetProps = (Properties)server.getAttribute(targetProviderLoader, "Properties");
-
- /*
- // JBMESSAGING-1183: set the factory refs according to the destinations types
- Context icSource = new InitialContext(sourceProps);
- Context icTarget = new InitialContext(targetProps);
- Destination sourceDest = (Destination)icSource.lookup(sourceDestinationLookup);
- Destination targetDest = (Destination)icTarget.lookup(targetDestinationLookup);
- String sourceFactoryRef = "QueueFactoryRef";
- if(sourceDest instanceof Topic)
- {
- sourceFactoryRef = "TopicFactoryRef";
- }
- String targetFactoryRef = "QueueFactoryRef";
- if(targetDest instanceof Topic)
- {
- targetFactoryRef = "TopicFactoryRef";
- }
-
- String sourceCFRef = (String)server.getAttribute(sourceProviderLoader, sourceFactoryRef);
-
- String targetCFRef = (String)server.getAttribute(targetProviderLoader, targetFactoryRef);
- */
-
- //ConnectionFactoryFactory sourceCff =
- // new JNDIConnectionFactoryFactory(sourceProps, sourceCFRef);
-
- /* ConnectionFactoryFactory destCff;
-
- if (sameSourceAndTarget)
- {
- destCff = sourceCff;
- }
- else
- {
- destCff= new JNDIConnectionFactoryFactory(targetProps, targetCFRef);
- }
-
- bridge.setSourceConnectionFactoryFactory(sourceCff);
-
- bridge.setDestConnectionFactoryFactory(destCff);
-
- DestinationFactory sourceDestinationFactory = new JNDIDestinationFactory(sourceProps, sourceDestinationLookup);
-
- DestinationFactory targetDestinationFactory = new JNDIDestinationFactory(targetProps, targetDestinationLookup);
-
- bridge.setSourceDestinationFactory(sourceDestinationFactory);
-
- bridge.setTargetDestinationFactory(targetDestinationFactory);
-
- bridge.start();
-
- log.info("Started bridge " + this.getName() + ". Source: " + sourceDestinationLookup + " Target: " + targetDestinationLookup);*/
- }
-
-
- protected void stopService() throws Exception
- {
- if (log.isTraceEnabled()) { log.trace("Stopping bridge"); }
-
- bridge.stop();
-
- //log.info("Stopped bridge " + this.getName());
- }
-
- // Private ---------------------------------------------------------------------------------
-
- private String checkAndTrim(String s)
- {
- if (s != null)
- {
- s = s.trim();
- if ("".equals(s))
- {
- s = null;
- }
- }
- return s;
- }
-}
Added: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java (rev 0)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -0,0 +1,447 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.jms.bridge;
+
+import java.util.Properties;
+
+import javax.jms.Destination;
+import javax.jms.Queue;
+import javax.jms.Topic;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.TransactionManager;
+
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.jms.bridge.impl.BridgeImpl;
+import org.jboss.messaging.jms.bridge.impl.JNDIConnectionFactoryFactory;
+import org.jboss.messaging.jms.bridge.impl.JNDIDestinationFactory;
+import org.jboss.messaging.jms.server.management.JMSManagementService;
+
+/**
+ * A BridgeService
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public class BridgeService implements BridgeServiceMBean
+{
+ private static final Logger log = Logger.getLogger(BridgeService.class);
+
+ private final String name;
+
+ private final Bridge bridge;
+
+ private String sourceDestinationLookup;
+
+ private String targetDestinationLookup;
+
+ private JMSProviderAdapterMBean sourceProvider;
+
+ private JMSProviderAdapterMBean targetProvider;
+
+ private final JMSManagementService managementService;
+
+ public BridgeService(String name, JMSManagementService managementService)
+ {
+ this.name = name;
+ this.managementService = managementService;
+
+ bridge = new BridgeImpl();
+ try
+ {
+ managementService.registerBridge(this);
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ // BridgeService implementation ----------------------------------
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getSourceProviderName() throws Exception
+ {
+ return (sourceProvider == null) ? null : sourceProvider.getName();
+ }
+
+ public String getTargetProviderName() throws Exception
+ {
+ return (targetProvider == null) ? null : targetProvider.getName();
+ }
+
+ public void setTransactionManager(TransactionManager tm)
+ {
+ bridge.setTransactionManager(tm);
+ }
+
+ public String getSourceDestinationLookup()
+ {
+ return sourceDestinationLookup;
+ }
+
+ public String getTargetDestinationLookup()
+ {
+ return targetDestinationLookup;
+ }
+
+ public void setSourceDestinationLookup(String lookup)
+ {
+ if (bridge.isStarted())
+ {
+ throw new IllegalStateException("Cannot set SourceDestinationLookup when bridge is started");
+ }
+ this.sourceDestinationLookup = checkAndTrim(lookup);
+ }
+
+ public void setTargetDestinationLookup(String lookup)
+ {
+ if (bridge.isStarted())
+ {
+ throw new IllegalStateException("Cannot set TargetDestinationLookup when bridge is started");
+ }
+ this.targetDestinationLookup = checkAndTrim(lookup);
+ }
+
+ public String getSourceUsername()
+ {
+ return bridge.getSourceUsername();
+ }
+
+ public String getSourcePassword()
+ {
+ return bridge.getSourcePassword();
+ }
+
+ public void setSourceUsername(String name)
+ {
+ bridge.setSourceUsername(name);
+ }
+
+ public void setSourcePassword(String pwd)
+ {
+ bridge.setSourcePassword(pwd);
+ }
+
+ public String getTargetUsername()
+ {
+ return bridge.getTargetUsername();
+ }
+
+ public String getTargetPassword()
+ {
+ return bridge.getTargetPassword();
+ }
+
+ public void setTargetUsername(String name)
+ {
+ bridge.setTargetUsername(name);
+ }
+
+ public void setTargetPassword(String pwd)
+ {
+ bridge.setTargetPassword(pwd);
+ }
+
+ public int getQualityOfServiceMode()
+ {
+ return bridge.getQualityOfServiceMode().intValue();
+ }
+
+ public void setQualityOfServiceMode(int mode)
+ {
+ bridge.setQualityOfServiceMode(QualityOfServiceMode.valueOf(mode));
+ }
+
+ public String getSelector()
+ {
+ return bridge.getSelector();
+ }
+
+ public void setSelector(String selector)
+ {
+ bridge.setSelector(selector);
+ }
+
+ public int getMaxBatchSize()
+ {
+ return bridge.getMaxBatchSize();
+ }
+
+ public void setMaxBatchSize(int size)
+ {
+ bridge.setMaxBatchSize(size);
+ }
+
+ public long getMaxBatchTime()
+ {
+ return bridge.getMaxBatchTime();
+ }
+
+ public void setMaxBatchTime(long time)
+ {
+ bridge.setMaxBatchTime(time);
+ }
+
+ public String getSubName()
+ {
+ return bridge.getSubscriptionName();
+ }
+
+ public void setSubName(String subname)
+ {
+ bridge.setSubscriptionName(subname);
+ }
+
+ public String getClientID()
+ {
+ return bridge.getClientID();
+ }
+
+ public void setClientID(String clientID)
+ {
+ bridge.setClientID(clientID);
+ }
+
+ public long getFailureRetryInterval()
+ {
+ return bridge.getFailureRetryInterval();
+ }
+
+ public void setFailureRetryInterval(long interval)
+ {
+ bridge.setFailureRetryInterval(interval);
+ }
+
+ public int getMaxRetries()
+ {
+ return bridge.getMaxRetries();
+ }
+
+ public void setMaxRetries(int retries)
+ {
+ bridge.setMaxRetries(retries);
+ }
+
+ public boolean isAddMessageIDInHeader()
+ {
+ return bridge.isAddMessageIDInHeader();
+ }
+
+ public void setAddMessageIDInHeader(boolean value)
+ {
+ bridge.setAddMessageIDInHeader(value);
+ }
+
+ public boolean isFailed()
+ {
+ return bridge.isFailed();
+ }
+
+ public boolean isPaused()
+ {
+ return bridge.isPaused();
+ }
+
+ public void pause() throws Exception
+ {
+ bridge.pause();
+ }
+
+ public void resume() throws Exception
+ {
+ bridge.resume();
+ }
+
+ // MessagingComponent implementation -----------------------------
+
+ public void start() throws Exception
+ {
+ if (isStarted())
+ {
+ throw new IllegalStateException("Bridge is already started");
+ }
+
+ if (log.isTraceEnabled())
+ {
+ log.trace("Starting bridge");
+ }
+
+ // super.startService();
+
+ if (this.sourceProvider == null)
+ {
+ throw new IllegalArgumentException("sourceProvider cannot be null");
+ }
+
+ if (this.targetProvider == null)
+ {
+ throw new IllegalArgumentException("targetProvider cannot be null");
+ }
+
+ if (sourceDestinationLookup == null)
+ {
+ throw new IllegalArgumentException("Source destination lookup cannot be null");
+ }
+
+ if (targetDestinationLookup == null)
+ {
+ throw new IllegalArgumentException("Target destination lookup cannot be null");
+ }
+
+ // FIXME comparing the provider's names is maybe not a bright idea
+ boolean sameSourceAndTarget = sourceProvider.getName().equals(targetProvider.getName());
+
+ Properties sourceProps = sourceProvider.getProperties();
+
+ Properties targetProps = targetProvider.getProperties();
+
+ // JBMESSAGING-1183: set the factory refs according to the destinations types
+ Context icSource = new InitialContext(sourceProps);
+ Context icTarget = new InitialContext(targetProps);
+ Destination sourceDest = (Destination)icSource.lookup(sourceDestinationLookup);
+ Destination targetDest = (Destination)icTarget.lookup(targetDestinationLookup);
+
+ String sourceCFRef = sourceProvider.getFactoryRef();
+
+ if (sourceCFRef == null && sourceDest instanceof Topic)
+ {
+ sourceCFRef = sourceProvider.getTopicFactoryRef();
+ }
+ if (sourceCFRef == null && sourceDest instanceof Queue)
+ {
+ sourceCFRef = sourceProvider.getQueueFactoryRef();
+ }
+
+ String targetCFRef = targetProvider.getFactoryRef();
+
+ if (targetCFRef == null && targetDest instanceof Topic)
+ {
+ targetCFRef = targetProvider.getTopicFactoryRef();
+ }
+ if (targetCFRef == null && targetDest instanceof Queue)
+ {
+ targetCFRef = targetProvider.getQueueFactoryRef();
+ }
+
+ ConnectionFactoryFactory sourceCff = new JNDIConnectionFactoryFactory(sourceProps, sourceCFRef);
+
+ ConnectionFactoryFactory destCff;
+
+ if (sameSourceAndTarget)
+ {
+ destCff = sourceCff;
+ }
+ else
+ {
+ destCff = new JNDIConnectionFactoryFactory(targetProps, targetCFRef);
+ }
+
+ bridge.setSourceConnectionFactoryFactory(sourceCff);
+
+ bridge.setTargetConnectionFactoryFactory(destCff);
+
+ DestinationFactory sourceDestinationFactory = new JNDIDestinationFactory(sourceProps, sourceDestinationLookup);
+
+ DestinationFactory targetDestinationFactory = new JNDIDestinationFactory(targetProps, targetDestinationLookup);
+
+ bridge.setSourceDestinationFactory(sourceDestinationFactory);
+
+ bridge.setTargetDestinationFactory(targetDestinationFactory);
+
+ bridge.start();
+
+ log.info("Started bridge [source: " + sourceDestinationLookup + ", target: " + targetDestinationLookup + "]");
+ }
+
+ public void stop() throws Exception
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Stopping bridge");
+ }
+
+ bridge.stop();
+
+ if (log.isTraceEnabled())
+ {
+ log.trace("Stopped bridge");
+ }
+ }
+
+ public boolean isStarted()
+ {
+ return bridge.isStarted();
+ }
+
+ // Public ----------------------------------------------------------------------------------
+
+ public synchronized void setSourceProvider(JMSProviderAdapterMBean sourceProvider) throws Exception
+ {
+ if (bridge.isStarted())
+ {
+ throw new IllegalStateException("Cannot set SourceProvider when bridge is started");
+ }
+ managementService.unregisterJMSProviderAdapter(sourceProvider);
+ this.sourceProvider = sourceProvider;
+ managementService.registerJMSProviderAdapter(sourceProvider);
+
+ }
+
+ public synchronized void setTargetProvider(JMSProviderAdapterMBean targetProvider) throws Exception
+ {
+ if (bridge.isStarted())
+ {
+ throw new IllegalStateException("Cannot set TargetProvider when bridge is started");
+ }
+ managementService.unregisterJMSProviderAdapter(targetProvider);
+ this.targetProvider = targetProvider;
+ managementService.registerJMSProviderAdapter(targetProvider);
+ }
+
+ // Private ---------------------------------------------------------------------------------
+
+ private String checkAndTrim(String s)
+ {
+ if (s != null)
+ {
+ s = s.trim();
+ if ("".equals(s))
+ {
+ s = null;
+ }
+ }
+ return s;
+ }
+
+}
Property changes on: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeService.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeServiceMBean.java (from rev 5514, trunk/src/main/org/jboss/messaging/jms/bridge/BridgeMBean.java)
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeServiceMBean.java (rev 0)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeServiceMBean.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.jms.bridge;
+
+import javax.transaction.TransactionManager;
+
+import org.jboss.messaging.core.server.MessagingComponent;
+
+
+
+/**
+ * A BridgeService
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision: 1.1 $</tt>
+ *
+ * $Id$
+ *
+ */
+public interface BridgeServiceMBean extends MessagingComponent
+{
+ String getSourceProviderName() throws Exception;
+
+ String getTargetProviderName() throws Exception;
+
+ String getSourceDestinationLookup();
+
+ String getTargetDestinationLookup();
+
+ void setSourceDestinationLookup(String lookup);
+
+ void setTargetDestinationLookup(String lookup);
+
+ String getSourceUsername();
+
+ String getSourcePassword();
+
+ void setSourceUsername(String name);
+
+ void setSourcePassword(String pwd);
+
+ String getTargetUsername();
+
+ String getTargetPassword();
+
+ void setTargetUsername(String name);
+
+ void setTargetPassword(String pwd);
+
+ int getQualityOfServiceMode();
+
+ void setQualityOfServiceMode(int mode);
+
+ String getSelector();
+
+ void setSelector(String selector);
+
+ int getMaxBatchSize();
+
+ void setMaxBatchSize(int size);
+
+ long getMaxBatchTime();
+
+ void setMaxBatchTime(long time);
+
+ String getSubName();
+
+ void setSubName(String subname);
+
+ String getClientID();
+
+ void setClientID(String clientID);
+
+ long getFailureRetryInterval();
+
+ void setFailureRetryInterval(long interval);
+
+ int getMaxRetries();
+
+ void setMaxRetries(int retries);
+
+ boolean isFailed();
+
+ boolean isPaused();
+
+ void pause() throws Exception;
+
+ void resume() throws Exception;
+
+ void setTransactionManager(TransactionManager tm);
+}
Property changes on: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/BridgeServiceMBean.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapter.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapter.java (rev 0)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapter.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.jms.bridge;
+
+import java.util.Properties;
+
+/**
+ * A JMSProviderAdapter
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ */
+public class JMSProviderAdapter implements JMSProviderAdapterMBean
+{
+ private final String name;
+
+ private final Properties props;
+
+ private final String factoryRef;
+
+ private final String queueFactoryRef;
+
+ private final String topicFactoryRef;
+
+ public JMSProviderAdapter(final String name, final Properties props, final String factoryRef)
+ {
+ this(name, props, factoryRef, factoryRef, factoryRef);
+ }
+
+ public JMSProviderAdapter(final String name,
+ final Properties props,
+ final String factoryRef,
+ final String queueFactoryRef,
+ final String topicFactoryRef)
+ {
+ this.name = name;
+ this.props = props;
+ this.factoryRef = factoryRef;
+ this.queueFactoryRef = queueFactoryRef;
+ this.topicFactoryRef = topicFactoryRef;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Properties getProperties()
+ {
+ return props;
+ }
+
+ public String getFactoryRef()
+ {
+ return factoryRef;
+ }
+
+ public String getQueueFactoryRef()
+ {
+ return queueFactoryRef;
+ }
+
+ public String getTopicFactoryRef()
+ {
+ return topicFactoryRef;
+ }
+}
Added: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapterMBean.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapterMBean.java (rev 0)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/bridge/JMSProviderAdapterMBean.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.messaging.jms.bridge;
+
+import java.util.Properties;
+
+/**
+ * A JMSProviderAdapterMBean
+ *
+ * @author jmesnil
+ *
+ *
+ */
+public interface JMSProviderAdapterMBean
+{
+
+ public String getName();
+
+ public Properties getProperties();
+
+ public String getFactoryRef();
+
+ public String getQueueFactoryRef();
+
+ public String getTopicFactoryRef();
+
+}
Modified: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/JMSManagementService.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/JMSManagementService.java 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/JMSManagementService.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -31,6 +31,8 @@
import org.jboss.messaging.core.settings.impl.QueueSettings;
import org.jboss.messaging.jms.JBossQueue;
import org.jboss.messaging.jms.JBossTopic;
+import org.jboss.messaging.jms.bridge.BridgeService;
+import org.jboss.messaging.jms.bridge.JMSProviderAdapterMBean;
import org.jboss.messaging.jms.client.JBossConnectionFactory;
import org.jboss.messaging.jms.server.JMSServerManager;
@@ -66,4 +68,11 @@
void registerConnectionFactory(String name, JBossConnectionFactory connectionFactory, List<String> bindings) throws Exception;
void unregisterConnectionFactory(String name) throws Exception;
+
+ void registerBridge(BridgeService bridgeControl) throws Exception;
+
+ void registerJMSProviderAdapter(JMSProviderAdapterMBean providerAdapter) throws Exception;
+
+ void unregisterJMSProviderAdapter(JMSProviderAdapterMBean providerAdapter) throws Exception;
+
}
Modified: branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/impl/JMSManagementServiceImpl.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/impl/JMSManagementServiceImpl.java 2009-01-07 14:01:41 UTC (rev 5591)
+++ branches/WIP_Bridge_in_standalone_JBM2/src/main/org/jboss/messaging/jms/server/management/impl/JMSManagementServiceImpl.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -27,6 +27,7 @@
import java.util.List;
import javax.management.ObjectName;
+import javax.management.StandardMBean;
import org.jboss.messaging.core.management.ManagementService;
import org.jboss.messaging.core.management.impl.ManagementServiceImpl;
@@ -39,6 +40,9 @@
import org.jboss.messaging.core.settings.impl.QueueSettings;
import org.jboss.messaging.jms.JBossQueue;
import org.jboss.messaging.jms.JBossTopic;
+import org.jboss.messaging.jms.bridge.BridgeService;
+import org.jboss.messaging.jms.bridge.BridgeServiceMBean;
+import org.jboss.messaging.jms.bridge.JMSProviderAdapterMBean;
import org.jboss.messaging.jms.client.JBossConnectionFactory;
import org.jboss.messaging.jms.server.JMSServerManager;
import org.jboss.messaging.jms.server.management.JMSManagementService;
@@ -85,7 +89,17 @@
return ObjectName.getInstance(ManagementServiceImpl.DOMAIN + ":module=JMS,type=ConnectionFactory,name=" +
quote(name));
}
+
+ public static ObjectName getBridgeObjectName(final String name) throws Exception
+ {
+ return ObjectName.getInstance(String.format("%s:module=JMS,type=Bridge,name=%s", ManagementServiceImpl.DOMAIN, quote(name)));
+ }
+ public static ObjectName getJMSProviderAdapterObjectName(final String name) throws Exception
+ {
+ return ObjectName.getInstance(String.format("%s:module=JMS,type=Bridge.ProviderAdapter,name=%s", ManagementServiceImpl.DOMAIN, quote(name)));
+ }
+
// Constructors --------------------------------------------------
public JMSManagementServiceImpl(final ManagementService managementService)
@@ -180,7 +194,27 @@
ObjectName objectName = getConnectionFactoryObjectName(name);
managementService.unregisterResource(objectName);
}
+
+ public void registerBridge(BridgeService bridge) throws Exception
+ {
+ ObjectName objectName = getBridgeObjectName(bridge.getName());
+ managementService.registerInJMX(objectName, new StandardMBean(bridge, BridgeServiceMBean.class));
+ managementService.registerInRegistry(objectName, bridge);
+ }
+ public void registerJMSProviderAdapter(JMSProviderAdapterMBean providerAdapter) throws Exception
+ {
+ ObjectName objectName = getJMSProviderAdapterObjectName(providerAdapter.getName());
+ managementService.registerInJMX(objectName, new StandardMBean(providerAdapter, JMSProviderAdapterMBean.class));
+ managementService.registerInRegistry(objectName, providerAdapter);
+ }
+
+ public void unregisterJMSProviderAdapter(JMSProviderAdapterMBean providerAdapter) throws Exception
+ {
+ ObjectName objectName = getJMSProviderAdapterObjectName(providerAdapter.getName());
+ managementService.unregisterResource(objectName);
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Added: branches/WIP_Bridge_in_standalone_JBM2/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java
===================================================================
--- branches/WIP_Bridge_in_standalone_JBM2/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java (rev 0)
+++ branches/WIP_Bridge_in_standalone_JBM2/tests/src/org/jboss/messaging/tests/integration/jms/bridge/BridgeTest.java 2009-01-07 14:11:25 UTC (rev 5592)
@@ -0,0 +1,253 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.jms.bridge;
+
+import static org.jboss.messaging.tests.integration.management.ManagementControlHelper.createJMSQueueControl;
+import static org.jboss.messaging.tests.integration.management.ManagementControlHelper.createJMSServerControl;
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.lang.management.ManagementFactory;
+import java.util.Properties;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.management.MBeanServerFactory;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.transaction.TransactionManager;
+
+import junit.framework.TestCase;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple;
+
+import org.jboss.messaging.core.management.impl.ManagementServiceImpl;
+import org.jboss.messaging.integration.bootstrap.JBMBootstrapServer;
+import org.jboss.messaging.jms.bridge.BridgeService;
+import org.jboss.messaging.jms.bridge.BridgeServiceMBean;
+import org.jboss.messaging.jms.bridge.JMSProviderAdapter;
+import org.jboss.messaging.jms.bridge.QualityOfServiceMode;
+import org.jboss.messaging.jms.server.management.JMSQueueControlMBean;
+import org.jboss.messaging.jms.server.management.JMSServerControlMBean;
+import org.jboss.messaging.jms.server.management.impl.JMSManagementServiceImpl;
+import org.jboss.messaging.tests.integration.jms.management.JMSUtil;
+
+/**
+ * A BridgeTestCase
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ */
+public class BridgeTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ /**
+ *
+ */
+ private static final String CF_LOOKUP = "/ConnectionFactory";
+
+ private static final String STANDALONE_BEANS = "jbm-standalone-beans.xml";
+
+ private static final String SOURCE_QUEUE_LOOKUP = "/queue/sourceQueue";
+
+ private static final String SOURCE_QUEUE_NAME = "sourceQueue";
+
+ private static final String TARGET_QUEUE_NAME = "targetQueue";
+
+ private static final String TARGET_QUEUE_LOOKUP = "/queue/targetQueue";
+
+ private JBMBootstrapServer bootstrap;
+
+ private JMSServerControlMBean serverControl;
+
+ private TransactionManager tm;
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ public static void assertRemainingMessages(int expectedCount, Queue queue) throws Exception
+ {
+ JMSQueueControlMBean control = createJMSQueueControl(queue, ManagementFactory.getPlatformMBeanServer());
+ int messageCount = control.countMessages(null);
+ assertEquals(expectedCount, messageCount);
+ }
+
+ public static void destroyQueue(String queueName) throws Exception
+ {
+ JMSServerControlMBean control = createJMSServerControl(ManagementFactory.getPlatformMBeanServer());
+ control.destroyQueue(queueName);
+ }
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testSimple() throws Exception
+ {
+
+ InitialContext context = new InitialContext();
+ Queue sourceQueue = (Queue)context.lookup(SOURCE_QUEUE_LOOKUP);
+ Queue targetQueue = (Queue)context.lookup(TARGET_QUEUE_LOOKUP);
+ ConnectionFactory cf = (ConnectionFactory)context.lookup(CF_LOOKUP);
+
+ JMSUtil.sendMessages(cf, sourceQueue, 1);
+ assertRemainingMessages(1, sourceQueue);
+ assertRemainingMessages(0, targetQueue);
+
+ BridgeServiceMBean bridgeService = setupBridgeService();
+ bridgeService.start();
+
+ Thread.sleep(500);
+
+ assertRemainingMessages(0, sourceQueue);
+ assertRemainingMessages(1, targetQueue);
+
+ Connection connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer targetConsumer = session.createConsumer(targetQueue);
+
+ connection.start();
+ Message message = targetConsumer.receive(500);
+ assertNotNull(message);
+
+ assertRemainingMessages(0, sourceQueue);
+ assertRemainingMessages(0, targetQueue);
+ }
+
+ public void testPause() throws Exception
+ {
+
+ InitialContext context = new InitialContext();
+ Queue sourceQueue = (Queue)context.lookup(SOURCE_QUEUE_LOOKUP);
+ Queue targetQueue = (Queue)context.lookup(TARGET_QUEUE_LOOKUP);
+ ConnectionFactory cf = (ConnectionFactory)context.lookup(CF_LOOKUP);
+
+ JMSUtil.sendMessages(cf, sourceQueue, 1);
+ assertRemainingMessages(1, sourceQueue);
+ assertRemainingMessages(0, targetQueue);
+
+ BridgeServiceMBean bridgeService = setupBridgeService();
+ bridgeService.start();
+
+ Thread.sleep(500);
+
+ assertRemainingMessages(0, sourceQueue);
+ assertRemainingMessages(1, targetQueue);
+
+ Connection connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageConsumer targetConsumer = session.createConsumer(targetQueue);
+
+ connection.start();
+ Message message = targetConsumer.receive(500);
+ assertNotNull(message);
+
+ assertRemainingMessages(0, sourceQueue);
+ assertRemainingMessages(0, targetQueue);
+
+ bridgeService.pause();
+ assertTrue(bridgeService.isPaused());
+
+ JMSUtil.sendMessages(sourceQueue, 1);
+ assertRemainingMessages(1, sourceQueue);
+ assertRemainingMessages(0, targetQueue);
+
+ bridgeService.resume();
+ assertFalse(bridgeService.isPaused());
+ assertTrue(bridgeService.isStarted());
+
+ Thread.sleep(500);
+
+ assertRemainingMessages(0, sourceQueue);
+ assertRemainingMessages(0, targetQueue);
+
+ message = targetConsumer.receive(500);
+ assertNotNull(message);
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ System.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+
+ bootstrap = new JBMBootstrapServer(new String[] { STANDALONE_BEANS });
+ bootstrap.run();
+
+ serverControl = createJMSServerControl(ManagementFactory.getPlatformMBeanServer());
+ boolean sourceQueueCreated = serverControl.createQueue(SOURCE_QUEUE_NAME, SOURCE_QUEUE_LOOKUP);
+ assertTrue(sourceQueueCreated);
+ boolean targetQueueCreated = serverControl.createQueue(TARGET_QUEUE_NAME, TARGET_QUEUE_LOOKUP);
+ assertTrue(targetQueueCreated);
+
+ tm = new TransactionManagerImple();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ destroyQueue(SOURCE_QUEUE_NAME);
+ destroyQueue(TARGET_QUEUE_NAME);
+
+ bootstrap.shutDown();
+
+ super.tearDown();
+ }
+
+ // Private -------------------------------------------------------
+
+ private BridgeServiceMBean setupBridgeService() throws Exception
+ {
+ Properties props = new Properties();
+ props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+
+ BridgeService bridgeService = new BridgeService(randomString(), new JMSManagementServiceImpl(new ManagementServiceImpl(MBeanServerFactory.createMBeanServer(), false)));
+ bridgeService.setSourceProvider(new JMSProviderAdapter("JBoss Messaging Adapter", props, CF_LOOKUP));
+ bridgeService.setTargetProvider(new JMSProviderAdapter("JBoss Messaging Adapter", props, CF_LOOKUP));
+ bridgeService.setSourceDestinationLookup(SOURCE_QUEUE_LOOKUP);
+ bridgeService.setTargetDestinationLookup(TARGET_QUEUE_LOOKUP);
+ bridgeService.setMaxBatchSize(1);
+ bridgeService.setMaxBatchTime(-1);
+ bridgeService.setFailureRetryInterval(-1);
+ bridgeService.setMaxRetries(-1);
+ bridgeService.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE.intValue());
+ bridgeService.setTransactionManager(tm);
+
+ return bridgeService;
+ }
+
+ // Inner classes -------------------------------------------------
+
+}
More information about the jboss-cvs-commits
mailing list