OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


Mail Archive Home | gotm-commits List | June 2005 Index

<--  Date Index  --> <--  Thread Index  -->

CVS update of gotm/src/java/org/objectweb/gotm/lib (5 files)


    Date: Wednesday, June 29, 2005 @ 09:41:15
  Author: rouvoy
    Path: /cvsroot/gotm/gotm/src/java/org/objectweb/gotm/lib

Modified: event/EventEngineSimple.java event/EventEngineThreadPool.java
          resource/ResourceImpl.java resource/ResourceWithPool.java
          resource/ResourceWithThread.java

* Improving the performance issue of GoTM by using java.util.ArrayList 
instead of java.util.HashSet class.


----------------------------------+
 event/EventEngineSimple.java     |   25 +++---
 event/EventEngineThreadPool.java |   24 +++---
 resource/ResourceImpl.java       |  122 +++++++++++++++++---------------
 resource/ResourceWithPool.java   |   12 +--
 resource/ResourceWithThread.java |  140 +++++++++++++++++++------------------
 5 files changed, 176 insertions(+), 147 deletions(-)


Index: gotm/src/java/org/objectweb/gotm/lib/event/EventEngineSimple.java
diff -u gotm/src/java/org/objectweb/gotm/lib/event/EventEngineSimple.java:1.5 
gotm/src/java/org/objectweb/gotm/lib/event/EventEngineSimple.java:1.6
--- gotm/src/java/org/objectweb/gotm/lib/event/EventEngineSimple.java:1.5     
  Tue Jun 28 10:15:39 2005
+++ gotm/src/java/org/objectweb/gotm/lib/event/EventEngineSimple.java   Wed 
Jun 29 09:41:15 2005
@@ -23,14 +23,15 @@
 Contributor(s): .
 
 ---------------------------------------------------------------------
-$Id: EventEngineSimple.java,v 1.5 2005/06/28 08:15:39 rouvoy Exp $
+$Id: EventEngineSimple.java,v 1.6 2005/06/29 07:41:15 rouvoy Exp $
 ====================================================================*/
 package org.objectweb.gotm.lib.event;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
 import org.objectweb.fractal.api.control.CacheController;
 import org.objectweb.fractal.lib.LoggablePrimitive;
@@ -40,8 +41,8 @@
 /**
  * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
  * @created 12 janv. 2005
- * @modified $Date: 2005/06/28 08:15:39 $
- * @version $Revision: 1.5 $
+ * @modified $Date: 2005/06/29 07:41:15 $
+ * @version $Revision: 1.6 $
  * @fractal.itf
  */
 public class EventEngineSimple
@@ -57,10 +58,10 @@
          * @param topic the identifier of the requested topic
          * @return the requested topic.
          */
-        protected Set getTopic(int topic) {
-            Set set = (Set) this.topics.get(new Integer(topic)) ;
+        protected Collection getTopic(int topic) {
+            Collection set = (Collection) this.topics.get(new 
Integer(topic)) ;
             if (set != null) return set;
-            set = new HashSet();
+            set = new ArrayList();
             this.topics.put(new Integer(topic),set);
             return set;
         }
@@ -104,9 +105,11 @@
         public void notify(int topic, Map context) {
             if (getLogger().isLoggable(DEBUG))
                 getLogger().log(DEBUG,"Notifying of topic "+topic);
-            Object[] listeners = getTopic(topic).toArray(); // Iterators are 
less performing than arrays
-            for(int i=0 ; i <listeners.length;i++)
-                ((PublishFeature)listeners[i]).notify(topic, context);
+//            Object[] listeners = getTopic(topic).toArray(); // Iterators 
are less performing than arrays
+//            for(int i=0 ; i <listeners.length;i++)
+//                ((PublishFeature)listeners[i]).notify(topic, context);
+          for(Iterator i=getTopic(topic).iterator() ; i.hasNext();)
+              ((PublishFeature)i.next()).notify(topic, context);
         }
 
         /* (non-Javadoc)
Index: gotm/src/java/org/objectweb/gotm/lib/event/EventEngineThreadPool.java
diff -u 
gotm/src/java/org/objectweb/gotm/lib/event/EventEngineThreadPool.java:1.3 
gotm/src/java/org/objectweb/gotm/lib/event/EventEngineThreadPool.java:1.4
--- gotm/src/java/org/objectweb/gotm/lib/event/EventEngineThreadPool.java:1.3 
  Tue Jun 28 10:15:39 2005
+++ gotm/src/java/org/objectweb/gotm/lib/event/EventEngineThreadPool.java     
  Wed Jun 29 09:41:15 2005
@@ -23,14 +23,15 @@
  Contributor(s): .
  
  ---------------------------------------------------------------------
- $Id: EventEngineThreadPool.java,v 1.3 2005/06/28 08:15:39 rouvoy Exp $
+ $Id: EventEngineThreadPool.java,v 1.4 2005/06/29 07:41:15 rouvoy Exp $
  ====================================================================*/
 
 package org.objectweb.gotm.lib.event;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.Iterator;
 import java.util.Map;
 
 import org.objectweb.fractal.lib.BindablePrimitive;
@@ -41,8 +42,8 @@
 /**
  * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
  * @created 5 janv. 2005
- * @modified $Date: 2005/06/28 08:15:39 $
- * @version $Revision: 1.3 $
+ * @modified $Date: 2005/06/29 07:41:15 $
+ * @version $Revision: 1.4 $
  * @fractal.itf name="runnable-manager" role="client" 
signature="org.objectweb.util.thread.api.RunnableManager"
  */
 public class EventEngineThreadPool 
@@ -73,10 +74,10 @@
      * @param topic the identifier of the requested topic
      * @return the requested topic.
      */
-    protected Set getTopic(int topic) {
-        Set set = (Set) this.topics.get(new Integer(topic)) ;
+    protected Collection getTopic(int topic) {
+        Collection set = (Collection) this.topics.get(new Integer(topic)) ;
         if (set != null) return set;
-        set = new HashSet();
+        set = new ArrayList();
         this.topics.put(new Integer(topic),set);
         return set;
     }
@@ -105,9 +106,10 @@
     public void notify(int topic, Map context) {
         if (getLogger().isLoggable(DEBUG))
             getLogger().log(DEBUG,"Notification of the "+topic+" topic.");
-        Object[] listeners = getTopic(topic).toArray(); // Iterators are 
less performing than arrays
-        for(int i=0 ; i <listeners.length;i++)
-            getRunnableManager().submitRunnable(new 
NotifyAction((PublishFeature)listeners[i],topic,context));
+//        Object[] listeners = getTopic(topic).toArray(); // Iterators are 
less performing than arrays
+//        for(int i=0 ; i <listeners.length;i++)
+        for (Iterator i = getTopic(topic).iterator(); i.hasNext();)
+            getRunnableManager().submitRunnable(new 
NotifyAction((PublishFeature)i.next(),topic,context));
     }
 
     /* (non-Javadoc)
Index: gotm/src/java/org/objectweb/gotm/lib/resource/ResourceImpl.java
diff -u gotm/src/java/org/objectweb/gotm/lib/resource/ResourceImpl.java:1.4 
gotm/src/java/org/objectweb/gotm/lib/resource/ResourceImpl.java:1.5
--- gotm/src/java/org/objectweb/gotm/lib/resource/ResourceImpl.java:1.4 Tue 
Jun 28 10:15:39 2005
+++ gotm/src/java/org/objectweb/gotm/lib/resource/ResourceImpl.java     Wed 
Jun 29 09:41:15 2005
@@ -1,35 +1,36 @@
 /*====================================================================
 
-GoTM: GoTM is an open Transaction Monitor
-Copyright (C) 2003-2005 INRIA - Jacquard & USTL - LIFL - GOAL
-Contact: gotm-team@xxxxxxxxxxxxx
-
-This library 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 any later version.
-
-This library 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 library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
-USA
-
-Initial developer(s): Romain Rouvoy.
-Contributor(s): .
-
----------------------------------------------------------------------
-$Id: ResourceImpl.java,v 1.4 2005/06/28 08:15:39 rouvoy Exp $
-====================================================================*/
+ GoTM: GoTM is an open Transaction Monitor
+ Copyright (C) 2003-2005 INRIA - Jacquard & USTL - LIFL - GOAL
+ Contact: gotm-team@xxxxxxxxxxxxx
+
+ This library 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 any later version.
+
+ This library 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 library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ USA
+
+ Initial developer(s): Romain Rouvoy.
+ Contributor(s): .
+
+ ---------------------------------------------------------------------
+ $Id: ResourceImpl.java,v 1.5 2005/06/29 07:41:15 rouvoy Exp $
+ ====================================================================*/
 package org.objectweb.gotm.lib.resource;
 
-import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
 import org.objectweb.gotm.lib.event.SubscribablePrimitive;
 import org.objectweb.transaction.api.event.PublishFeature;
@@ -37,75 +38,87 @@
 /**
  * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
  * @created 1 févr. 2005
- * @modified $Date: 2005/06/28 08:15:39 $
- * @version $Revision: 1.4 $
+ * @modified $Date: 2005/06/29 07:41:15 $
+ * @version $Revision: 1.5 $
  * @fractal.itf
  */
-public abstract class ResourceImpl              
-extends SubscribablePrimitive
-implements PublishFeature, Resource
-{
+public abstract class ResourceImpl
+        extends SubscribablePrimitive
+        implements PublishFeature, Resource {
     /** list of registered observers for this kind of wrapper. */
-    private final Set observers = new HashSet();
+    private final Collection observers = new ArrayList();
 
     /** list of available actions. */
-    private final Map actions ;
-    
+    private final Map actions;
+
     /**
      * Default constructor.
      */
     protected ResourceImpl() {
         this.actions = declareActions();
     }
-    
+
     protected Action getAction(int name) {
-        return (Action)this.actions.get(new Integer(name));
+        return (Action) this.actions.get(new Integer(name));
     }
-    
+
     /**
      * Defines the list of available actions for the associated resource.
+     * 
      * @return the list of labelled actions.
      */
-    protected abstract Map declareActions() ;
+    protected abstract Map declareActions();
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see 
org.objectweb.gotm.lib.event.Resource#addResource(java.lang.Object)
      */
     public void addResource(final Object wrapped) {
         this.observers.add(wrapped);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see 
org.objectweb.gotm.lib.resource.Resource#delResource(java.lang.Object)
      */
     public void delResource(final Object wrapped) {
         this.observers.remove(wrapped);
     }
-    
-    /* (non-Javadoc)
+
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.objectweb.fractal.api.control.CacheController#clearFc()
      */
     public void clearFc() {
-        this.observers.clear() ;
+        this.observers.clear();
     }
-    
-    /* (non-Javadoc)
-     * @see 
org.objectweb.gotm.lib.topic.PublishFeature#notify(java.lang.String, 
java.util.Map)
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see 
org.objectweb.gotm.lib.topic.PublishFeature#notify(java.lang.String,
+     *      java.util.Map)
      */
     public void notify(final int topic, final Map context) {
         Action action = getAction(topic);
         if (getLogger().isLoggable(ERROR))
-            getLogger().log(DEBUG,"Propagating "+topic);
-        Object[] listeners = this.observers.toArray();
-        for (int i=0 ; i < listeners.length ; i++) {
+            getLogger().log(DEBUG, "Propagating " + topic);
+        // Object[] listeners = this.observers.toArray();
+        // for (int i=0 ; i < listeners.length ; i++) {
+        // try {
+        // action.execute(context,listeners[i]);
+        for (Iterator i = this.observers.iterator(); i.hasNext();) {
             try {
-                action.execute(context,listeners[i]);
+                action.execute(context, i.next());
             } catch (NullPointerException ex) {
-                throw new RuntimeException("No Action available for "+topic);
+                throw new RuntimeException("No Action available for " + 
topic);
             } catch (Exception ex) {
                 if (getLogger().isLoggable(ERROR))
-                    getLogger().log(ERROR,"Resource.notify: ",ex);
+                    getLogger().log(ERROR, "Resource.notify: ", ex);
             }
         }
-    }    
+    }
 }
Index: gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithPool.java
diff -u 
gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithPool.java:1.3 
gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithPool.java:1.4
--- gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithPool.java:1.3   
  Mon May 23 13:20:55 2005
+++ gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithPool.java Wed 
Jun 29 09:41:15 2005
@@ -23,15 +23,15 @@
 Contributor(s): .
 
 ---------------------------------------------------------------------
-$Id: ResourceWithPool.java,v 1.3 2005/05/23 11:20:55 rouvoy Exp $
+$Id: ResourceWithPool.java,v 1.4 2005/06/29 07:41:15 rouvoy Exp $
 ====================================================================*/
 
 package org.objectweb.gotm.lib.resource;
 
-import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
 import org.objectweb.gotm.lib.event.SubscribablePrimitive;
 import org.objectweb.transaction.api.event.PublishFeature;
@@ -42,8 +42,8 @@
  * Implementation of a wrapper.
  * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
  * @created 22 déc. 2004
- * @modified $Date: 2005/05/23 11:20:55 $
- * @version $Revision: 1.3 $
+ * @modified $Date: 2005/06/29 07:41:15 $
+ * @version $Revision: 1.4 $
  * @fractal.itf name="runnable-manager" role="client" 
signature="org.objectweb.util.thread.api.RunnableManager"
  */
 public abstract class ResourceWithPool 
@@ -51,7 +51,7 @@
            implements PublishFeature, Resource
 {
     /** list of registered observers for this kind of wrapper. */
-    private Set observers = new HashSet();
+    private Collection observers = new ArrayList();
     
     /* (non-Javadoc)
      * @see org.objectweb.fractal.lib.BindablePrimitive#clientFc()
Index: gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithThread.java
diff -u 
gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithThread.java:1.3 
gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithThread.java:1.4
--- gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithThread.java:1.3 
  Tue Jun 28 10:15:39 2005
+++ gotm/src/java/org/objectweb/gotm/lib/resource/ResourceWithThread.java     
  Wed Jun 29 09:41:15 2005
@@ -1,36 +1,37 @@
 /*====================================================================
 
-GoTM: GoTM is an open Transaction Monitor
-Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
-Contact: gotm-team@xxxxxxxxxxxxx
-
-This library 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 any later version.
-
-This library 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 library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
-USA
-
-Initial developer(s): Romain Rouvoy.
-Contributor(s): .
-
----------------------------------------------------------------------
-$Id: ResourceWithThread.java,v 1.3 2005/06/28 08:15:39 rouvoy Exp $
-====================================================================*/
+ GoTM: GoTM is an open Transaction Monitor
+ Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
+ Contact: gotm-team@xxxxxxxxxxxxx
+
+ This library 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 any later version.
+
+ This library 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 library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
+ USA
+
+ Initial developer(s): Romain Rouvoy.
+ Contributor(s): .
+
+ ---------------------------------------------------------------------
+ $Id: ResourceWithThread.java,v 1.4 2005/06/29 07:41:15 rouvoy Exp $
+ ====================================================================*/
 
 package org.objectweb.gotm.lib.resource;
 
-import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
 import java.util.Map;
-import java.util.Set;
 
 import org.objectweb.gotm.lib.event.SubscribablePrimitive;
 import org.objectweb.transaction.api.event.PublishFeature;
@@ -38,86 +39,94 @@
 
 /**
  * Implementation of a wrapper.
+ * 
  * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
  * @created 22 déc. 2004
- * @modified $Date: 2005/06/28 08:15:39 $
- * @version $Revision: 1.3 $
+ * @modified $Date: 2005/06/29 07:41:15 $
+ * @version $Revision: 1.4 $
  * @fractal.itf
  */
-public abstract class ResourceWithThread 
-              extends SubscribablePrimitive
-           implements PublishFeature, Resource
-{
+public abstract class ResourceWithThread
+        extends SubscribablePrimitive
+        implements PublishFeature, Resource {
     /** list of registered observers for this kind of wrapper. */
-    private Set observers = new HashSet();
-    
+    private Collection observers = new ArrayList();
+
     /** list of available actions. */
-    private final Map actions ;
-    
-    /* (non-Javadoc)
+    private final Map actions;
+
+    /*
+     * (non-Javadoc)
+     * 
      * @see org.objectweb.fractal.lib.BindablePrimitive#clientFc()
      */
     protected String[] clientFc() {
-        return new String[] {
-                SubscribeFeature.SUBSCRIBE_FEATURE,
-            };
+        return new String[] { SubscribeFeature.SUBSCRIBE_FEATURE, };
     }
-    
+
     /**
      * Default constructor.
      */
     protected ResourceWithThread() {
         this.actions = declareActions();
     }
-    
+
     protected Action getAction(int name) {
-        return (Action)this.actions.get(new Integer(name));
+        return (Action) this.actions.get(new Integer(name));
     }
-    
+
     /**
      * Defines the list of available actions for the associated resource.
+     * 
      * @return the list of labelled actions.
      */
-    protected abstract Map declareActions() ;
-
+    protected abstract Map declareActions();
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see 
org.objectweb.gotm.lib.event.Resource#addResource(java.lang.Object)
      */
     public void addResource(Object wrapped) {
         this.observers.add(wrapped);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see 
org.objectweb.gotm.lib.resource.Resource#delResource(java.lang.Object)
      */
     public void delResource(Object wrapped) {
         this.observers.remove(wrapped);
     }
-    
-    /* (non-Javadoc)
-     * @see org.objectweb.transaction.api.event.PublishFeature#notify(int, 
java.util.Map)
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.objectweb.transaction.api.event.PublishFeature#notify(int,
+     *      java.util.Map)
      */
     public void notify(int topic, Map context) {
-//        Vector v = new Vector();
+        // Vector v = new Vector();
         Action action = getAction(topic);
-        Object[] listeners = this.observers.toArray();
-        for (int i=0 ; i < listeners.length ; i++) {
+        // Object[] listeners = this.observers.toArray();
+        // for (int i=0 ; i < listeners.length ; i++) {
+        for (Iterator i = this.observers.iterator(); i.hasNext();) {
             try {
-                Thread t = new RunnableAction(action,context,listeners[i]);
+                Thread t = new RunnableAction(action, context, i.next());
                 t.start();
-//                v.add(t);
+                // v.add(t);
             } catch (Exception ex) {
                 if (getLogger().isLoggable(ERROR))
-                    getLogger().log(ERROR,"Action.execute: ",ex);
+                    getLogger().log(ERROR, "Action.execute: ", ex);
             }
         }
-//        for (Iterator i = v.iterator();i.hasNext();) {
-//            try {
-//                ((Thread)i.next()).join();
-//            } catch (InterruptedException e) {
-//                e.printStackTrace();
-//            }
-//        }
-    }    
+        // for (Iterator i = v.iterator();i.hasNext();) {
+        // try {
+        // ((Thread)i.next()).join();
+        // } catch (InterruptedException e) {
+        // e.printStackTrace();
+        // }
+        //        }
+    }
 }



<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 2006-2007, OW2 Consortium | contact | webmaster.