/** * Starts the timer. This method is called when {@link #acquire()} is called * for the first time. It schedules a task to be executed at fixed rate to * monitor the time period specified. * * @return a future object representing the task scheduled */ protected ScheduledFuture<?> startTimer() { return getExecutorService().scheduleAtFixedRate(new Runnable() { @Override public void run() { endOfPeriod(); } }, getPeriod(), getPeriod(), getUnit()); }
/** * Tests creating a new instance. */ @Test public void testInit() { final ScheduledExecutorService service = EasyMock .createMock(ScheduledExecutorService.class); EasyMock.replay(service); final TimedSemaphore semaphore = new TimedSemaphore(service, PERIOD, UNIT, LIMIT); EasyMock.verify(service); assertEquals("Wrong service", service, semaphore.getExecutorService()); assertEquals("Wrong period", PERIOD, semaphore.getPeriod()); assertEquals("Wrong unit", UNIT, semaphore.getUnit()); assertEquals("Statistic available", 0, semaphore .getLastAcquiresPerPeriod()); assertEquals("Average available", 0.0, semaphore .getAverageCallsPerPeriod(), .05); assertFalse("Already shutdown", semaphore.isShutdown()); assertEquals("Wrong limit", LIMIT, semaphore.getLimit()); }
/** * Starts the timer. This method is called when {@link #acquire()} is called * for the first time. It schedules a task to be executed at fixed rate to * monitor the time period specified. * * @return a future object representing the task scheduled */ protected ScheduledFuture<?> startTimer() { return getExecutorService().scheduleAtFixedRate(new Runnable() { @Override public void run() { endOfPeriod(); } }, getPeriod(), getPeriod(), getUnit()); }
/** * Starts the timer. This method is called when {@link #acquire()} is called * for the first time. It schedules a task to be executed at fixed rate to * monitor the time period specified. * * @return a future object representing the task scheduled */ protected ScheduledFuture<?> startTimer() { return getExecutorService().scheduleAtFixedRate(new Runnable() { @Override public void run() { endOfPeriod(); } }, getPeriod(), getPeriod(), getUnit()); }
/** * Starts the timer. This method is called when {@link #acquire()} is called * for the first time. It schedules a task to be executed at fixed rate to * monitor the time period specified. * * @return a future object representing the task scheduled */ protected ScheduledFuture<?> startTimer() { return getExecutorService().scheduleAtFixedRate(new Runnable() { @Override public void run() { endOfPeriod(); } }, getPeriod(), getPeriod(), getUnit()); }