[jboss-cvs] JBoss Messaging SVN: r1467 - in branches/Branch_Client_Failover_Experiment: src/main/org/jboss/jms/client/container tests/src/org/jboss/test/messaging/jms/ha
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Oct 10 19:30:27 EDT 2006
Author: clebert.suconic at jboss.com
Date: 2006-10-10 19:30:24 -0400 (Tue, 10 Oct 2006)
New Revision: 1467
Modified:
branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/HATestBase.java
branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/ReconnectTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-519 - experiments - recreating Producer Delegate
Modified: branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java 2006-10-10 23:01:33 UTC (rev 1466)
+++ branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java 2006-10-10 23:30:24 UTC (rev 1467)
@@ -34,8 +34,12 @@
import org.jboss.jms.client.delegate.ClientSessionDelegate;
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.client.state.SessionState;
+import org.jboss.jms.client.state.HierarchicalStateSupport;
+import org.jboss.jms.client.state.ProducerState;
import org.jboss.jms.message.MessageIdGeneratorFactory;
import org.jboss.jms.tx.ResourceManagerFactory;
+import org.jboss.jms.delegate.ProducerDelegate;
+import org.jboss.jms.destination.JBossDestination;
import org.jboss.logging.Logger;
import org.jboss.remoting.Client;
import org.jboss.remoting.ConnectionListener;
@@ -192,7 +196,7 @@
{
if (log.isTraceEnabled())
{
- log.trace("Calling handleFailoever");
+ log.trace("Calling handleFailover");
}
ClientConnectionDelegate otherConnection = (ClientConnectionDelegate)((MethodInvocation)invocation).getArguments()[0];
@@ -212,13 +216,25 @@
SessionState sessionState = (SessionState)sessionsIterator.next();
ClientSessionDelegate newSessionDelegate=(ClientSessionDelegate)otherConnection.createSessionDelegate(sessionState.isTransacted(),sessionState.getAcknowledgeMode(),sessionState.isXA());
+ // don't know if I will need that or not
+ ClientSessionDelegate oldSessionDelegate = (ClientSessionDelegate)sessionState.getDelegate();
+ sessionState.setDelegate(newSessionDelegate);
if (log.isTraceEnabled())
{
- log.trace("Replacing session by a new session created on the new failed over connection - " + newSessionDelegate);
+ log.trace("Replacing session (" + oldSessionDelegate + ") by a new session created on the new failed over connection (" + newSessionDelegate + ")");
}
- sessionState.setDelegate(newSessionDelegate);
+ Iterator sessionObjectsIterator = sessionState.getChildren().iterator();
+ while (sessionObjectsIterator.hasNext())
+ {
+ HierarchicalStateSupport sessionChild = (HierarchicalStateSupport)sessionObjectsIterator.next();
+
+ if (sessionChild instanceof ProducerState)
+ {
+ handleFailoverOnProducer((ProducerState)sessionChild, newSessionDelegate, oldSessionDelegate);
+ }
+ }
}
@@ -226,8 +242,19 @@
return null;
}
- // ConnectionListener implementation -----------------------------------------------------------
+ private void handleFailoverOnProducer(ProducerState producerState, ClientSessionDelegate newSessionDelegate, ClientSessionDelegate oldSessionDelegate) throws JMSException {
+ ProducerDelegate newProducerDelegate = newSessionDelegate.createProducerDelegate((JBossDestination)producerState.getDestination());
+ // don't know if I will need that or not
+ ProducerDelegate oldProducerDelegate = (ProducerDelegate)producerState.getDelegate();
+ producerState.setDelegate((DelegateSupport)newProducerDelegate);
+ if (log.isTraceEnabled())
+ {
+ log.trace("Replacing producerDelegate on oldSession=" + oldSessionDelegate + " destination=" + producerState.getDestination());
+ }
+ }
+ // ConnectionListener implementation -----------------------------------------------------------
+
public void handleConnectionException(Throwable t, Client c)
{
log.error("Caught exception from connection", t);
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/HATestBase.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/HATestBase.java 2006-10-10 23:01:33 UTC (rev 1466)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/HATestBase.java 2006-10-10 23:30:24 UTC (rev 1467)
@@ -41,7 +41,10 @@
protected ConnectionFactory factoryServer1;
protected ConnectionFactory factoryServer2;
+ protected Context ctx1;
+ protected Context ctx2;
+
protected String host1=System.getProperty("HOST1","localhost");
protected String host2=System.getProperty("HOST2","localhost");
@@ -49,8 +52,8 @@
{
super.setUp();
- Context ctx1 = getContext(host1);
- Context ctx2 = getContext(host2);
+ ctx1 = getContext(host1);
+ ctx2 = getContext(host2);
factoryServer1 = (ConnectionFactory)ctx1.lookup("/ConnectionFactory");
factoryServer2 = (ConnectionFactory)ctx2.lookup("/ConnectionFactory");
@@ -87,5 +90,12 @@
return host2;
}
+ public Context getCtx1() {
+ return ctx1;
+ }
+ public Context getCtx2() {
+ return ctx2;
+ }
+
}
Modified: branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/ReconnectTest.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/ReconnectTest.java 2006-10-10 23:01:33 UTC (rev 1466)
+++ branches/Branch_Client_Failover_Experiment/tests/src/org/jboss/test/messaging/jms/ha/ReconnectTest.java 2006-10-10 23:30:24 UTC (rev 1467)
@@ -4,9 +4,7 @@
import org.jboss.jms.client.state.ConnectionState;
import org.jboss.jms.client.delegate.ClientConnectionDelegate;
-import javax.jms.ConnectionFactory;
-import javax.jms.Connection;
-import javax.jms.Session;
+import javax.jms.*;
public class ReconnectTest extends HATestBase
{
@@ -21,15 +19,35 @@
conn.getDelegate().failOver(conn2.getDelegate());
}
- public void testSimpleWithSession() throws Exception
+ public void testWithSession() throws Exception
{
JBossConnection conn = (JBossConnection)this.factoryServer1.createConnection();
Session session = conn.createSession(true,Session.AUTO_ACKNOWLEDGE);
-
+
ClientConnectionDelegate delegate = (ClientConnectionDelegate)conn.getDelegate();
ConnectionState state = (ConnectionState)delegate.getState();
JBossConnection conn2 = (JBossConnection)this.factoryServer1.createConnection();
conn.getDelegate().failOver(conn2.getDelegate());
}
+
+ public void testSimpleWithOneProducer() throws Exception
+ {
+ JBossConnection conn = (JBossConnection)this.factoryServer1.createConnection();
+ Session session = conn.createSession(true,Session.AUTO_ACKNOWLEDGE);
+ Destination destination = (Destination)getCtx1().lookup("topic/testTopic");
+ MessageProducer producer = session.createProducer(destination);
+
+ Message message = session.createTextMessage("Hello");
+ producer.send(message);
+
+ ClientConnectionDelegate delegate = (ClientConnectionDelegate)conn.getDelegate();
+ ConnectionState state = (ConnectionState)delegate.getState();
+
+ JBossConnection conn2 = (JBossConnection)this.factoryServer1.createConnection();
+ conn.getDelegate().failOver(conn2.getDelegate());
+
+ message = session.createTextMessage("Hello");
+ producer.send(message);
+ }
}
More information about the jboss-cvs-commits
mailing list