Revision: 15625
Author: emmartins
Date: Fri Dec  3 12:27:17 2010
Log: Update Issue 2135

Optimizes FT Timers replicated data and serialization tasks.
http://code.google.com/p/mobicents/source/detail?r=15625

Added:
/branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskDataMarshaller.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskDataMarshaller.java
Modified:
/branches/servers/cluster/2.x/example/beans/src/main/resources/META-INF/jboss-beans.xml /branches/servers/cluster/2.x/example/jar/src/main/java/org/mobicents/cluster/test/MCClusterTest.java /branches/servers/cluster/2.x/example/jar/src/main/java/org/mobicents/cluster/test/SerTimerTask.java /branches/servers/cluster/2.x/infinispan/src/main/java/org/mobicents/cluster/infinispan/InfinispanFailOverElector.java /branches/servers/cluster/2.x/spi/src/main/java/org/mobicents/cluster/base/AbstractCluster.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/CancelTimerAfterTxCommitRunnable.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/FaultTolerantScheduler.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/SetTimerAfterTxCommitRunnable.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTask.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskData.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskFactory.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/cluster/TimerTaskClusterDataKey.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/cluster/TimerTaskClusterDataMarshaller.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimer.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTask.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskData.java /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskFactory.java

=======================================
--- /dev/null
+++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskDataMarshaller.java Fri Dec 3 12:27:17 2010
@@ -0,0 +1,64 @@
+package org.mobicents.timers;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+/**
+ *
+ * @author martins
+ *
+ * @param <T>
+ */
+public abstract class TimerTaskDataMarshaller {
+
+       private final static int NOT_PERIODIC_TIMER = 255;
+
+       protected long readStartTime;
+       protected long readPeriod;
+       protected PeriodicScheduleStrategy readPeriodicScheduleStrategy;
+
+ protected void writeStandardTimerTaskData(ObjectOutput output, TimerTaskData timerTaskData) throws IOException {
+               output.writeLong(timerTaskData.getStartTime());
+               output.writeLong(timerTaskData.getPeriod());
+               if (timerTaskData.getPeriodicScheduleStrategy() != null) {
+                       
output.write(timerTaskData.getPeriodicScheduleStrategy().ordinal());
+               }
+               else {
+                       output.write(NOT_PERIODIC_TIMER);
+               }
+       }
+
+ protected void readStandardTimerTaskData(ObjectInput input) throws IOException {
+               readStartTime = input.readLong();
+               readPeriod = input.readLong();
+               int ordinal = input.read();
+               if (ordinal != NOT_PERIODIC_TIMER) {
+ readPeriodicScheduleStrategy = PeriodicScheduleStrategy.values()[ordinal];
+               }
+               else {
+                       readPeriodicScheduleStrategy = null;
+               }
+       }
+
+       /**
+        *
+        * @param output
+        * @param object
+        * @throws IOException
+        */
+ public abstract void writeTimerTaskData(ObjectOutput output, Object object)
+                       throws IOException;
+
+       /**
+        *
+        * @param input
+        * @param taskID
+        * @return
+        * @throws IOException
+        * @throws ClassNotFoundException
+        */
+ public abstract Object readTimerTaskData(ObjectInput input) throws IOException,
+                       ClassNotFoundException;
+
+}
=======================================
--- /dev/null
+++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskDataMarshaller.java Fri Dec 3 12:27:17 2010
@@ -0,0 +1,45 @@
+package org.mobicents.timers.timer;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.TimerTask;
+
+import org.mobicents.timers.TimerTaskDataMarshaller;
+
+/**
+ *
+ * @author martins
+ *
+ */
+public class FaultTolerantTimerTimerTaskDataMarshaller extends TimerTaskDataMarshaller {
+
+       /*
+        * (non-Javadoc)
+ * @see org.mobicents.timers.TimerTaskDataMarshaller#readTimerTaskData(java.io.ObjectInput)
+        */
+       @Override
+       public Object readTimerTaskData(ObjectInput input) throws IOException,
+                       ClassNotFoundException {
+               // read the standard timer task datat fields
+               super.readStandardTimerTaskData(input);
+               // read the java.util timer task
+               TimerTask timerTask = (TimerTask) input.readObject();
+               // recreate the timer task data
+ return new FaultTolerantTimerTimerTaskData(timerTask,readStartTime,readPeriod,readPeriodicScheduleStrategy);
+       }
+
+       /*
+        * (non-Javadoc)
+ * @see org.mobicents.timers.TimerTaskDataMarshaller#writeTimerTaskData(java.io.ObjectOutput, java.lang.Object)
+        */
+       @Override
+       public void writeTimerTaskData(ObjectOutput output, Object object)
+                       throws IOException {
+ FaultTolerantTimerTimerTaskData timerTaskData = (FaultTolerantTimerTimerTaskData) object;
+               // write the standard timer task data
+               super.writeStandardTimerTaskData(output, timerTaskData);
+               // write the java.util timer task
+               output.writeObject(timerTaskData.getJavaUtilTimerTask());
+       }
+}
=======================================
--- /branches/servers/cluster/2.x/example/beans/src/main/resources/META-INF/jboss-beans.xml Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/example/beans/src/main/resources/META-INF/jboss-beans.xml Fri Dec 3 12:27:17 2010
@@ -24,7 +24,7 @@
        </bean>

<bean name="MCClusterTest" class="org.mobicents.cluster.test.MCClusterTest"> - <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.mobicents:name=TimerTest",exposedInterface=org.mobicents.cluster.test.MCClusterTestMBean.class,registerDirectly=true) + <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="org.mobicents:name=FaultTolerantTimerServiceExample",exposedInterface=org.mobicents.cluster.test.MCClusterTestMBean.class,registerDirectly=true)
                </annotation>

                <property name="faultTolerantTimer">
=======================================
--- /branches/servers/cluster/2.x/example/jar/src/main/java/org/mobicents/cluster/test/MCClusterTest.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/example/jar/src/main/java/org/mobicents/cluster/test/MCClusterTest.java Fri Dec 3 12:27:17 2010
@@ -16,7 +16,7 @@
        private FaultTolerantTimer faultTolerantTimer;

        public void start() {
-               System.out.println("MCClusterTest Started");
+               System.out.println("Mobicents FT Timers Example Service 
started");
        }

        public TransactionManager getJta() {
=======================================
--- /branches/servers/cluster/2.x/example/jar/src/main/java/org/mobicents/cluster/test/SerTimerTask.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/example/jar/src/main/java/org/mobicents/cluster/test/SerTimerTask.java Fri Dec 3 12:27:17 2010
@@ -1,25 +1,14 @@
-/**
- * Start time:11:29:01 2009-08-10<br>
- * Project: mobicents-jainslee-server-core<br>
- *
- * @author <a href="mailto:[email protected]";>Bartosz Baranowski </a>
- */
 package org.mobicents.cluster.test;

 import java.io.Serializable;
 import java.util.TimerTask;

 /**
- * Start time:11:29:01 2009-08-10<br>
- * Project: mobicents-jainslee-server-core<br>
  *
- * @author <a href="mailto:[email protected]";>Bartosz Baranowski
- *         </a>
+ * @author <a href="mailto:[email protected]";>Bartosz Baranowski</a>
  */
-public class SerTimerTask extends TimerTask implements Serializable
-{
-
-       private String id = ""+( (Math.random()*10000)/1l);
+public class SerTimerTask extends TimerTask implements Serializable {
+
        /**
         *
         */
@@ -30,6 +19,7 @@
         */
        @Override
        public void run() {
- System.err.println("------------------------ TIMER RUN COMPLETER["+id+"] ------------------------");
-
-       }}
+ System.out.println("------------------------ TIMER RUN COMPLETED ------------------------");
+       }
+
+}
=======================================
--- /branches/servers/cluster/2.x/infinispan/src/main/java/org/mobicents/cluster/infinispan/InfinispanFailOverElector.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/infinispan/src/main/java/org/mobicents/cluster/infinispan/InfinispanFailOverElector.java Fri Dec 3 12:27:17 2010
@@ -13,7 +13,7 @@
  */
 public class InfinispanFailOverElector implements FailoverElector {

-       private final int shift = 5; // lets set default to something other than
+ private static final int shift = 5; // lets set default to something other than
                                                                        // zero

        /*
@@ -26,7 +26,7 @@
                // Jgroups return addresses always in sorted order, infinispan 
does not
                // change it.
                int size = list.size();
-               int index = (this.shift % size) + size;
+               int index = (shift % size) + size;
                index = index % size;
                return list.get(index);
        }
=======================================
--- /branches/servers/cluster/2.x/spi/src/main/java/org/mobicents/cluster/base/AbstractCluster.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/spi/src/main/java/org/mobicents/cluster/base/AbstractCluster.java Fri Dec 3 12:27:17 2010
@@ -1,5 +1,6 @@
 package org.mobicents.cluster.base;

+import java.io.Serializable;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
@@ -181,7 +182,12 @@
         *
         */
        private static class ClusterDataFailOverListenerComparator implements
-                       Comparator<ClusterDataFailOverListener> {
+                       Comparator<ClusterDataFailOverListener>, Serializable {
+               /**
+                *
+                */
+               private static final long serialVersionUID = 1L;
+
                /*
                 * (non-Javadoc)
                 *
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/CancelTimerAfterTxCommitRunnable.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/CancelTimerAfterTxCommitRunnable.java Fri Dec 3 12:27:17 2010
@@ -21,8 +21,6 @@
  */
 package org.mobicents.timers;

-import java.io.Serializable;
-
 import org.apache.log4j.Logger;


@@ -49,8 +47,7 @@
         */
        public void run() {

-               final TimerTaskData taskData = task.getData();
-               final Serializable taskID = taskData.getTaskID();
+               final String taskID = task.getTaskID();

                if (logger.isDebugEnabled()) {
                        logger.debug("Cancelling timer task for timer ID 
"+taskID);
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/FaultTolerantScheduler.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/FaultTolerantScheduler.java Fri Dec 3 12:27:17 2010
@@ -21,7 +21,6 @@
  */
 package org.mobicents.timers;

-import java.io.Serializable;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
@@ -75,7 +74,7 @@
        /**
* the local running tasks. NOTE: never ever check for values, class instances may differ due cache replication, ALWAYS use keys.
         */
- private final ConcurrentHashMap<Serializable, TimerTask> localRunningTasks = new ConcurrentHashMap<Serializable, TimerTask>(); + private final ConcurrentHashMap<String, TimerTask> localRunningTasks = new ConcurrentHashMap<String, TimerTask>();

        /**
         * the timer task factory associated with this scheduler
@@ -97,6 +96,11 @@
         */
        private final ClientLocalListener clusterClientLocalListener;

+       /**
+        *
+        */
+       private final TimerTaskDataMarshaller taskDataMarshaller;
+
        /**
         *
         * @param name
@@ -106,20 +110,21 @@
         * @param txManager
         * @param timerTaskFactory
         */
- public FaultTolerantScheduler(String name, int corePoolSize, Cluster<?> cluster, byte priority, TransactionManager txManager,TimerTaskFactory timerTaskFactory) { + public FaultTolerantScheduler(String name, int corePoolSize, Cluster<?> cluster, byte priority, TransactionManager txManager,TimerTaskFactory timerTaskFactory, TimerTaskDataMarshaller taskDataMarshaller) {
                this.name = name;
                this.executor = new ScheduledThreadPoolExecutor(corePoolSize);
                this.clusterDataKey = new 
FaultTolerantSchedulerClusterDataKey(name);
                this.cluster = cluster;
this.clusterData = cluster.getClusterDataSource().getClusterData(clusterDataKey);
                this.timerTaskFactory = timerTaskFactory;
+               this.taskDataMarshaller = taskDataMarshaller;
                this.txManager = txManager;
                clusterClientLocalListener = new ClientLocalListener(priority);
                if (!cluster.getClusterDataSource().isLocalMode()) {
                        cluster.addFailOverListener(clusterClientLocalListener);
                        
cluster.addDataRemovalListener(clusterClientLocalListener);
cluster.getClusterDataMarshalerManagement().register(FaultTolerantSchedulerClusterDataMarshaller.ID, new FaultTolerantSchedulerClusterDataMarshaller()); - cluster.getClusterDataMarshalerManagement().register(TimerTaskClusterDataMarshaller.ID, new TimerTaskClusterDataMarshaller()); + cluster.getClusterDataMarshalerManagement().register(TimerTaskClusterDataMarshaller.ID, new TimerTaskClusterDataMarshaller(taskDataMarshaller));
                }
        }

@@ -128,7 +133,7 @@
         * @param taskID
         * @return null if there is no such timer task data
         */
-       public TimerTaskData getTimerTaskData(Serializable taskID) {
+       public TimerTaskData getTimerTaskData(String taskID) {
final TimerTaskClusterDataKey key = new TimerTaskClusterDataKey(name, taskID); final ClusterData clusterData = cluster.getClusterDataSource().getClusterData(key);
                return (TimerTaskData) clusterData.getDataObject();
@@ -146,7 +151,7 @@
         * Retrieves local running tasks map.
         * @return
         */
-       ConcurrentHashMap<Serializable, TimerTask> getLocalRunningTasksMap() {
+       ConcurrentHashMap<String, TimerTask> getLocalRunningTasksMap() {
                return localRunningTasks;
        }

@@ -191,6 +196,14 @@
        public TimerTaskFactory getTimerTaskFactory() {
                return timerTaskFactory;
        }
+
+       /**
+        * Retrieves the task data marshaller.
+        * @return
+        */
+       public TimerTaskDataMarshaller getTaskDataMarshaller() {
+               return taskDataMarshaller;
+       }

        // logic

@@ -205,7 +218,7 @@
        public void schedule(TimerTask task, boolean checkIfAlreadyPresent) {

                final TimerTaskData taskData = task.getData();
-               final Serializable taskID = taskData.getTaskID();
+               final String taskID = task.getTaskID();
                task.setScheduler(this);

                if (logger.isDebugEnabled()) {
@@ -253,7 +266,7 @@
         * @param taskID
         * @return the task canceled
         */
-       public TimerTask cancel(Serializable taskID) {
+       public TimerTask cancel(String taskID) {

                if (logger.isDebugEnabled()) {
                        logger.debug("Canceling task with timer id "+taskID);
@@ -303,7 +316,7 @@
                return task;
        }

-       void remove(Serializable taskID,boolean removeFromCache) {
+       void remove(String taskID,boolean removeFromCache) {
                if(logger.isDebugEnabled())
                {
                        logger.debug("remove() : "+taskID+" - 
"+removeFromCache);
@@ -315,7 +328,7 @@
                }
        }

-       private void removeTaskDataFromCluster(Serializable taskID) {
+       private void removeTaskDataFromCluster(String taskID) {
final TimerTaskClusterDataKey ttKey = new TimerTaskClusterDataKey(name, taskID);
                clusterData.removeReference(ttKey);
                
cluster.getClusterDataSource().getClusterData(ttKey).remove(false);
@@ -326,10 +339,10 @@
         *
         * @param taskData
         */
-       private void recover(TimerTaskData taskData) {
-               TimerTask task = timerTaskFactory.newTimerTask(taskData);
+       private void recover(String taskID, TimerTaskData taskData) {
+               TimerTask task = timerTaskFactory.newTimerTask(taskID,taskData);
                if (logger.isDebugEnabled()) {
-                       logger.debug("Recovering task with id 
"+taskData.getTaskID());
+                       logger.debug("Recovering task with id 
"+task.getTaskID());
                }
                task.beforeRecover();
// on recovery the task will already be in the cache so we don't check for it
@@ -433,7 +446,9 @@
                        }

                        try {
-                               recover((TimerTaskData) 
clusterData.getDataObject());
+ final TimerTaskClusterDataKey key = (TimerTaskClusterDataKey) clusterData.getKey(); + final TimerTaskData taskData = (TimerTaskData) clusterData.getDataObject();
+                               recover(key.getTaskID(),taskData);
                        }
                        catch (Throwable e) {
                                logger.error(e.getMessage(),e);
@@ -443,7 +458,7 @@

                @Override
                public void dataRemoved(ClusterDataKey removedReferencedKey) {
- final Serializable taskId = ((TimerTaskClusterDataKey)removedReferencedKey).getTaskID(); + final String taskId = ((TimerTaskClusterDataKey)removedReferencedKey).getTaskID();
                        final TimerTask task = localRunningTasks.remove(taskId);
                        if (task != null) {
                                task.cancel();
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/SetTimerAfterTxCommitRunnable.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/SetTimerAfterTxCommitRunnable.java Fri Dec 3 12:27:17 2010
@@ -59,7 +59,7 @@

                if (!canceled) {

- scheduler.getLocalRunningTasksMap().put(task.getData().getTaskID(), task);
+                       
scheduler.getLocalRunningTasksMap().put(task.getTaskID(), task);

                        final TimerTaskData taskData = task.getData();
                        // calculate delay
@@ -73,13 +73,13 @@
                                if (taskData.getPeriod() < 0) {
                                        if (logger.isDebugEnabled()) {
                                                logger.debug("Scheduling one-shot 
timer with id "
-                                                               + 
task.getData().getTaskID());
+                                                               + 
task.getTaskID());
                                        }
task.setScheduledFuture(scheduler.getExecutor().schedule(task, delay, TimeUnit.MILLISECONDS));
                                } else {
                                        if (logger.isDebugEnabled()) {
                                                logger.debug("Scheduling periodic 
timer with id "
-                                                               + 
task.getData().getTaskID());
+                                                               + 
task.getTaskID());
                                        }
if (taskData.getPeriodicScheduleStrategy() == PeriodicScheduleStrategy.withFixedDelay) { task.setScheduledFuture(scheduler.getExecutor().scheduleWithFixedDelay(task, delay, taskData.getPeriod(),TimeUnit.MILLISECONDS));
@@ -91,22 +91,22 @@
                                }
                        } catch (Throwable e) {
                                logger.error(e.getMessage(), e);
-                               scheduler.remove(taskData.getTaskID(),true);
+                               scheduler.remove(task.getTaskID(),true);
                        }
                } else {
                        if (logger.isDebugEnabled()) {
                                logger.debug("Canceled scheduling periodic timer 
with id "
-                                               + task.getData().getTaskID());
+                                               + task.getTaskID());
                        }
                }
        }

        public void cancel() {
                if (logger.isDebugEnabled()) {
- logger.debug("Canceling set timer action for task with timer id "+task.getData().getTaskID()); + logger.debug("Canceling set timer action for task with timer id "+task.getTaskID());
                }
                canceled = true;
-               scheduler.remove(task.getData().getTaskID(),true);
+               scheduler.remove(task.getTaskID(),true);
        }

 }
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTask.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTask.java Fri Dec 3 12:27:17 2010
@@ -38,6 +38,11 @@
         */
        private final TimerTaskData data;

+       /**
+        *
+        */
+       private final String taskID;
+
        /**
         * the schedule future object that returns from the task scheduling
         */
@@ -62,8 +67,9 @@
         *
         * @param data
         */
-       public TimerTask(TimerTaskData data) {
+       public TimerTask(String taskID, TimerTaskData data) {
                this.data = data;
+               this.taskID = taskID;
        }

        /**
@@ -73,6 +79,14 @@
        public TimerTaskData getData() {
                return data;
        }
+
+       /**
+        *
+        * @return
+        */
+       public String getTaskID() {
+               return taskID;
+       }

        /**
* Retrieves the tx action to set the timer when the tx commits, not used in a non tx environment.
@@ -130,19 +144,19 @@
                if(data.getPeriod() < 0 && autoRemoval) {
                        if (logger.isDebugEnabled()) {
                                logger.debug("Task with id "
- + data.getTaskID() + " is not recurring, so removing it locally and in the cluster"); + + taskID + " is not recurring, so removing it locally and in the cluster");
                        }
// once the task has been fired, remove it locally and in the cluster, only if it is a non recurring task
                        removeFromScheduler();
                } else {
                        if (logger.isDebugEnabled()) {
                                logger.debug("Task with id "
- + data.getTaskID() + " is recurring, not removing it locally nor in the cluster"); + + taskID + " is recurring, not removing it locally nor in the cluster");
                        }
                }
                if (logger.isDebugEnabled()) {
                        logger.debug("Firing Timer with id "
-                                       + data.getTaskID());
+                                       + taskID);
                }
                runTask();
        }
@@ -151,7 +165,7 @@
* Self removal from the scheduler. Note that this method does not cancel the task execution.
         */
        protected void removeFromScheduler() {
-               scheduler.remove(data.getTaskID(),true);
+               scheduler.remove(taskID,true);
        }

        /**
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskData.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskData.java Fri Dec 3 12:27:17 2010
@@ -21,8 +21,6 @@
  */
 package org.mobicents.timers;

-import java.io.Serializable;
-
 /**
  *
* The {...@link TimerTask} data, which may be replicated in a cluster environment to support fail over.
@@ -30,12 +28,7 @@
  * @author martins
  *
  */
-public class TimerTaskData implements Serializable {
-
-       /**
-        *
-        */
-       private static final long serialVersionUID = 8905073681622353718L;
+public class TimerTaskData {

        /**
         * the starting time of the associated timer task execution
@@ -47,11 +40,6 @@
         */
        private final long period;

-       /**
-        * the id of the associated timer task
-        */
-       private final Serializable taskID;
-
        /**
* the strategy used in a periodic timer task, can be null if it is not a periodic timer task
         */
@@ -59,12 +47,10 @@

        /**
         *
-        * @param id
         * @param startTime
         * @param period
         */
- public TimerTaskData(Serializable id, long startTime, long period, PeriodicScheduleStrategy periodicScheduleStrategy) {
-               this.taskID = id;
+ public TimerTaskData(long startTime, long period, PeriodicScheduleStrategy periodicScheduleStrategy) {
                this.startTime = startTime;
                this.period = period;
                this.periodicScheduleStrategy = periodicScheduleStrategy;
@@ -93,14 +79,6 @@
        public void setStartTime(long startTime) {
                this.startTime = startTime;
        }
-
-       /**
-        * Retrieves the id of the associated timer task.
-        * @return
-        */
-       public Serializable getTaskID() {
-               return taskID;
-       }

        /**
* Retrieves the strategy used in a periodic timer task, can be null if it is not a periodic timer task.
@@ -109,19 +87,5 @@
        public PeriodicScheduleStrategy getPeriodicScheduleStrategy() {
                return periodicScheduleStrategy;
        }
-
-       @Override
-       public int hashCode() {
-               return taskID.hashCode();
-       }
-
-       @Override
-       public boolean equals(Object obj) {
-               if (obj != null && obj.getClass() == this.getClass()) {
-                       return ((TimerTaskData)obj).taskID.equals(this.taskID);
-               }
-               else {
-                       return false;
-               }
-       }
-}
+
+}
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskFactory.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/TimerTaskFactory.java Fri Dec 3 12:27:17 2010
@@ -30,10 +30,10 @@
 public interface TimerTaskFactory {

        /**
- * Creates a new instance of a concrete {...@link TimerTask}, using the specified {...@link TimerTaskData}. + * Creates a new instance of a concrete {...@link TimerTask}, using the specified {...@link TimerTaskData} and ID.
         *
         * @param data
         * @return
         */
-       public TimerTask newTimerTask(TimerTaskData data);
-}
+       public TimerTask newTimerTask(String taskID, TimerTaskData data);
+}
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/cluster/TimerTaskClusterDataKey.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/cluster/TimerTaskClusterDataKey.java Fri Dec 3 12:27:17 2010
@@ -1,7 +1,5 @@
 package org.mobicents.timers.cluster;

-import java.io.Serializable;
-
 import org.mobicents.cluster.ClusterDataKey;

 /**
@@ -11,10 +9,10 @@
  */
 public class TimerTaskClusterDataKey implements ClusterDataKey {

-       private final Serializable taskID;
+       private final String taskID;
        private final String schedulerName;

- public TimerTaskClusterDataKey(String schedulerName, Serializable taskID) {
+       public TimerTaskClusterDataKey(String schedulerName, String taskID) {
                this.taskID = taskID;
                this.schedulerName = schedulerName;
        }
@@ -23,7 +21,7 @@
                return schedulerName;
        }

-       public Serializable getTaskID() {
+       public String getTaskID() {
                return taskID;
        }

=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/cluster/TimerTaskClusterDataMarshaller.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/cluster/TimerTaskClusterDataMarshaller.java Fri Dec 3 12:27:17 2010
@@ -3,10 +3,10 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.io.Serializable;

 import org.mobicents.cluster.ClusterDataKey;
 import org.mobicents.cluster.ClusterDataMarshaller;
+import org.mobicents.timers.TimerTaskDataMarshaller;

 /**
  *
@@ -16,35 +16,40 @@
public class TimerTaskClusterDataMarshaller implements ClusterDataMarshaller {

        public static final int ID = 3601;
-
+
+       private final TimerTaskDataMarshaller dataMarshaller;
+
+ public TimerTaskClusterDataMarshaller(TimerTaskDataMarshaller dataMarshaller) {
+               this.dataMarshaller = dataMarshaller;
+       }
+
+
        @Override
        public void writeKey(ObjectOutput output, ClusterDataKey key)
                        throws IOException {
                final TimerTaskClusterDataKey tKey = (TimerTaskClusterDataKey) 
key;
                output.writeUTF(tKey.getSchedulerName());
-               // TODO optimize to not use writeObject ...
-               output.writeObject(tKey.getTaskID());
+               output.writeUTF(tKey.getTaskID());
        }

        @Override
        public ClusterDataKey readKey(ObjectInput input) throws IOException,
                        ClassNotFoundException {
                final String schedulerName = input.readUTF();
-               final Serializable taskId = (Serializable) input.readObject();
+               final String taskId = input.readUTF();
                return new TimerTaskClusterDataKey(schedulerName,taskId);
        }

        @Override
        public void writeDataObject(ObjectOutput output, Object object)
                        throws IOException {
- // TODO optimize to not use writeObject, cast to timerTaskData and write fields ...
-               output.writeObject(object);
+               dataMarshaller.writeTimerTaskData(output,object);
        }

        @Override
        public Object readDataObject(ObjectInput input) throws IOException,
                        ClassNotFoundException {
-               return input.readObject();
+               return dataMarshaller.readTimerTaskData(input);
        }

 }
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimer.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimer.java Fri Dec 3 12:27:17 2010
@@ -62,7 +62,7 @@
         */
public FaultTolerantTimer(String name, Cluster<?> cluster, byte priority, TransactionManager txManager) {
                timerTaskFactory = new FaultTolerantTimerTimerTaskFactory();
- scheduler = new FaultTolerantScheduler(name,16, cluster, priority, txManager, timerTaskFactory); + scheduler = new FaultTolerantScheduler(name,16, cluster, priority, txManager, timerTaskFactory, new FaultTolerantTimerTimerTaskDataMarshaller());
                timerTaskFactory.setScheduler(scheduler);
        }

@@ -85,7 +85,7 @@
for (org.mobicents.timers.TimerTask timerTask : scheduler.getLocalRunningTasks()) { FaultTolerantTimerTimerTask ftTimerTask = (FaultTolerantTimerTimerTask) timerTask;
                        if (ftTimerTask.isCanceled()) {
-                               
scheduler.cancel(ftTimerTask.getData().getTaskID());
+                               scheduler.cancel(ftTimerTask.getTaskID());
                                count++;
                        }
                }
@@ -94,37 +94,37 @@

        @Override
        public void schedule(TimerTask task, Date firstTime, long period) {
- final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(new FaultTolerantTimerTimerTaskData(task, UUID.randomUUID(),firstTime.getTime() - System.currentTimeMillis(),period,PeriodicScheduleStrategy.withFixedDelay)); + final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(UUID.randomUUID().toString(),new FaultTolerantTimerTimerTaskData(task, firstTime.getTime() - System.currentTimeMillis(),period,PeriodicScheduleStrategy.withFixedDelay));
                scheduler.schedule(taskWrapper);
        }

        @Override
        public void schedule(TimerTask task, Date time) {
- final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(new FaultTolerantTimerTimerTaskData(task, UUID.randomUUID(),time.getTime() - System.currentTimeMillis(),-1,null)); + final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(UUID.randomUUID().toString(),new FaultTolerantTimerTimerTaskData(task, time.getTime() - System.currentTimeMillis(),-1,null));
                scheduler.schedule(taskWrapper);
        }

        @Override
        public void schedule(TimerTask task, long delay) {
- final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(new FaultTolerantTimerTimerTaskData(task, UUID.randomUUID(),System.currentTimeMillis()+delay,-1,null)); + final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(UUID.randomUUID().toString(),new FaultTolerantTimerTimerTaskData(task, System.currentTimeMillis()+delay,-1,null));
                scheduler.schedule(taskWrapper);
        }

        @Override
        public void schedule(TimerTask task, long delay, long period) {
- final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(new FaultTolerantTimerTimerTaskData(task, UUID.randomUUID(),System.currentTimeMillis()+delay,period,PeriodicScheduleStrategy.withFixedDelay)); + final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(UUID.randomUUID().toString(),new FaultTolerantTimerTimerTaskData(task, System.currentTimeMillis()+delay,period,PeriodicScheduleStrategy.withFixedDelay));
                scheduler.schedule(taskWrapper);
        }

        @Override
public void scheduleAtFixedRate(TimerTask task, Date firstTime, long period) { - final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(new FaultTolerantTimerTimerTaskData(task, UUID.randomUUID(),firstTime.getTime() - System.currentTimeMillis(),period,PeriodicScheduleStrategy.atFixedRate)); + final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(UUID.randomUUID().toString(),new FaultTolerantTimerTimerTaskData(task, firstTime.getTime() - System.currentTimeMillis(),period,PeriodicScheduleStrategy.atFixedRate));
                scheduler.schedule(taskWrapper);
        }

        @Override
        public void scheduleAtFixedRate(TimerTask task, long delay, long 
period) {
- final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(new FaultTolerantTimerTimerTaskData(task, UUID.randomUUID(),System.currentTimeMillis()+delay,period,PeriodicScheduleStrategy.atFixedRate)); + final org.mobicents.timers.TimerTask taskWrapper = timerTaskFactory.newTimerTask(UUID.randomUUID().toString(),new FaultTolerantTimerTimerTaskData(task,System.currentTimeMillis()+delay,period,PeriodicScheduleStrategy.atFixedRate));
                scheduler.schedule(taskWrapper);
        }
 }
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTask.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTask.java Fri Dec 3 12:27:17 2010
@@ -53,8 +53,8 @@
         *
         * @param taskData
         */
- public FaultTolerantTimerTimerTask(FaultTolerantTimerTimerTaskData taskData,FaultTolerantScheduler scheduler) {
-               super(taskData);
+ public FaultTolerantTimerTimerTask(String taskID, FaultTolerantTimerTimerTaskData taskData, FaultTolerantScheduler scheduler) {
+               super(taskID,taskData);
                this.taskData = taskData;
                this.scheduler = scheduler;
                setPeriod(taskData.getJavaUtilTimerTask(),taskData.getPeriod());
@@ -66,13 +66,13 @@
         */
        public void runTask() {
                if (isCanceled()) {
-                       scheduler.cancel(this.getData().getTaskID());
+                       scheduler.cancel(this.getTaskID());
                }
                else {
                        try{
                                taskData.getJavaUtilTimerTask().run();
                                if(taskData.getPeriodicScheduleStrategy() == 
null) {
-                                       
scheduler.cancel(this.getData().getTaskID());
+                                       scheduler.cancel(this.getTaskID());
                                }
                                else {
                                        if (logger.isDebugEnabled()) {
@@ -158,7 +158,7 @@
                try {
                        Field stateField=cc.getDeclaredField("period");
                        stateField.setAccessible(true);
-                       stateField.set(javaUtilTimerTask,new Long(period));
+                       stateField.set(javaUtilTimerTask, Long.valueOf(period));
                        stateField.setAccessible(false);
                        return;
                } catch (Throwable e) {
=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskData.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskData.java Fri Dec 3 12:27:17 2010
@@ -21,7 +21,6 @@
  */
 package org.mobicents.timers.timer;

-import java.io.Serializable;
 import java.util.TimerTask;

 import org.mobicents.timers.PeriodicScheduleStrategy;
@@ -42,13 +41,12 @@
        /**
         *
         * @param javaUtilTimerTask
-        * @param id
         * @param startTime
         * @param period
         * @param periodicScheduleStrategy
         */
- public FaultTolerantTimerTimerTaskData(TimerTask javaUtilTimerTask, Serializable id, long startTime, long period, PeriodicScheduleStrategy periodicScheduleStrategy) {
-               super(id,startTime,period, periodicScheduleStrategy);
+ public FaultTolerantTimerTimerTaskData(TimerTask javaUtilTimerTask, long startTime, long period, PeriodicScheduleStrategy periodicScheduleStrategy) {
+               super(startTime,period, periodicScheduleStrategy);
                this.javaUtilTimerTask = javaUtilTimerTask;
        }

=======================================
--- /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskFactory.java Fri Dec 3 07:03:48 2010 +++ /branches/servers/cluster/2.x/timers/src/main/java/org/mobicents/timers/timer/FaultTolerantTimerTimerTaskFactory.java Fri Dec 3 12:27:17 2010
@@ -37,13 +37,13 @@

        /*
         * (non-Javadoc)
- * @see org.mobicents.slee.core.timers.TimerTaskFactory#newTimerTask(org.mobicents.slee.core.timers.TimerTaskData) + * @see org.mobicents.timers.TimerTaskFactory#newTimerTask(java.lang.String, org.mobicents.timers.TimerTaskData)
         */
-       public TimerTask newTimerTask(TimerTaskData data) {
+       public TimerTask newTimerTask(String taskID, TimerTaskData data) {
                if (scheduler == null) {
throw new IllegalStateException("unable to create data, scheduler is not set");
                }
- return new FaultTolerantTimerTimerTask((org.mobicents.timers.timer.FaultTolerantTimerTimerTaskData) data,scheduler); + return new FaultTolerantTimerTimerTask(taskID,(org.mobicents.timers.timer.FaultTolerantTimerTimerTaskData) data,scheduler);
        }

        /**

Reply via email to