[jboss-cvs] JBoss Messaging SVN: r1468 - in branches/Branch_Client_Failover_Experiment/src: etc main/org/jboss/jms/client/container main/org/jboss/jms/client/state
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 11 15:46:41 EDT 2006
Author: clebert.suconic at jboss.com
Date: 2006-10-11 15:46:37 -0400 (Wed, 11 Oct 2006)
New Revision: 1468
Modified:
branches/Branch_Client_Failover_Experiment/src/etc/aop-messaging-client.xml
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/state/ConnectionState.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-519 - working with Producers and ConnectionState for connection recreation
Modified: branches/Branch_Client_Failover_Experiment/src/etc/aop-messaging-client.xml
===================================================================
--- branches/Branch_Client_Failover_Experiment/src/etc/aop-messaging-client.xml 2006-10-10 23:30:24 UTC (rev 1467)
+++ branches/Branch_Client_Failover_Experiment/src/etc/aop-messaging-client.xml 2006-10-11 19:46:37 UTC (rev 1468)
@@ -35,9 +35,15 @@
<interceptor-ref name="org.jboss.jms.client.container.ExceptionInterceptor"/>
<interceptor-ref name="org.jboss.jms.client.container.ClosedInterceptor"/>
</bind>
- <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientConnectionDelegate->failOver(..))">
- <advice name="handleFailover" aspect="org.jboss.jms.client.container.ConnectionAspect"/>
- </bind>
+ <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientConnectionDelegate->start())">
+ <advice name="handleStart" aspect="org.jboss.jms.client.container.ConnectionAspect"/>
+ </bind>
+ <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientConnectionDelegate->stop())">
+ <advice name="handleStop" aspect="org.jboss.jms.client.container.ConnectionAspect"/>
+ </bind>
+ <bind pointcut="execution(* org.jboss.jms.client.delegate.ClientConnectionDelegate->failOver(..))">
+ <advice name="handleFailover" aspect="org.jboss.jms.client.container.ConnectionAspect"/>
+ </bind>
<bind pointcut="execution(* org.jboss.jms.client.delegate.ClientConnectionDelegate->createConnectionConsumer(..))">
<advice name="handleCreateConnectionConsumer" aspect="org.jboss.jms.client.container.AsfAspect"/>
</bind>
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:30:24 UTC (rev 1467)
+++ branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/container/ConnectionAspect.java 2006-10-11 19:46:37 UTC (rev 1468)
@@ -68,16 +68,11 @@
// Attributes ----------------------------------------------------
- protected String clientID;
- protected ExceptionListener exceptionListener;
+ protected JBossConnectionMetaData connMetaData;
- protected ConnectionMetaData connMetaData;
+ protected ConnectionState state;
- boolean justCreated = true;
-
- protected boolean listenerAdded;
-
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@@ -86,32 +81,36 @@
public Object handleGetClientID(Invocation invocation) throws Throwable
{
- justCreated = false;
+ ConnectionState currentState = getConnectionState(invocation);
- if (clientID == null)
+ currentState.setJustCreated(false);
+
+ if (currentState.getClientID() == null)
{
//Get from the server
- clientID = (String)invocation.invokeNext();
+ currentState.setClientID((String)invocation.invokeNext());
}
- return clientID;
+ return currentState.getClientID();
}
public Object handleSetClientID(Invocation invocation) throws Throwable
{
- if (clientID != null)
+ ConnectionState currentState = getConnectionState(invocation);
+
+ if (currentState.getClientID() != null)
{
throw new IllegalStateException("Client id has already been set");
}
- if (!justCreated)
+ if (!currentState.isJustCreated())
{
throw new IllegalStateException("setClientID can only be called directly after the connection is created");
}
MethodInvocation mi = (MethodInvocation)invocation;
- clientID = (String)mi.getArguments()[0];
+ currentState.setClientID((String)mi.getArguments()[0]);
- justCreated = false;
+ currentState.setJustCreated(false);
// this gets invoked on the server too
return invocation.invokeNext();
@@ -119,34 +118,36 @@
public Object handleGetExceptionListener(Invocation invocation) throws Throwable
{
- justCreated = false;
+ ConnectionState currentState = getConnectionState(invocation);
+ currentState.setJustCreated(false);
- return exceptionListener;
+ return currentState.getExceptionListener();
}
public Object handleSetExceptionListener(Invocation invocation) throws Throwable
{
- justCreated = false;
+ ConnectionState currentState = getConnectionState(invocation);
+ currentState.setJustCreated(false);
MethodInvocation mi = (MethodInvocation)invocation;
- exceptionListener = (ExceptionListener)mi.getArguments()[0];
+ currentState.setExceptionListener((ExceptionListener)mi.getArguments()[0]);
- Client client = getState(invocation).getRemotingConnection().getInvokingClient();
+ Client client = getConnectionState(invocation).getRemotingConnection().getInvokingClient();
if (client == null)
{
throw new java.lang.IllegalStateException("Cannot find remoting client");
}
- if (exceptionListener != null)
+ if (currentState.getExceptionListener() != null)
{
client.addConnectionListener(this);
- listenerAdded = true;
+ currentState.setListenerAdded(true);
}
else
{
- if (listenerAdded)
+ if (currentState.isListenerAdded())
{
client.removeConnectionListener(this);
}
@@ -156,28 +157,44 @@
public Object handleGetConnectionMetaData(Invocation invocation) throws Throwable
{
- justCreated = false;
+ ConnectionState currentState = getConnectionState(invocation);
+ currentState.setJustCreated(false);
- if (connMetaData == null)
- {
- ClientConnectionDelegate delegate = (ClientConnectionDelegate)invocation.getTargetObject();
- connMetaData = new JBossConnectionMetaData(((ConnectionState)delegate.getState()).getVersionToUse());
- }
+ if (connMetaData == null)
+ {
+ ClientConnectionDelegate delegate = (ClientConnectionDelegate)invocation.getTargetObject();
+ connMetaData = new JBossConnectionMetaData(((ConnectionState)delegate.getState()).getVersionToUse());
+ }
- return connMetaData;
+ return connMetaData;
}
- public Object handleCreateSessionDelegate(Invocation invocation) throws Throwable
- {
- justCreated = false;
- return invocation.invokeNext();
- }
+ public Object handleStart(Invocation invocation) throws Throwable
+ {
+ ConnectionState currentState = getConnectionState(invocation);
+ currentState.setStarted(true);
+ return invocation.invokeNext();
+ }
+ public Object handleStop(Invocation invocation) throws Throwable
+ {
+ ConnectionState currentState = getConnectionState(invocation);
+ currentState.setStarted(false);
+ return invocation.invokeNext();
+ }
+
+ public Object handleCreateSessionDelegate(Invocation invocation) throws Throwable
+ {
+ ConnectionState currentState = getConnectionState(invocation);
+ currentState.setJustCreated(false);
+ return invocation.invokeNext();
+ }
+
public Object handleClose(Invocation invocation) throws Throwable
{
Object ret = invocation.invokeNext();
- ConnectionState state = getState(invocation);
+ ConnectionState state = getConnectionState(invocation);
// Finished with the connection - we need to shutdown callback server
state.getRemotingConnection().stop();
@@ -199,16 +216,22 @@
log.trace("Calling handleFailover");
}
+ ClientConnectionDelegate currentDelegate = ((ClientConnectionDelegate)invocation.getTargetObject());
+ ConnectionState currentState = (ConnectionState)currentDelegate.getState();
+
+
ClientConnectionDelegate otherConnection = (ClientConnectionDelegate)((MethodInvocation)invocation).getArguments()[0];
ConnectionState otherConnectionState = (ConnectionState)((ClientConnectionDelegate)otherConnection).getState();
+ if (currentState.getClientID()!=null)
+ {
+ otherConnection.setClientID(currentState.getClientID());
+ }
+
JMSRemotingConnection newRemoting = otherConnectionState.getRemotingConnection();
- ClientConnectionDelegate currentDelegate = ((ClientConnectionDelegate)invocation.getTargetObject());
currentDelegate.setRemotingConnection(newRemoting);
- ConnectionState currentState = (ConnectionState)currentDelegate.getState();
-
Iterator sessionsIterator = currentState.getChildren().iterator();
while(sessionsIterator.hasNext())
@@ -216,10 +239,12 @@
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 (" + oldSessionDelegate + ") by a new session created on the new failed over connection (" + newSessionDelegate + ")");
@@ -259,7 +284,7 @@
{
log.error("Caught exception from connection", t);
- if (exceptionListener != null)
+ if (state.getExceptionListener()!= null)
{
JMSException j = null;
if (t instanceof Error)
@@ -281,9 +306,9 @@
log.error(msg, t);
j = new JMSException(msg + ": " + t.getMessage());
}
- synchronized (exceptionListener)
+ synchronized (state.getExceptionListener())
{
- exceptionListener.onException(j);
+ state.getExceptionListener().onException(j);
}
}
}
@@ -294,10 +319,16 @@
// Private -------------------------------------------------------
- private ConnectionState getState(Invocation inv)
- {
- return (ConnectionState)((DelegateSupport)inv.getTargetObject()).getState();
- }
+ private ConnectionState getConnectionState(Invocation invocation) {
+ if (state==null)
+ {
+ ClientConnectionDelegate currentDelegate = ((ClientConnectionDelegate)invocation.getTargetObject());
+ state = (ConnectionState)currentDelegate.getState();
+ }
+ return state;
+ }
+
+
// Inner classes -------------------------------------------------
}
Modified: branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/state/ConnectionState.java
===================================================================
--- branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/state/ConnectionState.java 2006-10-10 23:30:24 UTC (rev 1467)
+++ branches/Branch_Client_Failover_Experiment/src/main/org/jboss/jms/client/state/ConnectionState.java 2006-10-11 19:46:37 UTC (rev 1468)
@@ -34,6 +34,8 @@
import EDU.oswego.cs.dl.util.concurrent.SyncSet;
import EDU.oswego.cs.dl.util.concurrent.WriterPreferenceReadWriteLock;
+import javax.jms.ExceptionListener;
+
/**
*
* State corresponding to a connection. This state is acessible inside aspects/interceptors.
@@ -47,51 +49,68 @@
public class ConnectionState extends HierarchicalStateSupport
{
private static final Logger log = Logger.getLogger(ConnectionState.class);
-
+
private JMSRemotingConnection remotingConnection;
-
+
private ResourceManager resourceManager;
-
+
private MessageIdGenerator idGenerator;
-
+
private int serverID;
-
+
private Version versionToUse;
private ConnectionDelegate delegate;
-
+
+ protected boolean started;
+
+
+ /** This property used to be delcared on ConnectionAspect */
+ private String clientID;
+
+ /** This property used to be delcared on ConnectionAspect */
+ private ExceptionListener exceptionListener;
+
+ /** This property used to be delcared on ConnectionAspect */
+ private boolean justCreated = true;
+
+ /** This property used to be delcared on ConnectionAspect */
+ private boolean listenerAdded;
+
+
+
public ConnectionState(int serverID, ConnectionDelegate delegate,
JMSRemotingConnection remotingConnection, Version versionToUse,
ResourceManager rm, MessageIdGenerator gen)
throws Exception
{
super(null, (DelegateSupport)delegate);
-
+
if (log.isTraceEnabled()) { log.trace("Creating connection state"); }
-
+
children = new SyncSet(new HashSet(), new WriterPreferenceReadWriteLock());
-
+
this.remotingConnection = remotingConnection;
-
+
this.versionToUse = versionToUse;
-
+
this.resourceManager = rm;
-
+
this.idGenerator = gen;
-
+
this.serverID = serverID;
}
-
+
public ResourceManager getResourceManager()
{
return resourceManager;
}
-
+
public MessageIdGenerator getIdGenerator()
{
return idGenerator;
}
-
+
public JMSRemotingConnection getRemotingConnection()
{
return remotingConnection;
@@ -101,12 +120,12 @@
{
this.remotingConnection=remotingConnection;
}
-
+
public Version getVersionToUse()
{
return versionToUse;
}
-
+
public int getServerID()
{
return serverID;
@@ -128,11 +147,51 @@
{
}
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void setStarted(boolean started) {
+ this.started = started;
+ }
+
+ public String getClientID() {
+ return clientID;
+ }
+
+ public void setClientID(String clientID) {
+ this.clientID = clientID;
+ }
+
+ public ExceptionListener getExceptionListener() {
+ return exceptionListener;
+ }
+
+ public void setExceptionListener(ExceptionListener exceptionListener) {
+ this.exceptionListener = exceptionListener;
+ }
+
+ public boolean isJustCreated() {
+ return justCreated;
+ }
+
+ public void setJustCreated(boolean justCreated) {
+ this.justCreated = justCreated;
+ }
+
+ public boolean isListenerAdded() {
+ return listenerAdded;
+ }
+
+ public void setListenerAdded(boolean listenerAdded) {
+ this.listenerAdded = listenerAdded;
+ }
+
/** Connection doesn't have a parent */
public HierarchicalState getParent()
{
return null;
}
-
+
}
More information about the jboss-cvs-commits
mailing list