db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r416820 - /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java
Date Fri, 23 Jun 2006 21:25:00 GMT
Author: arminw
Date: Fri Jun 23 14:25:00 2006
New Revision: 416820

URL: http://svn.apache.org/viewvc?rev=416820&view=rev
Log:
fix OJB-114, apply patch

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java?rev=416820&r1=416819&r2=416820&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerAbstractImpl.java
Fri Jun 23 14:25:00 2006
@@ -15,6 +15,9 @@
  * limitations under the License.
  */
 
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.ojb.broker.PBLifeCycleEvent;
 import org.apache.ojb.broker.PBLifeCycleListener;
 import org.apache.ojb.broker.PBListener;
@@ -41,34 +44,38 @@
  */
 public abstract class PersistenceBrokerAbstractImpl implements PersistenceBrokerInternal
 {
-    /**
-     * Returns <em>true</em> if PB-transaction check is enabled.
-     */
+    /** Returns <em>true</em> if PB-transaction check is enabled. */
     private boolean txCheck;
 
+    /*
+    PB instances are single threaded used, but we use synchronization here to
+    avoid problems with the JVM Finalizer thread - more details see issue
+    OJB-114 in JIRA
+    */
+
     /**
      * List containing all permanent {@link org.apache.ojb.broker.PBStateListener}
      * instances.
      */
-    private IdentityArrayList permanentStateListeners = new IdentityArrayList();
+    private final List permanentStateListeners = Collections.synchronizedList(new IdentityArrayList());
 
     /**
      * List containing all temporary {@link org.apache.ojb.broker.PBStateListener}
      * instances.
      */
-    private IdentityArrayList temporaryStateListeners = new IdentityArrayList();
+    private final List temporaryStateListeners = Collections.synchronizedList(new IdentityArrayList());
 
     /**
      * List containing all permanent {@link org.apache.ojb.broker.PBLifeCycleListener}
      * instances.
      */
-    private IdentityArrayList permanentLifeCycleListeners = new IdentityArrayList(100);
+    private List permanentLifeCycleListeners = Collections.synchronizedList(new IdentityArrayList(100));
 
     /**
      * List containing all temporary {@link org.apache.ojb.broker.PBLifeCycleListener}
      * instances.
      */
-    private IdentityArrayList temporaryLifeCycleListeners = new IdentityArrayList(100);
+    private List temporaryLifeCycleListeners = Collections.synchronizedList(new IdentityArrayList(100));
 
     /**
      * Override if needed.
@@ -108,49 +115,45 @@
         this.txCheck = txCheck;
     }
 
-    /**
-     * @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener listener)
-     */
+    /** @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener listener) */
     public void addListener(PBListener listener) throws PersistenceBrokerException
     {
         addListener(listener, false);
     }
 
-    /**
-     * @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener listener, boolean
permanent)
-     */
+    /** @see org.apache.ojb.broker.PersistenceBroker#addListener(PBListener listener, boolean
permanent) */
     public void addListener(PBListener listener, boolean permanent) throws PersistenceBrokerException
     {
-        if (listener instanceof PBStateListener)
+        if(listener instanceof PBStateListener)
         {
-            if (permanent)
+            if(permanent)
             {
-                if (!permanentStateListeners.contains(listener))
+                if(!permanentStateListeners.contains(listener))
                 {
                     permanentStateListeners.add(listener);
                 }
             }
             else
             {
-                if (!temporaryStateListeners.contains(listener))
+                if(!temporaryStateListeners.contains(listener))
                 {
                     temporaryStateListeners.add(listener);
                 }
             }
         }
 
-        if (listener instanceof PBLifeCycleListener)
+        if(listener instanceof PBLifeCycleListener)
         {
-            if (permanent)
+            if(permanent)
             {
-                if (!permanentLifeCycleListeners.contains(listener))
+                if(!permanentLifeCycleListeners.contains(listener))
                 {
                     permanentLifeCycleListeners.add(listener);
                 }
             }
             else
             {
-                if (!temporaryLifeCycleListeners.contains(listener))
+                if(!temporaryLifeCycleListeners.contains(listener))
                 {
                     temporaryLifeCycleListeners.add(listener);
                 }
@@ -158,37 +161,33 @@
         }
     }
 
-    /**
-     * @see org.apache.ojb.broker.PersistenceBroker#removeListener(PBListener listener)
-     */
+    /** @see org.apache.ojb.broker.PersistenceBroker#removeListener(PBListener listener)
*/
     public void removeListener(PBListener listener) throws PersistenceBrokerException
     {
-        if (listener instanceof PBStateListener)
+        if(listener instanceof PBStateListener)
         {
             permanentStateListeners.remove(listener);
             temporaryStateListeners.remove(listener);
         }
 
-        if (listener instanceof PBLifeCycleListener)
+        if(listener instanceof PBLifeCycleListener)
         {
             permanentLifeCycleListeners.remove(listener);
             temporaryLifeCycleListeners.remove(listener);
         }
     }
 
-    /**
-     * @see org.apache.ojb.broker.PersistenceBroker#removeAllListeners(boolean)
-     */
+    /** @see org.apache.ojb.broker.PersistenceBroker#removeAllListeners(boolean) */
     public void removeAllListeners(boolean permanent) throws PersistenceBrokerException
     {
-        if (permanent)
+        if(permanent)
         {
             // remove permanent listeners as well
             permanentStateListeners.clear();
             // this could be huge, thus simply replace instance
             if(permanentLifeCycleListeners.size() > 10000)
             {
-                permanentLifeCycleListeners = new IdentityArrayList(100);
+                permanentLifeCycleListeners = Collections.synchronizedList(new IdentityArrayList(100));
             }
             else
             {
@@ -200,7 +199,7 @@
         // this could be huge, thus simply replace instance
         if(temporaryLifeCycleListeners.size() > 10000)
         {
-            temporaryLifeCycleListeners = new IdentityArrayList(100);
+            temporaryLifeCycleListeners = Collections.synchronizedList(new IdentityArrayList(100));
         }
         else
         {
@@ -208,9 +207,7 @@
         }
     }
 
-    /**
-     * @see org.apache.ojb.broker.PersistenceBroker#removeAllListeners()
-     */
+    /** @see org.apache.ojb.broker.PersistenceBroker#removeAllListeners() */
     public void removeAllListeners() throws PersistenceBrokerException
     {
         removeAllListeners(false);
@@ -218,11 +215,11 @@
 
     public void fireBrokerEvent(PersistenceBrokerEvent event)
     {
-        if (event instanceof PBLifeCycleEvent)
+        if(event instanceof PBLifeCycleEvent)
         {
             fireBrokerEvent((PBLifeCycleEvent) event);
         }
-        else if (event instanceof PBStateEvent)
+        else if(event instanceof PBStateEvent)
         {
             fireBrokerEvent((PBStateEvent) event);
         }
@@ -235,43 +232,54 @@
 
     public void fireBrokerEvent(PBLifeCycleEvent event)
     {
-        if (event.getPersitenceBrokerAware() != null)
+        if(event.getPersitenceBrokerAware() != null)
         {
             // first we do the persistent object callback
             performCallBack(event);
         }
 
         // now we notify the listeners
-        for (int i = permanentLifeCycleListeners.size() - 1; i >= 0; i--)
+        synchronized(permanentLifeCycleListeners)
         {
-            notifiyObjectLifeCycleListener((PBLifeCycleListener) permanentLifeCycleListeners.get(i),
event);
+            for(int i = permanentLifeCycleListeners.size() - 1; i >= 0; i--)
+            {
+                notifiyObjectLifeCycleListener((PBLifeCycleListener) permanentLifeCycleListeners.get(i),
event);
+            }
         }
 
-        for(int i = temporaryLifeCycleListeners.size() - 1; i >= 0; i--)
+        synchronized(temporaryLifeCycleListeners)
         {
-            notifiyObjectLifeCycleListener((PBLifeCycleListener) temporaryLifeCycleListeners.get(i),
event);
-
+            for(int i = temporaryLifeCycleListeners.size() - 1; i >= 0; i--)
+            {
+                notifiyObjectLifeCycleListener((PBLifeCycleListener) temporaryLifeCycleListeners.get(i),
event);
+            }
         }
     }
 
     public void fireBrokerEvent(PBStateEvent event)
     {
-        for(int i = permanentStateListeners.size() - 1; i >= 0; i--)
+        synchronized(permanentStateListeners)
         {
-            notifiyStateListener((PBStateListener) permanentStateListeners.get(i), event);
+            for(int i = permanentStateListeners.size() - 1; i >= 0; i--)
+            {
+                notifiyStateListener((PBStateListener) permanentStateListeners.get(i), event);
+            }
         }
 
-        for(int i = temporaryStateListeners.size() - 1; i >= 0; i--)
+        synchronized(temporaryStateListeners)
         {
-            notifiyStateListener((PBStateListener) temporaryStateListeners.get(i), event);
+            for(int i = temporaryStateListeners.size() - 1; i >= 0; i--)
+            {
+                notifiyStateListener((PBStateListener) temporaryStateListeners.get(i), event);
+            }
         }
     }
 
     private void performCallBack(PBLifeCycleEvent event)
     {
         // Check for null
-        if (event.getPersitenceBrokerAware() == null) return;
-        switch (event.getEventType().typeId())
+        if(event.getPersitenceBrokerAware() == null) return;
+        switch(event.getEventType().typeId())
         {
             case PBLifeCycleEvent.TYPE_AFTER_LOOKUP:
                 event.getPersitenceBrokerAware().afterLookup(event.getTriggeringBroker());
@@ -299,7 +307,7 @@
 
     private void notifiyStateListener(PBStateListener listener, PBStateEvent stateEvent)
     {
-        switch (stateEvent.getEventType().typeId())
+        switch(stateEvent.getEventType().typeId())
         {
             case PBStateEvent.KEY_BEFORE_COMMIT:
                 listener.beforeCommit(stateEvent);
@@ -330,7 +338,7 @@
 
     private void notifiyObjectLifeCycleListener(PBLifeCycleListener listener, PBLifeCycleEvent
lifeEvent)
     {
-        switch (lifeEvent.getEventType().typeId())
+        switch(lifeEvent.getEventType().typeId())
         {
             case PBLifeCycleEvent.TYPE_AFTER_LOOKUP:
                 listener.afterLookup(lifeEvent);



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message