You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by kw...@apache.org on 2007/02/01 23:53:21 UTC

svn commit: r502392 - /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java

Author: kwsutter
Date: Thu Feb  1 14:53:20 2007
New Revision: 502392

URL: http://svn.apache.org/viewvc?view=rev&rev=502392
Log:
Changes for OPENJPA-115.  Removed the explicit lock/unlock invocations when obtaining an EM (broker).  Changed
_brokers to use ConcurrentReferenceHashSet (with weak references).  And, due to the weak references (probable
cause), I had to check for nulls when iterating through the _brokers during the close processing.

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java?view=diff&rev=502392&r1=502391&r2=502392
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java (original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java Thu Feb  1 14:53:20 2007
@@ -37,6 +37,7 @@
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.ReferenceHashSet;
+import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashSet;
 import org.apache.openjpa.lib.util.concurrent.ReentrantLock;
 import org.apache.openjpa.meta.MetaDataRepository;
 import org.apache.openjpa.util.GeneralException;
@@ -73,8 +74,8 @@
     private transient Map _transactional = new HashMap();
 
     // weak-ref tracking of open brokers
-    private transient Collection _brokers = new ReferenceHashSet
-        (ReferenceHashSet.WEAK);
+    private transient Collection _brokers = new ConcurrentReferenceHashSet
+        (ConcurrentReferenceHashSet.WEAK);
 
     // cache the class names loaded from the persistent classes property so
     // that we can re-load them for each new broker
@@ -141,7 +142,6 @@
 
     public Broker newBroker(String user, String pass, boolean managed,
         int connRetainMode, boolean findExisting) {
-        lock();
         try {
             assertOpen();
             makeReadOnly();
@@ -181,8 +181,6 @@
             throw ke;
         } catch (RuntimeException re) {
             throw new GeneralException(re);
-        } finally {
-            unlock();
         }
     }
 
@@ -289,7 +287,7 @@
             Broker broker;
             for (Iterator itr = _brokers.iterator(); itr.hasNext();) {
                 broker = (Broker) itr.next();
-                if (!broker.isClosed())
+                if ((broker != null) && (!broker.isClosed()))
                     broker.close();
             }
 
@@ -363,7 +361,8 @@
 
         // reset these transient fields to empty values
         _transactional = new HashMap();
-        _brokers = new ReferenceHashSet(ReferenceHashSet.WEAK);
+        _brokers = new ConcurrentReferenceHashSet(
+                ConcurrentReferenceHashSet.WEAK);
 
         makeReadOnly();
         return this;



Re: svn commit: r502392 - /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java

Posted by Kevin Sutter <kw...@gmail.com>.
Good point.  I'll clean that up on my next commit.

Kevin

On 2/1/07, Craig L Russell <Cr...@sun.com> wrote:
>
> Hi Kevin,
>
> Good changes.
>
> Here's where I would have put a comment:
>
> On Feb 1, 2007, at 2:53 PM, kwsutter@apache.org wrote:
>
> >              Broker broker;
> >              for (Iterator itr = _brokers.iterator(); itr.hasNext
> > ();) {
> >                  broker = (Broker) itr.next();
> > -                if (!broker.isClosed())
> /* Check for null here because _brokers is a weak reference
> collection */
> > +                if ((broker != null) && (!broker.isClosed()))
> >                      broker.close();
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
>

Re: svn commit: r502392 - /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/AbstractBrokerFactory.java

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Kevin,

Good changes.

Here's where I would have put a comment:

On Feb 1, 2007, at 2:53 PM, kwsutter@apache.org wrote:

>              Broker broker;
>              for (Iterator itr = _brokers.iterator(); itr.hasNext 
> ();) {
>                  broker = (Broker) itr.next();
> -                if (!broker.isClosed())
/* Check for null here because _brokers is a weak reference  
collection */
> +                if ((broker != null) && (!broker.isClosed()))
>                      broker.close();

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!