test_class.declarator: ran = 0
test_class.modifier: public
test_class.original_string: public int ran = 0;
test_class.type: int
test_class.var_name: ran
test_class.declarator: finished = 0
test_class.modifier: public
test_class.original_string: public int finished = 0;
test_class.type: int
test_class.var_name: finished
test_class.declarator: time = 0
test_class.modifier: public
test_class.original_string: public long time = 0;
test_class.type: long
test_class.var_name: time
test_class.file: src/agents/apps/floodlight/floodlight-1.0/src/test/java/net/floodlightcontroller/core/util/SingletonTaskTest.java
test_class.identifier: SingletonTaskTest
test_class.superclass: extends FloodlightTestCase
test_case.body: @Test
      public void testReschedule() throws InterruptedException {
          ScheduledExecutorService ses =
              Executors.newSingleThreadScheduledExecutor();
  
          final Object tc = this;
          SingletonTask st1 = new SingletonTask(ses, new Runnable() {
              @Override
              public void run() {
                  synchronized (tc) {
                      ran += 1;
                  }
                  time = System.nanoTime();
              }
          });
  
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
          st1.reschedule(20, TimeUnit.MILLISECONDS);
          Thread.sleep(5);
          assertFalse("Check that task hasn't run yet", ran > 0);
  
          ses.shutdown();
          ses.awaitTermination(5, TimeUnit.SECONDS);
  
          assertEquals("Check that task ran only once", 1, ran);
      }
test_case.class_method_signature: SingletonTaskTest.testReschedule()
test_case.full_signature: @Test public void testReschedule()
test_case.identifier: testReschedule
test_case.invocations: newSingleThreadScheduledExecutor nanoTime reschedule sleep assertFalse reschedule sleep assertFalse reschedule sleep assertFalse reschedule sleep assertFalse reschedule sleep assertFalse reschedule sleep assertFalse reschedule sleep assertFalse reschedule sleep assertFalse shutdown awaitTermination assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testReschedule()
focal_class.declarator: logger = 
              LoggerFactory.getLogger(SingletonTask.class)
focal_class.modifier: protected static final
focal_class.original_string: protected static final Logger logger = 
              LoggerFactory.getLogger(SingletonTask.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: context = new SingletonTaskContext()
focal_class.modifier: protected
focal_class.original_string: protected SingletonTaskContext context = new SingletonTaskContext();
focal_class.type: SingletonTaskContext
focal_class.var_name: context
focal_class.declarator: task
focal_class.modifier: protected
focal_class.original_string: protected Runnable task;
focal_class.type: Runnable
focal_class.var_name: task
focal_class.declarator: ses
focal_class.modifier: protected
focal_class.original_string: protected ScheduledExecutorService ses;
focal_class.type: ScheduledExecutorService
focal_class.var_name: ses
focal_class.file: src/agents/apps/floodlight/floodlight-1.0/src/main/java/net/floodlightcontroller/core/util/SingletonTask.java
focal_class.identifier: SingletonTask
focal_class.class_method_signature: SingletonTask.SingletonTask(ScheduledExecutorService ses,
              Runnable task)
focal_class.full_signature: public  SingletonTask(ScheduledExecutorService ses,
              Runnable task)
focal_class.identifier: SingletonTask
focal_class.modifiers: public
focal_class.parameters: (ScheduledExecutorService ses,
              Runnable task)
focal_class.signature:  SingletonTask(ScheduledExecutorService ses,
              Runnable task)
focal_class.class_method_signature: SingletonTask.reschedule(long delay, TimeUnit unit)
focal_class.full_signature: public void reschedule(long delay, TimeUnit unit)
focal_class.identifier: reschedule
focal_class.modifiers: public
focal_class.parameters: (long delay, TimeUnit unit)
focal_class.return: void
focal_class.signature: void reschedule(long delay, TimeUnit unit)
focal_method.body: public void reschedule(long delay, TimeUnit unit) {
          boolean needQueue = true;
          SingletonTaskWorker stw = null;
  
          synchronized (context) {
              if (context.taskRunning || context.taskShouldRun) {
                  if (context.taskRunning) {
                      // schedule to restart at the right time
                      if (delay > 0) {
                          long now = System.nanoTime();
                          long then = 
                              now + TimeUnit.NANOSECONDS.convert(delay, unit);
                          context.waitingTask.nextschedule = then;
  //                        logger.debug("rescheduled task " + this + " for " + TimeUnit.SECONDS.convert(then, TimeUnit.NANOSECONDS) + "s. A bunch of these messages -may- indicate you have a blocked task.");
                      } else {
                          context.waitingTask.nextschedule = 0;
                      }
                      needQueue = false;
                  } else {
                      // cancel and requeue
                      context.waitingTask.canceled = true;
                      context.waitingTask = null;
                  }
              }
  
              context.taskShouldRun = true;
  
              if (needQueue) {
                  stw = context.waitingTask = new SingletonTaskWorker(this);                    
              }
          }
  
          if (needQueue) {
              if (delay <= 0) 
                  ses.execute(stw);
              else
                  ses.schedule(stw, delay, unit);
          }
      }
focal_method.class_method_signature: SingletonTask.reschedule(long delay, TimeUnit unit)
focal_method.full_signature: public void reschedule(long delay, TimeUnit unit)
focal_method.identifier: reschedule
focal_method.invocations: nanoTime convert execute schedule
focal_method.modifiers: public
focal_method.parameters: (long delay, TimeUnit unit)
focal_method.return: void
focal_method.signature: void reschedule(long delay, TimeUnit unit)