[dna-commits] DNA SVN: r1509 - in trunk/dna-graph/src/main: java/org/jboss/dna/graph/connector and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Dec 31 17:41:02 EST 2009


Author: bcarothers
Date: 2009-12-31 17:41:01 -0500 (Thu, 31 Dec 2009)
New Revision: 1509

Modified:
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
   trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java
   trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
Log:
DNA-608 RepositoryConnectionPool.ConnectionWrapper.close Closes the Underlying Connection

Applied a patch that returns the closed flag and the related checks to the ConnectionWrapper class.

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java	2009-12-31 21:36:01 UTC (rev 1508)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/GraphI18n.java	2009-12-31 22:41:01 UTC (rev 1509)
@@ -33,6 +33,7 @@
  */
 public final class GraphI18n {
 
+    public static I18n closedConnectionMayNotBeUsed;
     public static I18n errorConvertingIo;
     public static I18n errorConvertingType;
     public static I18n errorReadingPropertyValueBytes;

Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java	2009-12-31 21:36:01 UTC (rev 1508)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/connector/RepositoryConnectionPool.java	2009-12-31 22:41:01 UTC (rev 1509)
@@ -142,7 +142,7 @@
     /**
      * Flag specifying whether a connection should be validated before returning it from the {@link #getConnection()} method.
      */
-    private final AtomicBoolean validateConnectionBeforeUse = new AtomicBoolean(true);
+    private final AtomicBoolean validateConnectionBeforeUse = new AtomicBoolean(false);
 
     /**
      * The time in nanoseconds that ping should wait before timing out and failing.
@@ -779,10 +779,8 @@
             mainLock.lock();
             // Remove the connection from the in-use set ...
             boolean removed = this.inUseConnections.remove(wrapper);
+            assert removed;
 
-            // This means that the wrapper was already closed at least once since the last time it was opened
-            if (!removed) return;
-
             // If we're shutting down the pool, then just close the connection ...
             if (this.runState != RUNNING) {
                 wrapperToClose = wrapper;
@@ -934,6 +932,7 @@
         private final RepositoryConnection original;
         private final long timeCreated;
         private long lastUsed;
+        private boolean closed = false;
 
         protected ConnectionWrapper( RepositoryConnection connection ) {
             assert connection != null;
@@ -973,6 +972,7 @@
          * {@inheritDoc}
          */
         public XAResource getXAResource() {
+            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             return this.original.getXAResource();
         }
 
@@ -980,6 +980,7 @@
          * {@inheritDoc}
          */
         public CachePolicy getDefaultCachePolicy() {
+            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             return this.original.getDefaultCachePolicy();
         }
 
@@ -991,6 +992,7 @@
          */
         public void execute( ExecutionContext context,
                              Request request ) throws RepositorySourceException {
+            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             this.original.execute(context, request);
         }
 
@@ -999,6 +1001,7 @@
          */
         public boolean ping( long time,
                              TimeUnit unit ) throws InterruptedException {
+            if (closed) throw new IllegalStateException(GraphI18n.closedConnectionMayNotBeUsed.text());
             return this.original.ping(time, unit);
         }
 
@@ -1006,8 +1009,11 @@
          * {@inheritDoc}
          */
         public void close() {
-            this.lastUsed = System.currentTimeMillis();
-            returnConnection(this);
+            if (!closed) {
+                this.lastUsed = System.currentTimeMillis();
+                this.closed = true;
+                returnConnection(this);
+            }
         }
     }
 

Modified: trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties
===================================================================
--- trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties	2009-12-31 21:36:01 UTC (rev 1508)
+++ trunk/dna-graph/src/main/resources/org/jboss/dna/graph/GraphI18n.properties	2009-12-31 22:41:01 UTC (rev 1509)
@@ -21,6 +21,7 @@
 # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 # 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 #
+closedConnectionMayNotBeUsed = The connection has been closed and may not be used
 errorConvertingIo = Error converting {0} to a {1}
 errorConvertingType = Error converting {0} to a {1}: {2}
 errorReadingPropertyValueBytes = Error reading bytes



More information about the dna-commits mailing list