[hornetq-commits] JBoss hornetq SVN: r9959 - in trunk/examples: jms and 9 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Dec 1 07:23:38 EST 2010


Author: ataylor
Date: 2010-12-01 07:23:36 -0500 (Wed, 01 Dec 2010)
New Revision: 9959

Added:
   trunk/examples/jms/multiple-failover-failback/
   trunk/examples/jms/multiple-failover-failback/build.bat
   trunk/examples/jms/multiple-failover-failback/build.sh
   trunk/examples/jms/multiple-failover-failback/build.xml
   trunk/examples/jms/multiple-failover-failback/server0/
   trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties
   trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml
   trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml
   trunk/examples/jms/multiple-failover-failback/server0/hornetq-jms.xml
   trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml
   trunk/examples/jms/multiple-failover-failback/server1/
   trunk/examples/jms/multiple-failover-failback/server1/client-jndi.properties
   trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml
   trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml
   trunk/examples/jms/multiple-failover-failback/server1/hornetq-jms.xml
   trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml
   trunk/examples/jms/multiple-failover-failback/server2/
   trunk/examples/jms/multiple-failover-failback/server2/client-jndi.properties
   trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml
   trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml
   trunk/examples/jms/multiple-failover-failback/server2/hornetq-jms.xml
   trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml
   trunk/examples/jms/multiple-failover-failback/src/
   trunk/examples/jms/multiple-failover-failback/src/org/
   trunk/examples/jms/multiple-failover-failback/src/org/hornetq/
   trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/
   trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/
   trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java
Modified:
   trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java
Log:
added failback example

Modified: trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java
===================================================================
--- trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java	2010-12-01 11:00:36 UTC (rev 9958)
+++ trunk/examples/common/src/org/hornetq/common/example/HornetQExample.java	2010-12-01 12:23:36 UTC (rev 9959)
@@ -158,6 +158,26 @@
                                                 "hornetq-beans.xml");
    }
 
+   protected void reStartServer(final int index) throws Exception
+   {
+      String config = configs[index];
+      HornetQExample.log.info("starting server with config '" + config + "' " + "logServerOutput " + logServerOutput);
+      File f = new File(config + "/KILL_ME");
+      f.delete();
+      String debugProp = System.getProperty("server" + index);
+      boolean debugServer= "true".equals(debugProp);
+      servers[index] = SpawnedVMSupport.spawnVM(serverClasspath,
+                                                "HornetQServer_" + index,
+                                                SpawnedHornetQServer.class.getName(),
+                                                serverProps,
+                                                logServerOutput,
+                                                "STARTED::",
+                                                "FAILED::",
+                                                config,
+                                                debugServer,
+                                                "hornetq-beans.xml");
+   }
+
    protected void startServers() throws Exception
    {
       servers = new Process[configs.length];

Copied: trunk/examples/jms/multiple-failover-failback/build.bat (from rev 9955, trunk/examples/jms/multiple-failover/build.bat)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/build.bat	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/build.bat	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,13 @@
+ at echo off
+
+set "OVERRIDE_ANT_HOME=..\..\..\tools\ant"
+
+if exist "..\..\..\src\bin\build.bat" (
+   rem running from TRUNK
+   call ..\..\..\src\bin\build.bat %*
+) else (
+   rem running from the distro
+   call ..\..\..\bin\build.bat %*
+)
+
+set "OVERRIDE_ANT_HOME="

Copied: trunk/examples/jms/multiple-failover-failback/build.sh (from rev 9955, trunk/examples/jms/multiple-failover/build.sh)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/build.sh	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/build.sh	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+OVERRIDE_ANT_HOME=../../../tools/ant
+export OVERRIDE_ANT_HOME
+
+if [ -f "../../../src/bin/build.sh" ]; then
+   # running from TRUNK
+   ../../../src/bin/build.sh "$@"
+else
+   # running from the distro
+   ../../../bin/build.sh "$@"
+fi
+
+
+

Copied: trunk/examples/jms/multiple-failover-failback/build.xml (from rev 9955, trunk/examples/jms/multiple-failover/build.xml)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/build.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/build.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2009 Red Hat, Inc.
+  ~  Red Hat licenses this file to you under the Apache License, version
+  ~  2.0 (the "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+  ~  implied.  See the License for the specific language governing
+  ~  permissions and limitations under the License.
+  -->
+
+<!DOCTYPE project [
+      <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+      ]>
+
+<project default="run" name="HornetQ JMS Non-transaction Multiple Failover Example">
+
+   <import file="../../common/build.xml"/>
+
+   <target name="run" depends="delete-files">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.hornetq.jms.example.MultipleFailoverFailbackExample"/>
+         <param name="hornetq.example.beans.file" value="server0 server1 server2"/>
+      </antcall>
+   </target>
+
+   <target name="runRemote" depends="delete-files">
+      <antcall target="runExample">
+         <param name="example.classname" value="org.hornetq.jms.example.MultipleFailoverFailbackExample"/>
+         <param name="hornetq.example.runServer" value="false"/>
+      </antcall>
+   </target>
+     
+   <target name="delete-files" depends="clean">
+      <delete file="./server0/KILL_ME"/>
+      <delete file="./server1/KILL_ME"/>
+      <delete file="./server2/KILL_ME"/>
+   </target>
+
+</project>

Added: trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/client-jndi.properties	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-beans.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2009 Red Hat, Inc.
+  ~  Red Hat licenses this file to you under the Apache License, version
+  ~  2.0 (the "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+  ~  implied.  See the License for the specific language governing
+  ~  permissions and limitations under the License.
+  -->
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">1099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">1098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.hornetq.core.config.impl.FileConfiguration"/>
+
+	<!-- The security manager -->
+   <bean name="HornetQSecurityManager" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+	<!-- The core server -->
+   <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl">
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="HornetQSecurityManager"/>
+         </parameter>        
+      </constructor>
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="HornetQServer"/>
+         </parameter>         
+      </constructor>
+   </bean>
+
+</deployment>

Added: trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-configuration.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,78 @@
+<!--
+  ~ Copyright 2009 Red Hat, Inc.
+  ~  Red Hat licenses this file to you under the Apache License, version
+  ~  2.0 (the "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+  ~  implied.  See the License for the specific language governing
+  ~  permissions and limitations under the License.
+  -->
+
+<configuration xmlns="urn:hornetq"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="urn:hornetq /schema/hornetq-configuration.xsd">
+
+   <clustered>true</clustered>
+
+   <shared-store>true</shared-store>
+
+   <allow-failback>true</allow-failback>
+   <!-- Connectors -->
+
+   <connectors>
+      <connector name="netty-connector">
+         <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+         <param key="port" value="5445"/>
+      </connector>
+   </connectors>      
+
+   <!-- Acceptors -->
+   <acceptors>
+      <acceptor name="netty-acceptor">
+         <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+         <param key="port" value="5445"/>
+      </acceptor>
+   </acceptors>
+
+	<broadcast-groups>
+		<broadcast-group name="bg-group1">
+			<group-address>231.7.7.7</group-address>
+			<group-port>9876</group-port>
+			<broadcast-period>1000</broadcast-period>
+         <connector-ref>netty-connector</connector-ref>
+		</broadcast-group>
+	</broadcast-groups>
+
+	<discovery-groups>
+		<discovery-group name="dg-group1">
+			<group-address>231.7.7.7</group-address>
+			<group-port>9876</group-port>
+			<refresh-timeout>60000</refresh-timeout>
+		</discovery-group>
+	</discovery-groups>
+
+	<cluster-connections>
+		<cluster-connection name="my-cluster">
+			<address>jms</address>
+         <connector-ref>netty-connector</connector-ref>
+			<discovery-group-ref discovery-group-name="dg-group1"/>
+		</cluster-connection>
+	</cluster-connections>
+   <!-- Other config -->
+
+   <security-settings>
+      <!--security for example queue-->
+      <security-setting match="jms.queue.exampleQueue">
+         <permission type="createDurableQueue" roles="guest"/>
+         <permission type="deleteDurableQueue" roles="guest"/>
+         <permission type="createNonDurableQueue" roles="guest"/>
+         <permission type="deleteNonDurableQueue" roles="guest"/>
+         <permission type="consume" roles="guest"/>
+         <permission type="send" roles="guest"/>
+      </security-setting>
+   </security-settings>
+
+</configuration>

Added: trunk/examples/jms/multiple-failover-failback/server0/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-jms.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-jms.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,33 @@
+<configuration xmlns="urn:hornetq"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connectors>
+         <connector-ref connector-name="netty-connector"/>
+      </connectors>
+
+      <entries>
+         <entry name="ConnectionFactory"/>
+      </entries>
+       
+       <ha>true</ha>
+      <!-- Pause 1 second between connect attempts -->
+      <retry-interval>1000</retry-interval>
+
+      <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+      implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+      pause is the same length -->
+      <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+      <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+      <reconnect-attempts>-1</reconnect-attempts>
+       
+   </connection-factory>
+
+   <!--the queue used by the example-->
+   <queue name="exampleQueue">
+      <entry name="/queue/exampleQueue"/>
+   </queue>
+
+</configuration>

Added: trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server0/hornetq-users.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</configuration>
\ No newline at end of file

Added: trunk/examples/jms/multiple-failover-failback/server1/client-jndi.properties
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/client-jndi.properties	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:2099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-beans.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2009 Red Hat, Inc.
+  ~  Red Hat licenses this file to you under the Apache License, version
+  ~  2.0 (the "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+  ~  implied.  See the License for the specific language governing
+  ~  permissions and limitations under the License.
+  -->
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">2099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">2098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.hornetq.core.config.impl.FileConfiguration"/>
+
+	<!-- The security manager -->
+   <bean name="HornetQSecurityManager" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+	<!-- The core server -->
+   <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl">
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="HornetQSecurityManager"/>
+         </parameter>        
+      </constructor>
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="HornetQServer"/>
+         </parameter>         
+      </constructor>
+   </bean>
+
+</deployment>

Added: trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-configuration.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,86 @@
+<!--
+  ~ Copyright 2009 Red Hat, Inc.
+  ~  Red Hat licenses this file to you under the Apache License, version
+  ~  2.0 (the "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+  ~  implied.  See the License for the specific language governing
+  ~  permissions and limitations under the License.
+  -->
+
+<configuration xmlns="urn:hornetq"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="urn:hornetq ../../../src/schema/hornetq-configuration.xsd">
+
+   <clustered>true</clustered>
+
+   <backup>true</backup>
+
+   <shared-store>true</shared-store>
+
+   <allow-failback>true</allow-failback>
+
+    <!-- Connectors -->
+
+   <connectors>
+      <connector name="netty-connector">
+         <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+         <param key="port" value="5446"/>
+      </connector>
+   </connectors>
+   
+   <!-- Acceptors -->
+   <acceptors>
+      <acceptor name="netty-acceptor">
+         <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+         <param key="port" value="5446"/>
+      </acceptor>
+   </acceptors>
+
+    <broadcast-groups>
+		<broadcast-group name="bg-group1">
+			<group-address>231.7.7.7</group-address>
+			<group-port>9876</group-port>
+			<broadcast-period>1000</broadcast-period>
+         <connector-ref>netty-connector</connector-ref>
+		</broadcast-group>
+	</broadcast-groups>
+
+	<discovery-groups>
+		<discovery-group name="dg-group1">
+			<group-address>231.7.7.7</group-address>
+			<group-port>9876</group-port>
+			<refresh-timeout>60000</refresh-timeout>
+		</discovery-group>
+	</discovery-groups>
+
+	<cluster-connections>
+		<cluster-connection name="my-cluster">
+			<address>jms</address>
+         <connector-ref>netty-connector</connector-ref>
+			<discovery-group-ref discovery-group-name="dg-group1"/>
+		</cluster-connection>
+	</cluster-connections>
+   <!-- Other config -->
+
+   <large-messages-directory>../server0/data/large-messages</large-messages-directory>
+   <bindings-directory>../server0/data/bindings</bindings-directory>
+   <journal-directory>../server0/data/journal</journal-directory>
+   <paging-directory>../server0/data/paging</paging-directory>
+    
+   <security-settings>
+      <!--security for example queue-->
+      <security-setting match="jms.queue.exampleQueue">
+         <permission type="createDurableQueue" roles="guest"/>
+         <permission type="deleteDurableQueue" roles="guest"/>
+         <permission type="createNonDurableQueue" roles="guest"/>
+         <permission type="deleteNonDurableQueue" roles="guest"/>
+         <permission type="consume" roles="guest"/>
+         <permission type="send" roles="guest"/>
+      </security-setting>
+   </security-settings>
+   
+</configuration>

Added: trunk/examples/jms/multiple-failover-failback/server1/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-jms.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-jms.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,32 @@
+<configuration xmlns="urn:hornetq"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connectors>
+         <connector-ref connector-name="netty-connector"/>
+      </connectors>
+
+      <entries>
+         <entry name="ConnectionFactory"/>
+      </entries>
+       
+       <ha>true</ha>
+      <!-- Pause 1 second between connect attempts -->
+      <retry-interval>1000</retry-interval>
+
+      <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+      implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+      pause is the same length -->
+      <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+      <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+      <reconnect-attempts>-1</reconnect-attempts>
+   </connection-factory>
+
+   <!--the queue used by the example-->
+   <queue name="exampleQueue">
+      <entry name="/queue/exampleQueue"/>
+   </queue>
+
+</configuration>

Added: trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server1/hornetq-users.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</configuration>
\ No newline at end of file

Added: trunk/examples/jms/multiple-failover-failback/server2/client-jndi.properties
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/client-jndi.properties	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/client-jndi.properties	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,16 @@
+#
+# Copyright 2009 Red Hat, Inc.
+#  Red Hat licenses this file to you under the Apache License, version
+#  2.0 (the "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#     http://www.apache.org/licenses/LICENSE-2.0
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+#  implied.  See the License for the specific language governing
+#  permissions and limitations under the License.
+#
+
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:3099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Added: trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-beans.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2009 Red Hat, Inc.
+  ~  Red Hat licenses this file to you under the Apache License, version
+  ~  2.0 (the "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+  ~  implied.  See the License for the specific language governing
+  ~  permissions and limitations under the License.
+  -->
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+   <!-- JNDI server. Disable this if you don't want JNDI -->
+   <bean name="JNDIServer" class="org.jnp.server.Main">
+      <property name="namingInfo">
+         <inject bean="Naming"/>
+      </property>
+      <property name="port">3099</property>
+      <property name="bindAddress">localhost</property>
+      <property name="rmiPort">3098</property>
+      <property name="rmiBindAddress">localhost</property>
+   </bean>
+   
+   <!-- MBean server -->
+   <bean name="MBeanServer" class="javax.management.MBeanServer">
+      <constructor factoryClass="java.lang.management.ManagementFactory"
+                   factoryMethod="getPlatformMBeanServer"/>
+   </bean> 
+
+   <!-- The core configuration -->
+   <bean name="Configuration" class="org.hornetq.core.config.impl.FileConfiguration"/>
+
+	<!-- The security manager -->
+   <bean name="HornetQSecurityManager" class="org.hornetq.spi.core.security.HornetQSecurityManagerImpl">
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+
+	<!-- The core server -->
+   <bean name="HornetQServer" class="org.hornetq.core.server.impl.HornetQServerImpl">
+      <constructor>
+         <parameter>
+            <inject bean="Configuration"/>
+         </parameter>
+         <parameter>
+            <inject bean="MBeanServer"/>
+         </parameter>
+         <parameter>
+            <inject bean="HornetQSecurityManager"/>
+         </parameter>        
+      </constructor>
+      <start ignored="true"/>
+      <stop ignored="true"/>
+   </bean>
+   
+   <!-- The JMS server -->
+   <bean name="JMSServerManager" class="org.hornetq.jms.server.impl.JMSServerManagerImpl">
+      <constructor>         
+         <parameter>
+            <inject bean="HornetQServer"/>
+         </parameter>         
+      </constructor>
+   </bean>
+
+</deployment>

Added: trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-configuration.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,85 @@
+<!--
+  ~ Copyright 2009 Red Hat, Inc.
+  ~  Red Hat licenses this file to you under the Apache License, version
+  ~  2.0 (the "License"); you may not use this file except in compliance
+  ~  with the License.  You may obtain a copy of the License at
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~  Unless required by applicable law or agreed to in writing, software
+  ~  distributed under the License is distributed on an "AS IS" BASIS,
+  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+  ~  implied.  See the License for the specific language governing
+  ~  permissions and limitations under the License.
+  -->
+
+<configuration xmlns="urn:hornetq"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="urn:hornetq ../../../src/schema/hornetq-configuration.xsd">
+   <!-- Connectors -->
+
+   <clustered>true</clustered>
+
+   <backup>true</backup>
+
+   <shared-store>true</shared-store>
+
+   <allow-failback>true</allow-failback>
+    
+   <connectors>
+      <connector name="netty-connector">
+         <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
+         <param key="port" value="5447"/>
+      </connector>
+   </connectors>
+   
+   <!-- Acceptors -->
+   <acceptors>
+      <acceptor name="netty-acceptor">
+         <factory-class>org.hornetq.core.remoting.impl.netty.NettyAcceptorFactory</factory-class>
+         <param key="port" value="5447"/>
+      </acceptor>
+   </acceptors>
+
+    <broadcast-groups>
+		<broadcast-group name="bg-group1">
+			<group-address>231.7.7.7</group-address>
+			<group-port>9876</group-port>
+			<broadcast-period>1000</broadcast-period>
+         <connector-ref>netty-connector</connector-ref>
+		</broadcast-group>
+	</broadcast-groups>
+
+	<discovery-groups>
+		<discovery-group name="dg-group1">
+			<group-address>231.7.7.7</group-address>
+			<group-port>9876</group-port>
+			<refresh-timeout>60000</refresh-timeout>
+		</discovery-group>
+	</discovery-groups>
+
+	<cluster-connections>
+		<cluster-connection name="my-cluster">
+			<address>jms</address>
+         <connector-ref>netty-connector</connector-ref>
+			<discovery-group-ref discovery-group-name="dg-group1"/>
+		</cluster-connection>
+	</cluster-connections>
+
+   <large-messages-directory>../server0/data/large-messages</large-messages-directory>
+   <bindings-directory>../server0/data/bindings</bindings-directory>
+   <journal-directory>../server0/data/journal</journal-directory>
+   <paging-directory>../server0/data/paging</paging-directory> 
+   <!-- Other config -->
+
+   <security-settings>
+      <!--security for example queue-->
+      <security-setting match="jms.queue.exampleQueue">
+         <permission type="createDurableQueue" roles="guest"/>
+         <permission type="deleteDurableQueue" roles="guest"/>
+         <permission type="createNonDurableQueue" roles="guest"/>
+         <permission type="deleteNonDurableQueue" roles="guest"/>
+         <permission type="consume" roles="guest"/>
+         <permission type="send" roles="guest"/>
+      </security-setting>
+   </security-settings>
+   
+</configuration>

Added: trunk/examples/jms/multiple-failover-failback/server2/hornetq-jms.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-jms.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-jms.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,32 @@
+<configuration xmlns="urn:hornetq"
+            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+   <!--the connection factory used by the example-->
+   <connection-factory name="ConnectionFactory">
+      <connectors>
+         <connector-ref connector-name="netty-connector"/>
+      </connectors>
+
+      <entries>
+         <entry name="ConnectionFactory"/>
+      </entries>
+
+      <ha>true</ha>
+      <!-- Pause 1 second between connect attempts -->
+      <retry-interval>1000</retry-interval>
+
+      <!-- Multiply subsequent reconnect pauses by this multiplier. This can be used to
+      implement an exponential back-off. For our purposes we just set to 1.0 so each reconnect
+      pause is the same length -->
+      <retry-interval-multiplier>1.0</retry-interval-multiplier>
+
+      <!-- Try reconnecting an unlimited number of times (-1 means "unlimited") -->
+      <reconnect-attempts>-1</reconnect-attempts>
+   </connection-factory>
+
+   <!--the queue used by the example-->
+   <queue name="exampleQueue">
+      <entry name="/queue/exampleQueue"/>
+   </queue>
+
+</configuration>

Added: trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml
===================================================================
--- trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/server2/hornetq-users.xml	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:hornetq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xsi:schemaLocation="urn:hornetq /schema/hornetq-users.xsd">
+   <!-- the default user.  this is used where username is null-->
+   <defaultuser name="guest" password="guest">
+      <role name="guest"/>
+   </defaultuser>
+</configuration>
\ No newline at end of file

Copied: trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java (from rev 9957, trunk/examples/jms/multiple-failover/src/org/hornetq/jms/example/MultipleFailoverExample.java)
===================================================================
--- trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java	                        (rev 0)
+++ trunk/examples/jms/multiple-failover-failback/src/org/hornetq/jms/example/MultipleFailoverFailbackExample.java	2010-12-01 12:23:36 UTC (rev 9959)
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ *  Red Hat licenses this file to you under the Apache License, version
+ *  2.0 (the "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ *  implied.  See the License for the specific language governing
+ *  permissions and limitations under the License.
+ */
+
+package org.hornetq.jms.example;
+
+import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.common.example.HornetQExample;
+import org.hornetq.core.client.impl.DelegatingSession;
+import org.hornetq.jms.client.HornetQConnection;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+
+/**
+ * @author <a href="mailto:andy.taylor at jboss.com">Andy Taylor</a>
+ *         Date: Nov 4, 2010
+ *         Time: 10:51:45 AM
+ */
+public class MultipleFailoverFailbackExample extends HornetQExample
+{
+   public static void main(final String[] args)
+   {
+      new MultipleFailoverFailbackExample().run(args);
+   }
+   
+   @Override
+   public boolean runExample() throws Exception
+   {
+      final int numMessages = 30;
+
+      Connection connection = null;
+
+      InitialContext initialContext = null;
+
+      try
+      {
+         // Step 1. Get an initial context for looking up JNDI from the server #1
+         initialContext = getContext(0);
+
+         // Step 2. Look up the JMS resources from JNDI
+         Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
+         ConnectionFactory connectionFactory = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+         // Step 3. Create a JMS Connection
+         connection = connectionFactory.createConnection();
+
+         // Step 4. Create a *non-transacted* JMS Session with client acknwoledgement
+         Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+
+         // Step 5. Start the connection to ensure delivery occurs
+         connection.start();
+
+         // Step 6. Create a JMS MessageProducer and a MessageConsumer
+         MessageProducer producer = session.createProducer(queue);
+         MessageConsumer consumer = session.createConsumer(queue);
+
+         // Step 7. Send some messages to server #1, the live server
+         for (int i = 0; i < numMessages; i++)
+         {
+            TextMessage message = session.createTextMessage("This is text message " + i);
+            producer.send(message);
+            System.out.println("Sent message: " + message.getText());
+         }
+
+         // Step 8. Receive and acknowledge a third of the sent messages
+         TextMessage message0 = null;
+         for (int i = 0; i < numMessages / 3; i++)
+         {
+            message0 = (TextMessage)consumer.receive(5000);
+            System.out.println("Got message: " + message0.getText());
+         }
+         message0.acknowledge();
+
+         // Step 9. Receive the rest third of the sent messages but *do not* acknowledge them yet
+         for (int i = numMessages / 3; i < numMessages; i++)
+         {
+            message0 = (TextMessage)consumer.receive(5000);
+            System.out.println("Got message: " + message0.getText());
+         }
+
+         // Step 10. Crash server #1, the live server, and wait a little while to make sure
+         // it has really crashed
+         Thread.sleep(2000);
+         killServer(0);
+
+         // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
+         // backup server has occurred
+         try
+         {
+            message0.acknowledge();
+         }
+         catch (JMSException e)
+         {
+            System.err.println("Got exception while acknowledging message: " + e.getMessage());
+         }
+
+         // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+         for (int i = numMessages / 3; i < (numMessages / 3) * 2; i++)
+         {
+            message0 = (TextMessage)consumer.receive(5000);
+            System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
+         }
+         message0.acknowledge();
+
+         Thread.sleep(2000);
+         reStartServer(0);
+
+         // Step 11. Acknowledging the 2nd half of the sent messages will fail as failover to the
+         // backup server has occurred
+         try
+         {
+            message0.acknowledge();
+         }
+         catch (JMSException e)
+         {
+            System.err.println("Got exception while acknowledging message: " + e.getMessage());
+         }
+
+         // Step 12. Consume again the 2nd third of the messages again. Note that they are not considered as redelivered.
+         for (int i = (numMessages / 3) * 2; i < numMessages; i++)
+         {
+            message0 = (TextMessage)consumer.receive(5000);
+            System.out.printf("Got message: %s (redelivered?: %s)\n", message0.getText(), message0.getJMSRedelivered());
+         }
+         message0.acknowledge();
+
+         return true;
+      }
+      finally
+      {
+         // Step 13. Be sure to close our resources!
+
+         if (connection != null)
+         {
+            connection.close();
+         }
+
+         if (initialContext != null)
+         {
+            initialContext.close();
+         }
+      }
+   }
+
+   private int getServer(Connection connection)
+   {
+      DelegatingSession session = (DelegatingSession) ((HornetQConnection) connection).getInitialSession();
+      TransportConfiguration transportConfiguration = session.getSessionFactory().getConnectorConfiguration();
+      String port = (String) transportConfiguration.getParams().get("port");
+      return Integer.valueOf(port) - 5445;
+   }
+}



More information about the hornetq-commits mailing list