geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/timer/src/test/org/apache/geronimo/timer/jdbc JDBCWorkerPersistenceTest.java
Date Tue, 20 Jul 2004 23:36:53 GMT
djencks     2004/07/20 16:36:53

  Modified:    modules/timer/src/java/org/apache/geronimo/timer
                        ExecutorTaskFactory.java PersistentTimer.java
                        Playback.java ThreadPooledTimer.java WorkInfo.java
                        WorkerPersistence.java
               modules/timer/src/java/org/apache/geronimo/timer/jdbc
                        JDBCWorkerPersistence.java
               modules/timer/src/java/org/apache/geronimo/timer/vm
                        VMStoreThreadPooledTransactionalTimer.java
                        VMWorkerPersistence.java
               modules/timer/src/test/org/apache/geronimo/timer
                        AbstractThreadPooledTimerTest.java
               modules/timer/src/test/org/apache/geronimo/timer/jdbc
                        JDBCWorkerPersistenceTest.java
  Log:
  modifications needed for ejb entity timers, bugfixes, and import cleanup
  
  Revision  Changes    Path
  1.2       +3 -5      incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/ExecutorTaskFactory.java
  
  Index: ExecutorTaskFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/ExecutorTaskFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExecutorTaskFactory.java	18 Jul 2004 22:10:56 -0000	1.1
  +++ ExecutorTaskFactory.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -1,8 +1,6 @@
   package org.apache.geronimo.timer;
   
  -import java.util.Date;
   
  -import org.apache.geronimo.timer.ExecutorTask;
   
   
   /**
  @@ -12,7 +10,7 @@
    *
    * */
   public interface ExecutorTaskFactory {
  -    //TODO make the WorkerPersistence smarter so the oneTime and atFixedRate parameters
are not needed.
  -    // This could be done by eg. using a stored procedure for update/delete.
  +
       ExecutorTask createExecutorTask(Runnable userTask, WorkInfo workInfo, ThreadPooledTimer
threadPooledTimer);
  +
   }
  
  
  
  1.2       +10 -8     incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/PersistentTimer.java
  
  Index: PersistentTimer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/PersistentTimer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PersistentTimer.java	18 Jul 2004 22:10:56 -0000	1.1
  +++ PersistentTimer.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -15,21 +15,23 @@
    *
    * */
   public interface PersistentTimer {
  -    WorkInfo schedule(UserTaskFactory userTaskFactory, String key, Object userInfo, long
delay) throws PersistenceException, RollbackException, SystemException;
  +    WorkInfo schedule(UserTaskFactory userTaskFactory, String key, Object userId, Object
userInfo, long delay) throws PersistenceException, RollbackException, SystemException;
   
  -    WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo, Date
time) throws PersistenceException, RollbackException, SystemException;
  +    WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userId, Object
userInfo, Date time) throws PersistenceException, RollbackException, SystemException;
   
  -    WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo, long
delay, long period) throws PersistenceException, RollbackException, SystemException;
  +    WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo, long
delay, long period, Object userId) throws PersistenceException, RollbackException, SystemException;
   
  -    WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo, Date
firstTime, long period) throws PersistenceException, RollbackException, SystemException;
  +    WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userId, Object
userInfo, Date firstTime, long period) throws PersistenceException, RollbackException, SystemException;
   
  -    WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object userInfo,
long delay, long period) throws PersistenceException, RollbackException, SystemException;
  +    WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object userId,
Object userInfo, long delay, long period) throws PersistenceException, RollbackException,
SystemException;
   
  -    WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object userInfo,
Date firstTime, long period) throws PersistenceException, RollbackException, SystemException;
  +    WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object userId,
Object userInfo, Date firstTime, long period) throws PersistenceException, RollbackException,
SystemException;
   
       Collection playback(String key, UserTaskFactory userTaskFactory) throws PersistenceException;
   
  -    Collection getIdsByKey(String key) throws PersistenceException;
  +    Collection getIdsByKey(String key, Object userId) throws PersistenceException;
   
       WorkInfo getWorkInfo(Long id);
  +
  +    void cancelTimerTasks(Collection ids);
   }
  
  
  
  1.2       +2 -2      incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/Playback.java
  
  Index: Playback.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/Playback.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Playback.java	18 Jul 2004 22:10:56 -0000	1.1
  +++ Playback.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -1,6 +1,6 @@
   package org.apache.geronimo.timer;
   
  -import java.util.Date;
  +
   
   /**
    *
  
  
  
  1.2       +36 -27    incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/ThreadPooledTimer.java
  
  Index: ThreadPooledTimer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/ThreadPooledTimer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ThreadPooledTimer.java	18 Jul 2004 22:10:56 -0000	1.1
  +++ ThreadPooledTimer.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -24,6 +24,8 @@
   import java.util.HashMap;
   import java.util.Map;
   import java.util.Timer;
  +import java.util.Iterator;
  +import java.util.TimerTask;
   
   import javax.transaction.RollbackException;
   import javax.transaction.Status;
  @@ -34,15 +36,7 @@
   import EDU.oswego.cs.dl.util.concurrent.Executor;
   import org.apache.geronimo.gbean.GBeanLifecycle;
   import org.apache.geronimo.gbean.WaitingException;
  -import org.apache.geronimo.gbean.GBeanInfo;
  -import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.transaction.context.TransactionContext;
  -import org.apache.geronimo.timer.ExecutorFeedingTimerTask;
  -import org.apache.geronimo.timer.ExecutorTask;
  -import org.apache.geronimo.timer.ExecutorTaskFactory;
  -import org.apache.geronimo.timer.PersistenceException;
  -import org.apache.geronimo.timer.PersistentTimer;
  -import org.apache.geronimo.timer.Playback;
   
   /**
    *
  @@ -86,37 +80,37 @@
           doStop();
       }
   
  -    public WorkInfo schedule(UserTaskFactory userTaskFactory, String key, Object userInfo,
long delay) throws PersistenceException, RollbackException, SystemException {
  +    public WorkInfo schedule(UserTaskFactory userTaskFactory, String key, Object userId,
Object userInfo, long delay) throws PersistenceException, RollbackException, SystemException
{
           Date time = new Date(System.currentTimeMillis() + delay);
  -        return schedule(key, userTaskFactory, userInfo, time);
  +        return schedule(key, userTaskFactory, userId, userInfo, time);
       }
   
  -    public WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo,
Date time) throws PersistenceException, RollbackException, SystemException {
  -        WorkInfo worker = createWorker(key, userTaskFactory, executorTaskFactory, false,
userInfo, time, null);
  +    public WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userId,
Object userInfo, Date time) throws PersistenceException, RollbackException, SystemException
{
  +        WorkInfo worker = createWorker(key, userTaskFactory, executorTaskFactory, userId,
userInfo, time, null, false);
           registerSynchronization(new ScheduleSynchronization(worker.getExecutorFeedingTimerTask(),
time));
           addWorkInfo(worker);
           return worker;
       }
   
  -    public WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo,
long delay, long period) throws PersistenceException, RollbackException, SystemException {
  +    public WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo,
long delay, long period, Object userId) throws PersistenceException, RollbackException, SystemException
{
           Date time = new Date(System.currentTimeMillis() + delay);
  -        return schedule(key, userTaskFactory, userInfo, time, period);
  +        return schedule(key, userTaskFactory, userId, userInfo, time, period);
       }
   
  -    public WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userInfo,
Date firstTime, long period) throws PersistenceException, RollbackException, SystemException
{
  -        WorkInfo worker = createWorker(key, userTaskFactory, executorTaskFactory, false,
userInfo, firstTime, new Long(period));
  +    public WorkInfo schedule(String key, UserTaskFactory userTaskFactory, Object userId,
Object userInfo, Date firstTime, long period) throws PersistenceException, RollbackException,
SystemException {
  +        WorkInfo worker = createWorker(key, userTaskFactory, executorTaskFactory, userId,
userInfo, firstTime, new Long(period), false);
           registerSynchronization(new ScheduleRepeatedSynchronization(worker.getExecutorFeedingTimerTask(),
firstTime, period));
           addWorkInfo(worker);
           return worker;
       }
   
  -    public WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object
userInfo, long delay, long period) throws PersistenceException, RollbackException, SystemException
{
  +    public WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object
userId, Object userInfo, long delay, long period) throws PersistenceException, RollbackException,
SystemException {
           Date time = new Date(System.currentTimeMillis() + delay);
  -        return scheduleAtFixedRate(key, userTaskFactory, userInfo, time, period);
  +        return scheduleAtFixedRate(key, userTaskFactory, userId, userInfo, time, period);
       }
   
  -    public WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object
userInfo, Date firstTime, long period) throws PersistenceException, RollbackException, SystemException
{
  -        WorkInfo worker = createWorker(key, userTaskFactory, executorTaskFactory, true,
userInfo, firstTime, new Long(period));
  +    public WorkInfo scheduleAtFixedRate(String key, UserTaskFactory userTaskFactory, Object
userId, Object userInfo, Date firstTime, long period) throws PersistenceException, RollbackException,
SystemException {
  +        WorkInfo worker = createWorker(key, userTaskFactory, executorTaskFactory, userId,
userInfo, firstTime, new Long(period), true);
           registerSynchronization(new ScheduleAtFixedRateSynchronization(worker.getExecutorFeedingTimerTask(),
firstTime, period));
           addWorkInfo(worker);
           return worker;
  @@ -128,14 +122,30 @@
           return playback.getWorkInfos();
       }
   
  -    public Collection getIdsByKey(String key) throws PersistenceException {
  -        return workerPersistence.getIdsByKey(key);
  +    public Collection getIdsByKey(String key, Object userId) throws PersistenceException
{
  +        return workerPersistence.getIdsByKey(key, userId);
       }
   
       public WorkInfo getWorkInfo(Long id) {
           return (WorkInfo) idToWorkInfoMap.get(id);
       }
   
  +    /**
  +     * Called when client, eg. ejb container, is stopped and needs to cancel its timertasks
without
  +     * affecting persisted timer data.
  +     * @param ids list of ids to have their corresponding workInfo timertasks cancelled.
  +     */
  +    public void cancelTimerTasks(Collection ids) {
  +        for (Iterator iterator = ids.iterator(); iterator.hasNext();) {
  +            Long idLong = (Long) iterator.next();
  +            WorkInfo workInfo = getWorkInfo(idLong);
  +            if (workInfo != null) {
  +                TimerTask timerTask = workInfo.getExecutorFeedingTimerTask();
  +                timerTask.cancel();
  +            }
  +        }
  +    }
  +
       private void addWorkInfo(WorkInfo worker) {
           idToWorkInfoMap.put(new Long(worker.getId()), worker);
       }
  @@ -152,8 +162,7 @@
               workInfo.nextTime();
           } else {
               workInfo.nextInterval();
  -            //TODO this is wrong, need different update.
  -            workerPersistence.fixedRateWorkPerformed(workInfo.getId());
  +            workerPersistence.intervalWorkPerformed(workInfo.getId(), workInfo.getPeriod().longValue());
           }
       }
   
  @@ -172,8 +181,8 @@
           return executor;
       }
   
  -    private WorkInfo createWorker(String key, UserTaskFactory userTaskFactory, ExecutorTaskFactory
executorTaskFactory, boolean atFixedRate, Object userInfo, Date time, Long period) throws
PersistenceException {
  -        WorkInfo workInfo = new WorkInfo(key, userInfo, time, period, atFixedRate);
  +    private WorkInfo createWorker(String key, UserTaskFactory userTaskFactory, ExecutorTaskFactory
executorTaskFactory, Object userId, Object userInfo, Date time, Long period, boolean atFixedRate)
throws PersistenceException {
  +        WorkInfo workInfo = new WorkInfo(key, userId, userInfo, time, period, atFixedRate);
           //save and assign id
           workerPersistence.save(workInfo);
   
  
  
  
  1.2       +17 -3     incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/WorkInfo.java
  
  Index: WorkInfo.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/WorkInfo.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WorkInfo.java	18 Jul 2004 22:10:56 -0000	1.1
  +++ WorkInfo.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -30,22 +30,32 @@
    * */
   public class WorkInfo {
       //these should be persistent.
  -    private final String key;
       private long id = -1;
  +
  +    //typically object name of ejb.
  +    private final String key;
  +    //typically entity pk
  +    private final Object userId;
  +    //typically serializable object ejb timer service supplies to users.
       private final Object userInfo;
  +    //next firing
       private Date time;
  +    //time between firings
       private final Long period;
  +
       private final boolean atFixedRate;
   
       //these should not be persistent.
       private ExecutorFeedingTimerTask worker;
       private ExecutorTask taskWrapper;
   
  +    //wrappers to this timer service can store the wrapper here.
       private Object clientHandle;
   
   
  -    public WorkInfo(String key, Object userInfo, Date time, Long period, boolean atFixedRate)
{
  +    public WorkInfo(String key, Object userId, Object userInfo, Date time, Long period,
boolean atFixedRate) {
           this.key = key;
  +        this.userId = userId;
           this.userInfo = userInfo;
           this.time = time;
           this.period = period;
  @@ -65,6 +75,10 @@
               throw new IllegalStateException("Id can be set only once!");
           }
           this.id = id;
  +    }
  +
  +    public Object getUserId() {
  +        return userId;
       }
   
       public Object getUserInfo() {
  
  
  
  1.2       +2 -6      incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/WorkerPersistence.java
  
  Index: WorkerPersistence.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/WorkerPersistence.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WorkerPersistence.java	18 Jul 2004 22:10:56 -0000	1.1
  +++ WorkerPersistence.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -1,11 +1,7 @@
   package org.apache.geronimo.timer;
   
  -import java.util.Date;
   import java.util.Collection;
   
  -import org.apache.geronimo.timer.PersistenceException;
  -import org.apache.geronimo.timer.Playback;
  -
   /**
    *
    *
  @@ -24,5 +20,5 @@
   
       void intervalWorkPerformed(long id, long period) throws PersistenceException;
   
  -    Collection getIdsByKey(String key) throws PersistenceException;
  +    Collection getIdsByKey(String key, Object userId) throws PersistenceException;
   }
  
  
  
  1.2       +32 -20    incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistence.java
  
  Index: JDBCWorkerPersistence.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistence.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCWorkerPersistence.java	18 Jul 2004 22:10:57 -0000	1.1
  +++ JDBCWorkerPersistence.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -49,14 +49,14 @@
   public class JDBCWorkerPersistence implements WorkerPersistence, GBeanLifecycle {
   
       private static final String createSequenceSQL = "create sequence timertasks_seq";
  -    private static final String createTableSQL = "create table timertasks (id long primary
key, serverid varchar(256) not null, timerkey varchar(256) not null, userinfo varchar(4096),
firsttime long not null, period long, atfixedrate boolean not null)";
  +    private static final String createTableSQL = "create table timertasks (id long primary
key, serverid varchar(256) not null, timerkey varchar(256) not null, userid varchar(4096),
userinfo varchar(4096), firsttime long not null, period long, atfixedrate boolean not null)";
       private static final String sequenceSQL = "select timertasks_seq.nextval";
  -    private static final String insertSQL = "insert into timertasks (id, serverid, timerkey,
userinfo, firsttime, period, atfixedrate) values (?, ?, ?, ?, ?, ?, ?)";
  +    private static final String insertSQL = "insert into timertasks (id, serverid, timerkey,
userid, userinfo, firsttime, period, atfixedrate) values (?, ?, ?, ?, ?, ?, ?, ?)";
       private static final String deleteSQL = "delete from timertasks where id=?";
  -    private static final String selectSQL = "select id, userinfo, firsttime, period, atfixedrate
from timertasks where serverid = ? and timerkey=?";
  +    private static final String selectSQL = "select id, userid, userinfo, firsttime, period,
atfixedrate from timertasks where serverid = ? and timerkey=?";
       private static final String fixedRateUpdateSQL = "update timertasks set firsttime =
firsttime + period where id = ?";
       private static final String intervalUpdateSQL = "update timertasks set firsttime =
? where id = ?";
  -      private static final String selectByKeySQL = "select id from timertasks where key
= ?";
  +    private static final String selectByKeySQL = "select id from timertasks where serverid
= ? and timerkey = ? and (userid = ? or ? is null)";
   
       private final String serverUniqueId;
       private final ManagedConnectionFactoryWrapper managedConnectionFactoryWrapper;
  @@ -100,18 +100,20 @@
                   workInfo.setId(id);
                   PreparedStatement insertStatement = c.prepareStatement(insertSQL);
                   try {
  -                    String serializedUserKey = serialize(workInfo.getUserInfo());
  +                    String serializedUserId = serialize(workInfo.getUserId());
  +                     String serializedUserKey = serialize(workInfo.getUserInfo());
                       insertStatement.setLong(1, id);
                       insertStatement.setString(2, serverUniqueId);
                       insertStatement.setString(3, workInfo.getKey());
  -                    insertStatement.setString(4, serializedUserKey);
  -                    insertStatement.setLong(5, workInfo.getTime().getTime());
  +                    insertStatement.setString(4, serializedUserId);
  +                    insertStatement.setString(5, serializedUserKey);
  +                      insertStatement.setLong(6, workInfo.getTime().getTime());
                       if (workInfo.getPeriod() == null) {
  -                        insertStatement.setNull(6, Types.NUMERIC);
  +                        insertStatement.setNull(7, Types.NUMERIC);
                       } else {
  -                        insertStatement.setLong(6, workInfo.getPeriod().longValue());
  +                        insertStatement.setLong(7, workInfo.getPeriod().longValue());
                       }
  -                    insertStatement.setBoolean(7, workInfo.getAtFixedRate());
  +                    insertStatement.setBoolean(8, workInfo.getAtFixedRate());
                       int result = insertStatement.executeUpdate();
                       if (result != 1) {
                           throw new PersistenceException("Could not insert!");
  @@ -154,23 +156,25 @@
                   PreparedStatement selectStatement = c.prepareStatement(selectSQL);
                   selectStatement.setString(1, serverUniqueId);
                   selectStatement.setString(2, key);
  -                    try {
  +                try {
                       ResultSet taskRS = selectStatement.executeQuery();
                       try {
                           while (taskRS.next()) {
                               long id = taskRS.getLong(1);
  -                            String serializedUserInfo = taskRS.getString(2);
  +                            String serizalizedUserId = taskRS.getString(2);
  +                            Object userId = deserialize(serizalizedUserId);
  +                            String serializedUserInfo = taskRS.getString(3);
                               Object userInfo = deserialize(serializedUserInfo);
  -                            long timeMillis = taskRS.getLong(3);
  +                            long timeMillis = taskRS.getLong(4);
                               Date time = new Date(timeMillis);
                               Long period = null;
  -                            period = new Long(taskRS.getLong(4));
  +                            period = new Long(taskRS.getLong(5));
                               if (!taskRS.wasNull()) {
                                   period = null;
                               }
  -                            boolean atFixedRate = taskRS.getBoolean(5);
  +                            boolean atFixedRate = taskRS.getBoolean(6);
                               //TODO make sure the reference to this is ok, meaning we can't
use a handle to this WorkerPersistence.
  -                            WorkInfo workInfo = new WorkInfo(key, userInfo, time, period,
atFixedRate);
  +                            WorkInfo workInfo = new WorkInfo(key, userId, userInfo, time,
period, atFixedRate);
                               workInfo.setId(id);
                               playback.schedule(workInfo);
                           }
  @@ -216,7 +220,7 @@
                   try {
                       updateStatement.setLong(1, next);
                       updateStatement.setLong(2, id);
  -                           updateStatement.execute();
  +                    updateStatement.execute();
                   } finally {
                       updateStatement.close();
                   }
  @@ -228,7 +232,7 @@
           }
       }
   
  -    public Collection getIdsByKey(String key) throws PersistenceException {
  +    public Collection getIdsByKey(String key, Object userId) throws PersistenceException
{
           Collection ids = new ArrayList();
           try {
               Connection c = dataSource.getConnection();
  @@ -236,7 +240,15 @@
                   PreparedStatement selectStatement = c.prepareStatement(selectByKeySQL);
                   selectStatement.setString(1, serverUniqueId);
                   selectStatement.setString(2, key);
  -                    try {
  +                if (userId == null) {
  +                    selectStatement.setNull(3, Types.VARCHAR);
  +                    selectStatement.setNull(4, Types.VARCHAR);
  +                } else {
  +                    String userIdString = serialize(userId);
  +                    selectStatement.setString(3, userIdString);
  +                    selectStatement.setString(4, userIdString);
  +                }
  +                try {
                       ResultSet taskRS = selectStatement.executeQuery();
                       try {
                           while (taskRS.next()) {
  
  
  
  1.2       +1 -3      incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/vm/VMStoreThreadPooledTransactionalTimer.java
  
  Index: VMStoreThreadPooledTransactionalTimer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/vm/VMStoreThreadPooledTransactionalTimer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VMStoreThreadPooledTransactionalTimer.java	18 Jul 2004 22:10:57 -0000	1.1
  +++ VMStoreThreadPooledTransactionalTimer.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -18,10 +18,8 @@
   package org.apache.geronimo.timer.vm;
   
   import EDU.oswego.cs.dl.util.concurrent.Executor;
  -import org.apache.geronimo.connector.outbound.ManagedConnectionFactoryWrapper;
   import org.apache.geronimo.gbean.GBeanInfo;
   import org.apache.geronimo.gbean.GBeanInfoFactory;
  -import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.timer.PersistentTimer;
   import org.apache.geronimo.timer.ThreadPooledTimer;
   import org.apache.geronimo.timer.TransactionalExecutorTaskFactory;
  
  
  
  1.2       +3 -3      incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/vm/VMWorkerPersistence.java
  
  Index: VMWorkerPersistence.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/java/org/apache/geronimo/timer/vm/VMWorkerPersistence.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- VMWorkerPersistence.java	18 Jul 2004 22:10:57 -0000	1.1
  +++ VMWorkerPersistence.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -79,11 +79,11 @@
           //dont do anything... sharing data with WorkInfo.
       }
   
  -    public Collection getIdsByKey(String key) throws PersistenceException {
  +    public Collection getIdsByKey(String key, Object userId) throws PersistenceException
{
           Collection ids = new ArrayList();
           for (Iterator iterator = tasks.values().iterator(); iterator.hasNext();) {
               WorkInfo workInfo = (WorkInfo) iterator.next();
  -            if (key.equals(workInfo.getKey())) {
  +            if (key.equals(workInfo.getKey()) && (userId == null || userId.equals(workInfo.getUserId())))
{
                   ids.add(new Long(workInfo.getId()));
               }
           }
  
  
  
  1.2       +8 -7      incubator-geronimo/modules/timer/src/test/org/apache/geronimo/timer/AbstractThreadPooledTimerTest.java
  
  Index: AbstractThreadPooledTimerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/test/org/apache/geronimo/timer/AbstractThreadPooledTimerTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractThreadPooledTimerTest.java	18 Jul 2004 22:10:57 -0000	1.1
  +++ AbstractThreadPooledTimerTest.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -42,6 +42,7 @@
       private static final long SLOP = 200;
   
       private static final String key = "testThreadPooledTimer";
  +    private Object userId = null;
       private ThreadPool threadPool;
       private ThreadPooledTimer timer;
   
  @@ -74,7 +75,7 @@
   
       public void testTasks() throws Exception {
           for (long i = 0; i < COUNT; i++) {
  -            timer.schedule(userTaskFactory, key, userKey, i);
  +            timer.schedule(userTaskFactory, key, userId, userKey, i);
           }
           Thread.currentThread().sleep(COUNT + SLOP);
           assertEquals(COUNT, counter.get());
  @@ -83,7 +84,7 @@
       public void testCancel() throws Exception {
           WorkInfo[] workInfos = new WorkInfo[COUNT];
           for (long i = 0; i < COUNT; i++) {
  -            workInfos[(int) i] = timer.schedule(userTaskFactory, key, userKey, DELAY);
  +            workInfos[(int) i] = timer.schedule(userTaskFactory, key, userId, userKey,
DELAY);
           }
           for (int i = 0; i < workInfos.length; i++) {
               workInfos[i].getExecutorFeedingTimerTask().cancel();
  @@ -94,7 +95,7 @@
   
       public void testPersistence() throws Exception {
           for (long i = 0; i < COUNT; i++) {
  -            timer.schedule(userTaskFactory, key, userKey, DELAY);
  +            timer.schedule(userTaskFactory, key, userId, userKey, DELAY);
           }
           timer.doStop();
           assertEquals(0, counter.get());
  @@ -135,7 +136,7 @@
       public void testTasksInTransaction() throws Exception {
           TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
           for (long i = 0; i < COUNT; i++) {
  -            timer.schedule(userTaskFactory, key, userKey, i);
  +            timer.schedule(userTaskFactory, key, userId, userKey, i);
           }
           Thread.currentThread().sleep(COUNT + SLOP);
           assertEquals(0, counter.get());
  @@ -148,7 +149,7 @@
           Thread.currentThread().sleep(SLOP + DELAY);
           WorkInfo[] workInfos = new WorkInfo[COUNT];
           for (long i = 0; i < COUNT; i++) {
  -            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userKey,
DELAY, DELAY);
  +            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userId,
userKey, DELAY, DELAY);
           }
           Thread.currentThread().sleep(SLOP + DELAY);
           assertEquals(COUNT, counter.get());
  @@ -165,7 +166,7 @@
   
       public void testRepeatCountFromPersisted() throws Exception {
           assert DELAY > 2 * SLOP;
  -        timer.scheduleAtFixedRate(key, userTaskFactory, userKey, 0L, DELAY);
  +        timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, 0L, DELAY);
           Thread.currentThread().sleep(4 * DELAY + SLOP);
           timer.doStop();
           assertEquals(5, counter.get());
  
  
  
  1.2       +22 -3     incubator-geronimo/modules/timer/src/test/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistenceTest.java
  
  Index: JDBCWorkerPersistenceTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/timer/src/test/org/apache/geronimo/timer/jdbc/JDBCWorkerPersistenceTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCWorkerPersistenceTest.java	18 Jul 2004 22:10:57 -0000	1.1
  +++ JDBCWorkerPersistenceTest.java	20 Jul 2004 23:36:53 -0000	1.2
  @@ -21,6 +21,7 @@
   import java.sql.PreparedStatement;
   import java.sql.ResultSet;
   import java.util.Date;
  +import java.util.Collection;
   
   import javax.sql.DataSource;
   
  @@ -43,7 +44,8 @@
   
       private final String serverUniqueId = "TestServerUniqueID";
       private final String key = "test:service=Timer";
  -    private final Object userKey = "test user info";
  +    private final Object userInfo = "test user info";
  +    private Object userId = null;
   
       private JDBCWorkerPersistence jdbcWorkerPersistence;
       private DataSource datasource;
  @@ -59,7 +61,7 @@
           jdbcWorkerPersistence.doStart();
           time = new Date(System.currentTimeMillis());
           period = new Long(1000);
  -        workInfo = new WorkInfo(key, userKey, time, period, true);
  +        workInfo = new WorkInfo(key, userId, userInfo, time, period, true);
       }
   
       protected void tearDown() throws Exception {
  @@ -96,6 +98,23 @@
           jdbcWorkerPersistence.cancel(workInfo.getId());
           assertEquals(0, countRows());
       }
  +
  +    public void testGetByKey() throws Exception {
  +        time = new Date(System.currentTimeMillis());
  +        period = new Long(1000);
  +        WorkInfo workInfo1 = new WorkInfo(key, new Long(1), userInfo, time, period, true);
  +        WorkInfo workInfo2 = new WorkInfo(key, new Long(2), userInfo, time, period, true);
  +        jdbcWorkerPersistence.save(workInfo1);
  +        jdbcWorkerPersistence.save(workInfo2);
  +        Collection idsAll = jdbcWorkerPersistence.getIdsByKey(key, null);
  +        assertEquals(2, idsAll.size());
  +        Collection ids1 = jdbcWorkerPersistence.getIdsByKey(key, new Long(1));
  +        assertEquals(1, ids1.size());
  +        Collection ids2 = jdbcWorkerPersistence.getIdsByKey(key, new Long(2));
  +        assertEquals(1, ids2.size());
  +    }
  +
  +
   
       private void showRows() throws Exception {
           Connection c = datasource.getConnection();
  
  
  

Mime
View raw message