OW2 Consortium
Search OW2 Mail Archive: 

Advanced Search - Powered by Google


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

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

CVS update of gotm/src (4 files)


    Date: Friday, November 18, 2005 @ 14:49:48
  Author: rouvoy
    Path: /cvsroot/gotm/gotm/src

   Added: java/org/objectweb/gotm/lib/timer/Timer.java
          java/org/objectweb/gotm/lib/timer/TimerImpl.java
Modified: fractal/org/objectweb/gotm/lib/coordination/FcCommitEngine.fractal
           java/org/objectweb/gotm/lib/coordination/TimeoutImpl.java

* New version of AoKell-oo,
* Implementation of a timer.


--------------------------------------------------------------------+
 fractal/org/objectweb/gotm/lib/coordination/FcCommitEngine.fractal |    8 
 java/org/objectweb/gotm/lib/coordination/TimeoutImpl.java          |   58 
+---
 java/org/objectweb/gotm/lib/timer/Timer.java                       |   59 
++++
 java/org/objectweb/gotm/lib/timer/TimerImpl.java                   |  140 
++++++++++
 4 files changed, 223 insertions(+), 42 deletions(-)


Index: 
gotm/src/fractal/org/objectweb/gotm/lib/coordination/FcCommitEngine.fractal
diff -u 
gotm/src/fractal/org/objectweb/gotm/lib/coordination/FcCommitEngine.fractal:1.4
 
gotm/src/fractal/org/objectweb/gotm/lib/coordination/FcCommitEngine.fractal:1.5
--- 
gotm/src/fractal/org/objectweb/gotm/lib/coordination/FcCommitEngine.fractal:1.4
     Thu Nov 17 14:04:23 2005
+++ 
gotm/src/fractal/org/objectweb/gotm/lib/coordination/FcCommitEngine.fractal 
Fri Nov 18 14:49:48 2005
@@ -38,6 +38,8 @@
 
   <component name="Timeout"
        definition="org.objectweb.gotm.lib.coordination.FcTimeoutImpl"/>
+  <component name="Timer"
+       definition="org.objectweb.gotm.lib.timer.FcTimerImpl"/>
   <component name="Fc2PC" 
        definition="org.objectweb.gotm.lib.coordination.FcTwoPCFeature"/>
   <component name="Fc2PCActions" 
@@ -78,6 +80,8 @@
   <binding client="FcCommit.end-log"   server="this.commit-end-log"/>
   <binding client="FcCommit.abort"     server="FcAbort.coord-process"/>
 
-  <binding client="Timeout.subscribe"     server="this.timeout-subscribe"/>
-  <binding client="Timeout.coord-process" server="FcAbort.coord-process"/>
+  <binding client="Timeout.subscribe" server="this.timeout-subscribe"/>
+  <binding client="Timeout.timer"     server="Timer.timer"/>
+  
+  <binding client="Timer.coord-process" server="FcAbort.coord-process"/>
 </definition>
\ No newline at end of file
Index: gotm/src/java/org/objectweb/gotm/lib/coordination/TimeoutImpl.java
diff -u 
gotm/src/java/org/objectweb/gotm/lib/coordination/TimeoutImpl.java:1.8 
gotm/src/java/org/objectweb/gotm/lib/coordination/TimeoutImpl.java:1.9
--- gotm/src/java/org/objectweb/gotm/lib/coordination/TimeoutImpl.java:1.8    
  Thu Nov 17 14:04:22 2005
+++ gotm/src/java/org/objectweb/gotm/lib/coordination/TimeoutImpl.java  Fri 
Nov 18 14:49:48 2005
@@ -23,21 +23,16 @@
  Contributor(s): .
  
  ---------------------------------------------------------------------
- $Id: TimeoutImpl.java,v 1.8 2005/11/17 13:04:22 rouvoy Exp $
+ $Id: TimeoutImpl.java,v 1.9 2005/11/18 13:49:48 rouvoy Exp $
  ====================================================================*/
 
 package org.objectweb.gotm.lib.coordination;
 
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.HashMap;
 import java.util.Map;
 
-import javax.swing.Timer;
-
 import org.objectweb.fractal.api.control.CacheController;
 import org.objectweb.gotm.lib.message.SubscribablePrimitive;
-import org.objectweb.transaction.api.coordination.CoordinationFeature;
+import org.objectweb.gotm.lib.timer.Timer;
 import org.objectweb.transaction.api.message.Event;
 import org.objectweb.transaction.api.message.SubscribeFeature;
 import org.objectweb.transaction.lib.transaction.TransactionStatusCommitted;
@@ -48,8 +43,8 @@
 
 /**
  * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
- * @version $Revision: 1.8 $
- * @fractal.itf name="coord-process" role="client" 
signature="org.objectweb.transaction.api.coordination.CoordinationFeature"
+ * @version $Revision: 1.9 $
+ * @fractal.itf name="timer" role="client" 
signature="org.objectweb.gotm.lib.timer.Timer"
  */
 public class TimeoutImpl 
 extends SubscribablePrimitive
@@ -59,28 +54,7 @@
     public static final int DEFAULT_TIMEOUT = 0;
     
     private int timeout = DEFAULT_TIMEOUT;
-    
-    private Timer daemon ;
-    
-    /**
-     * Default Constructor.
-     */
-    public TimeoutImpl() {
-        ActionListener taskPerformer = new ActionListener() {
-            public void actionPerformed(ActionEvent evt) {
-                if (getLogger().isLoggable(DEBUG))
-                        getLogger().log(DEBUG, "Timeout has expired!");
-                try {
-                    TimeoutImpl.this.getTerminator().execute(new HashMap());
-                } catch (Exception e) {
-                    getLogger().log(FATAL, "Timeout abort failed:",e);
-                }
-            }
-        };
-        this.daemon = new Timer(DEFAULT_TIMEOUT, taskPerformer);
-//        Timer.setLogTimers(true);
-        this.daemon.setRepeats(false);
-    }
+    private boolean first = true;
     
     /* (non-Javadoc)
      * @see org.objectweb.gotm.lib.BindingFeature#clientFc()
@@ -88,7 +62,7 @@
     protected String[] clientFc() {
         return new String[] {
                 SubscribeFeature.SUBSCRIBE_FEATURE, 
-                CoordinationFeature.PROCESS_FEATURE
+                Timer.TIMER
         };
     }
 
@@ -105,9 +79,10 @@
         };
     }
 
-    protected final CoordinationFeature getTerminator() {
-            return (CoordinationFeature) 
singletonFc(CoordinationFeature.PROCESS_FEATURE);
-    }
+    /**
+     * @return the timer.
+     */
+    protected final Timer getTimer() {return (Timer) 
singletonFc(Timer.TIMER);}
     
     /* (non-Javadoc)
      * @see org.objectweb.gotm.lib.protocol.TimeoutAttribute#setTimeout(int)
@@ -116,7 +91,6 @@
         if (getLogger().isLoggable(DEBUG))
             getLogger().log(DEBUG, "Configuring timeout for "+delay+" sec.");
         this.timeout = delay ;
-        this.daemon.setInitialDelay(this.timeout*1000);
     }
     
     /* (non-Javadoc)
@@ -134,12 +108,15 @@
             if (getTimeout() != 0) {
                 if (getLogger().isLoggable(DEBUG))
                     getLogger().log(DEBUG, "Starting timeout for 
"+getTimeout()+" sec.");
-                this.daemon.restart();
+                if (this.first) 
+                    getTimer().start(getTimeout());
+                else 
+                    getTimer().restart();
             }
         } else if (getTimeout() != 0) {
             if (getLogger().isLoggable(DEBUG))
-                getLogger().log(DEBUG, "Stopping timeout 
(delay="+this.daemon.getDelay()+").");
-            this.daemon.stop();
+                getLogger().log(DEBUG, "Stopping timeout 
(delay="+getTimeout()+").");
+            getTimer().stop();
         }
     }
 
@@ -153,12 +130,13 @@
      */
     public void initFc() {
         setTimeout(DEFAULT_TIMEOUT);
+        this.first = true;
     }
 
     /* (non-Javadoc)
      * @see org.objectweb.fractal.api.control.CacheController#clearFc()
      */
     public void clearFc() {
-        this.daemon.stop();
+        getTimer().stop();
     }
 }
Index: gotm/src/java/org/objectweb/gotm/lib/timer/Timer.java
diff -u /dev/null gotm/src/java/org/objectweb/gotm/lib/timer/Timer.java:1.1
--- /dev/null   Fri Nov 18 14:49:48 2005
+++ gotm/src/java/org/objectweb/gotm/lib/timer/Timer.java       Fri Nov 18 
14:49:48 2005
@@ -0,0 +1,59 @@
+/*====================================================================
+
+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: Timer.java,v 1.1 2005/11/18 13:49:48 rouvoy Exp $
+====================================================================*/
+package org.objectweb.gotm.lib.timer;
+
+import org.objectweb.transaction.api.Feature;
+
+/**
+ * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
+ * @created 18 nov. 2005
+ * @modified $Date: 2005/11/18 13:49:48 $
+ * @version $Revision: 1.1 $
+ * @fractal.itf name="timer"
+ */
+public interface Timer
+        extends Feature {
+    /** <code>TIMER</code> identifier. */
+    static final String TIMER = "timer";
+    
+    /**
+     * starts the timer.
+     * @param time the duration of the timer.
+     */
+    void start(int time);
+    
+    /**
+     * restarts the timer for the remaining time.
+     */
+    void restart();
+    
+    /**
+     * stops the timer.
+     */
+    void stop();
+}
Index: gotm/src/java/org/objectweb/gotm/lib/timer/TimerImpl.java
diff -u /dev/null 
gotm/src/java/org/objectweb/gotm/lib/timer/TimerImpl.java:1.1
--- /dev/null   Fri Nov 18 14:49:48 2005
+++ gotm/src/java/org/objectweb/gotm/lib/timer/TimerImpl.java   Fri Nov 18 
14:49:48 2005
@@ -0,0 +1,140 @@
+/*====================================================================
+
+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: TimerImpl.java,v 1.1 2005/11/18 13:49:48 rouvoy Exp $
+====================================================================*/
+package org.objectweb.gotm.lib.timer;
+
+import java.util.HashMap;
+
+import org.objectweb.fractal.lib.BindablePrimitive;
+import org.objectweb.transaction.api.coordination.CoordinationFeature;
+
+/**
+ * @author <a href="mailto:Romain.Rouvoy@xxxxxxx";>Romain Rouvoy</a>
+ * @created 18 nov. 2005
+ * @modified $Date: 2005/11/18 13:49:48 $
+ * @version $Revision: 1.1 $
+ * @fractal.itf name="coord-process" role="client" 
signature="org.objectweb.transaction.api.coordination.CoordinationFeature"
+ */
+public class TimerImpl
+        extends BindablePrimitive 
+        implements Timer {
+    /** <code>PERIOD</code> . */
+    public static int PERIOD = 500;
+
+    private Thread clock;
+    boolean shutdown = true;
+
+    /* (non-Javadoc)
+     * @see org.objectweb.fractal.lib.BindablePrimitive#clientFc()
+     */
+    protected String[] clientFc() {
+        return new String[] { CoordinationFeature.PROCESS_FEATURE };
+    }
+
+    /**
+     * @return the coordination object to call when time elapses.
+     */
+    protected final CoordinationFeature getTerminator() {
+        return (CoordinationFeature) 
singletonFc(CoordinationFeature.PROCESS_FEATURE);
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.objectweb.gotm.lib.timer.Timer#start(int)
+     */
+    public void start(int time) {
+        this.clock = new Thread(new Clock(time*1000, PERIOD));
+        this.restart();
+    }
+    
+    /* (non-Javadoc)
+     * @see org.objectweb.gotm.lib.timer.Timer#restart()
+     */
+    public void restart() {
+        this.shutdown = false;
+        this.clock.start();
+    }
+
+    /* (non-Javadoc)
+     * @see org.objectweb.gotm.lib.timer.Timer#stop()
+     */
+    public void stop() {
+        this.shutdown = true;
+    }
+
+    
+    private class Clock implements Runnable {
+        private int timeout,refresh ;
+        
+        /**
+         * @param time
+         * @param refresh
+         */
+        public Clock(int time, int refresh) {
+            this.timeout = time;
+            this.refresh = refresh;
+        }
+        
+        /* (non-Javadoc)
+         * @see java.lang.Runnable#run()
+         */
+        public void run() {
+            try {
+                tic();
+            } catch (InterruptedException e) {
+                if (getLogger().isLoggable(ERROR))
+                    getLogger().log(ERROR, "Timer interrupted",e);
+            } catch (Exception e) {
+                if (getLogger().isLoggable(ERROR))
+                    getLogger().log(ERROR, "Timer failed",e);
+            }
+        }
+        
+        /**
+         * @throws Exception 
+         */
+        public void tic() throws Exception {
+            while(!shutdown) {
+                if (getLogger().isLoggable(DEBUG))
+                    getLogger().log(DEBUG, "Timer sleeping for "+refresh+" 
ms (remaining="+this.timeout+" ms)");
+                Thread.sleep(refresh);
+                this.timeout -= refresh;
+                if (shutdown) {
+                    if (getLogger().isLoggable(DEBUG))
+                        getLogger().log(DEBUG, "Timer shutdown 
(remaining="+this.timeout+" ms)");
+                    return;
+                }
+                if (this.timeout <= 0) {                
+                    if (getLogger().isLoggable(DEBUG))
+                        getLogger().log(DEBUG, "Time elapsed ! Executing 
handler");
+                    getTerminator().execute(new HashMap());
+                }
+            }
+        }
+    }
+
+}



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

Reply via email to:

Powered by MHonArc.

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