[jboss-cvs] JBossAS SVN: r111643 - branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Jun 20 14:01:52 EDT 2011
Author: jesper.pedersen
Date: 2011-06-20 14:01:52 -0400 (Mon, 20 Jun 2011)
New Revision: 111643
Added:
branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/ReentrantLock.java
Modified:
branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsManagedConnection.java
branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsSession.java
Log:
[JBPAPP-6742] Changed generic JMS resource adapter
Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsManagedConnection.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsManagedConnection.java 2011-06-20 17:30:46 UTC (rev 111642)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsManagedConnection.java 2011-06-20 18:01:52 UTC (rev 111643)
@@ -22,13 +22,13 @@
package org.jboss.resource.adapter.jms;
import java.io.PrintWriter;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.ReentrantLock;
import javax.jms.Connection;
import javax.jms.ExceptionListener;
@@ -355,11 +355,39 @@
// destory handles
destroyHandles();
- // I'm recreating the lock object when we return to the pool
- // because it looks too nasty to expect the connection handle
- // to unlock properly in certain race conditions
- // where the dissociation of the managed connection is "random".
- lock = new ReentrantLock(true);
+ boolean isActive = false;
+
+ if (lock.hasQueuedThreads())
+ {
+ Collection<Thread> threads = lock.getQueuedThreads();
+ for (Thread thread : threads)
+ {
+ Throwable t = new Throwable("Thread waiting for lock during cleanup");
+ t.setStackTrace(thread.getStackTrace());
+
+ log.warn(t.getMessage(), t);
+ }
+
+ isActive = true;
+ }
+
+ if (lock.isLocked())
+ {
+ Throwable t = new Throwable("Lock owned during cleanup");
+ t.setStackTrace(lock.getOwner().getStackTrace());
+
+ log.warn(t.getMessage(), t);
+
+ isActive = true;
+ }
+
+ if (isActive)
+ {
+ // There are active lock - make sure that the JCA container kills
+ // this handle by throwing an exception
+
+ throw new ResourceException("Still active locks for " + this);
+ }
}
/**
@@ -414,8 +442,19 @@
protected void unlock()
{
- if (lock.isHeldByCurrentThread())
+ if (lock.isLocked())
+ {
lock.unlock();
+ }
+ else
+ {
+ log.warn("Owner is null");
+
+ Throwable t = new Throwable("Thread trying to unlock");
+ t.setStackTrace(Thread.currentThread().getStackTrace());
+
+ log.warn(t.getMessage(), t);
+ }
}
/**
@@ -546,6 +585,12 @@
log.warn("Handling jms exception failure: " + this, exception);
+ // We need to unlock() before sending the connection error to the
+ // event listeners. Otherwise the lock won't be in sync once
+ // cleanup() is called
+ if (lock.isLocked() && Thread.currentThread().equals(lock.getOwner()))
+ unlock();
+
try
{
con.setExceptionListener(null);
Modified: branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsSession.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsSession.java 2011-06-20 17:30:46 UTC (rev 111642)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/JmsSession.java 2011-06-20 18:01:52 UTC (rev 111643)
@@ -95,6 +95,8 @@
public JmsSession(final JmsManagedConnection mc, JmsConnectionRequestInfo info)
{
this.mc = mc;
+ this.lockedMC = null;
+ this.lockCount = 0;
this.info = info;
if (trace)
log.trace("new JmsSession " + this + " mc=" + mc + " cri=" + info);
@@ -123,7 +125,7 @@
protected void unlock()
{
- JmsManagedConnection mc = this.mc;
+ JmsManagedConnection mc = this.lockedMC;
if (--lockCount == 0)
lockedMC = null;
@@ -746,6 +748,8 @@
void destroy()
{
mc = null;
+ lockedMC = null;
+ lockCount = 0;
}
void start() throws JMSException
Added: branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/ReentrantLock.java
===================================================================
--- branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/ReentrantLock.java (rev 0)
+++ branches/JBPAPP_5_1_0_Final_JBPAPP-6742/connector/src/main/org/jboss/resource/adapter/jms/ReentrantLock.java 2011-06-20 18:01:52 UTC (rev 111643)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.resource.adapter.jms;
+
+import java.util.Collection;
+
+/**
+ * ReentrantLock override
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+public class ReentrantLock extends java.util.concurrent.locks.ReentrantLock
+{
+ /** Serial version uid */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor
+ * @param fair Fair locking
+ */
+ public ReentrantLock(boolean fair)
+ {
+ super(fair);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Thread getOwner()
+ {
+ return super.getOwner();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<Thread> getQueuedThreads()
+ {
+ return super.getQueuedThreads();
+ }
+}
More information about the jboss-cvs-commits
mailing list