Package javax.ejb

Examples of javax.ejb.Timer


        // Get all services
        Collection<Timer> currentTimers = timerService.getTimers();
        Iterator<Timer> iter = currentTimers.iterator();
        HashSet<Serializable> existingTimers = new HashSet<Serializable>();
        while (iter.hasNext()) {
            Timer timer = iter.next();
            try {
                Serializable info = timer.getInfo();
                existingTimers.add(info);
            } catch (Throwable e) {
                // EJB 2.1 only?: We need this try because weblogic seems to
                // suck...
                log.debug("Error invoking timer.getInfo(): ", e);
View Full Code Here


     * Stop all timers that this object has created.
     */
    public void stopTimers () {
  for (Iterator i = ctx.getTimerService().getTimers().iterator ();
       i.hasNext ();) {
      Timer timer = (Timer)i.next();
      timer.cancel ();
  }
    }
View Full Code Here

     * Stop all timers that this object has created.
     */
    public void stopTimers () {
  for (Iterator i = ctx.getTimerService().getTimers().iterator ();
       i.hasNext ();) {
      Timer timer = (Timer)i.next();
      timer.cancel ();
  }
    }
View Full Code Here

   public void testRollbackCancel() throws Exception
   {
      TimedMockObject to = new TimedMockObject();
      TimerService service = createTimerService(to);
      Timer timer = service.createTimer(500, null);

      txManager.begin();
      timer.cancel();
      txManager.rollback();

      assertEquals("Expected one txtimer", 1, service.getTimers().size());
      sleep(1000);
      assertEquals("TimedObject not called", 1, to.getCallCount());
View Full Code Here

   {
      TimedMockObject to = new TimedMockObject();
      TimerService service = createTimerService(to);
     
      txManager.begin();
      Timer timer = service.createTimer(500, null);
      sleep(1000);
      assertEquals("TimedObject called", 0, to.getCallCount());
      txManager.commit();
      // On WinXp, immediately after commit the timer will be scheduled
      // with a time in the past, due to sleep(1000) and so it will immediately timeout
View Full Code Here

   public void testMultipleEventDuration() throws Exception
   {
      TimedMockObject to = new TimedMockObject();
      TimerService service = createTimerService(to);

      Timer timer = service.createTimer(500, 500, null);
      assertEquals("Expected one txtimer", 1, service.getTimers().size());
      sleep(2000);
      assertTrue("TimedObject not called enough", 1 < to.getCallCount());

      timer.cancel();
      assertEquals("Expected no txtimer", 0, service.getTimers().size());
   }
View Full Code Here

   public void testMultipleEventExpire() throws Exception
   {
      TimedMockObject to = new TimedMockObject();
      TimerService service = createTimerService(to);

      Timer timer = service.createTimer(new Date(System.currentTimeMillis() + 500), 500, null);
      assertEquals("Expected one txtimer", 1, service.getTimers().size());
      sleep(2000);
      assertTrue("TimedObject not called enough", 1 < to.getCallCount());

      timer.cancel();
      assertEquals("Expected no txtimer", 0, service.getTimers().size());
   }
View Full Code Here

   public void testTimerSerialization() throws Exception
   {
      TimedMockObject to = new TimedMockObject();
      TimerService service = createTimerService(to);
      Timer timer = service.createTimer(500, null);
      timer.cancel();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      try
      {
View Full Code Here

   public void testTimerHandleSerialization() throws Exception
   {
      TimedMockObject to = new TimedMockObject();
      TimerService service = createTimerService(to);
      Timer timer1 = service.createTimer(500, null);
      TimerHandle handle1 = timer1.getHandle();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream(baos);
      oos.writeObject(handle1);
      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
      ObjectInputStream ois = new ObjectInputStream(bais);
      TimerHandle handle2 = (TimerHandle)ois.readObject();

      Timer timer2 = handle2.getTimer();
      assertEquals("Timers are not equal", timer1, timer2);

      sleep(1000);
      assertTrue("TimedObject not called", 1 == to.getCallCount());
      assertEquals("Expected no txtimer", 0, service.getTimers().size());
View Full Code Here

   public void testSingleEventDuration() throws Exception
   {
      TimedMockObject to = new TimedMockObject();
      TimerService service = createTimerService(to);

      Timer timer = service.createTimer(500, null);
      assertEquals("Expected one txtimer", 1, service.getTimers().size());
      timer.cancel();
      sleep(1000);
      assertEquals("TimedObject called", 0, to.getCallCount());
      assertEquals("Expected no txtimer", 0, service.getTimers().size());
   }
View Full Code Here

TOP

Related Classes of javax.ejb.Timer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.