@Test public void testIdleServiceManager() throws InterruptedException { ServiceElement serviceElement = TestUtil.makeServiceElement("bar", "foo", 2); IdleServiceManager idleServiceManager = new IdleServiceManager(3000L, serviceElement); TestServiceActivityProvider sap1 = new TestServiceActivityProvider(); TestServiceActivityProvider sap2 = new TestServiceActivityProvider(); idleServiceManager.addService(sap1); Listener l = new Listener(); ServiceChannel.getInstance().subscribe(l, serviceElement, ServiceChannelEvent.Type.IDLE); Thread.sleep(1000); idleServiceManager.addService(sap2); sap1.active = false; Thread.sleep(1000); sap2.active = false; int i = 0; long t0 = System.currentTimeMillis(); while(l.notified==0 && i<10) { Thread.sleep(500); i++; } System.out.println("Waited "+(System.currentTimeMillis()-t0)+" millis"); Assert.assertTrue(l.notified == 1); }
public IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement) { this.maxIdleTime = maxIdleTime; this.serviceElement = serviceElement; long delay = TimeUtil.computeLeaseRenewalTime(maxIdleTime); if(logger.isDebugEnabled()) { logger.debug("Service [{}] idle time: {}, computed delay time for checking idle status: {}.", LoggingUtil.getLoggingName(serviceElement), TimeUtil.format(maxIdleTime), TimeUtil.format(delay)); } scheduledExecutorService.scheduleWithFixedDelay(new IdleChecker(delay), delay, delay, TimeUnit.MILLISECONDS); }
IdleServiceManager { public IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement) { this.maxIdleTime = maxIdleTime; this.serviceElement = serviceElement; long delay = TimeUtil.computeLeaseRenewalTime(maxIdleTime); if(logger.isDebugEnabled()) { logger.debug("Service [{}] idle time: {}, computed delay time for checking idle status: {}.", LoggingUtil.getLoggingName(serviceElement), TimeUtil.format(maxIdleTime), TimeUtil.format(delay)); } scheduledExecutorService.scheduleWithFixedDelay(new IdleChecker(delay), delay, delay, TimeUnit.MILLISECONDS); } }
IdleServiceManager { public IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement) { this.maxIdleTime = maxIdleTime; this.serviceElement = serviceElement; long delay = TimeUtil.computeLeaseRenewalTime(maxIdleTime); if(logger.isDebugEnabled()) { logger.debug("Service [{}] idle time: {}, computed delay time for checking idle status: {}.", LoggingUtil.getLoggingName(serviceElement), TimeUtil.format(maxIdleTime), TimeUtil.format(delay)); } scheduledExecutorService.scheduleWithFixedDelay(new IdleChecker(delay), delay, delay, TimeUnit.MILLISECONDS); } IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement); }
IdleServiceManager { public IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement) { this.maxIdleTime = maxIdleTime; this.serviceElement = serviceElement; long delay = TimeUtil.computeLeaseRenewalTime(maxIdleTime); if(logger.isDebugEnabled()) { logger.debug("Service [{}] idle time: {}, computed delay time for checking idle status: {}.", LoggingUtil.getLoggingName(serviceElement), TimeUtil.format(maxIdleTime), TimeUtil.format(delay)); } scheduledExecutorService.scheduleWithFixedDelay(new IdleChecker(delay), delay, delay, TimeUnit.MILLISECONDS); } IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement); void addService(final ServiceActivityProvider service); void removeService(final ServiceActivityProvider service); void terminate(); }
IdleServiceManager { public IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement) { this.maxIdleTime = maxIdleTime; this.serviceElement = serviceElement; long delay = TimeUtil.computeLeaseRenewalTime(maxIdleTime); if(logger.isDebugEnabled()) { logger.debug("Service [{}] idle time: {}, computed delay time for checking idle status: {}.", LoggingUtil.getLoggingName(serviceElement), TimeUtil.format(maxIdleTime), TimeUtil.format(delay)); } scheduledExecutorService.scheduleWithFixedDelay(new IdleChecker(delay), delay, delay, TimeUnit.MILLISECONDS); } IdleServiceManager(final Long maxIdleTime, final ServiceElement serviceElement); void addService(final ServiceActivityProvider service); void removeService(final ServiceActivityProvider service); void terminate();  }