List of usage examples for java.util.concurrent ScheduledFuture isCancelled
boolean isCancelled();
From source file:org.apache.hadoop.yarn.server.resourcemanager.security.TestX509SecurityHandler.java
@Test(timeout = 12000) public void testFailedCertificateRenewal() throws Exception { conf.set(YarnConfiguration.HOPS_RM_SECURITY_ACTOR_KEY, "org.apache.hadoop.yarn.server.resourcemanager.security.TestingRMAppSecurityActions"); RMAppSecurityManager securityManager = new RMAppSecurityManager(rmContext); MockX509SecurityHandler.MockFailingX509SecurityHandler x509Handler = new MockX509SecurityHandler.MockFailingX509SecurityHandler( rmContext, securityManager, Integer.MAX_VALUE); securityManager.registerRMAppSecurityHandlerWithType(x509Handler, X509SecurityHandler.class); securityManager.init(conf);//from w w w . ja v a2s. c om securityManager.start(); LocalDateTime now = DateUtils.getNow(); LocalDateTime expiration = now.plus(10, ChronoUnit.SECONDS); ApplicationId appId = ApplicationId.newInstance(DateUtils.localDateTime2UnixEpoch(now), 1); X509SecurityHandler.X509MaterialParameter x509Param = new X509SecurityHandler.X509MaterialParameter(appId, "Dolores", 1); x509Param.setExpiration(DateUtils.localDateTime2UnixEpoch(expiration)); x509Handler.registerRenewer(x509Param); Map<ApplicationId, ScheduledFuture> tasks = x509Handler.getRenewalTasks(); // There should be a scheduled task ScheduledFuture task = tasks.get(appId); assertFalse(task.isCancelled()); assertFalse(task.isDone()); assertFalse(x509Handler.hasRenewalFailed()); assertEquals(0, x509Handler.getNumberOfRenewalFailures()); TimeUnit.SECONDS.sleep(10); assertTrue(tasks.isEmpty()); assertEquals(4, x509Handler.getNumberOfRenewalFailures()); assertTrue(x509Handler.hasRenewalFailed()); securityManager.stop(); }
From source file:org.openhab.binding.lifx.internal.LifxLightDiscovery.java
@Override protected void startBackgroundDiscovery() { logger.debug("Starting the LIFX device background discovery"); ScheduledFuture<?> localDiscoveryJob = discoveryJob; if (localDiscoveryJob == null || localDiscoveryJob.isCancelled()) { discoveryJob = scheduler.scheduleWithFixedDelay(this::doScan, 0, REFRESH_INTERVAL, TimeUnit.SECONDS); }//from w ww . j a v a 2 s. c o m }
From source file:org.openhab.binding.lifx.internal.LifxLightDiscovery.java
@Override protected void stopBackgroundDiscovery() { logger.debug("Stopping LIFX device background discovery"); ScheduledFuture<?> localDiscoveryJob = discoveryJob; if (localDiscoveryJob != null && !localDiscoveryJob.isCancelled()) { localDiscoveryJob.cancel(true);// w ww.java 2s . com discoveryJob = null; } ScheduledFuture<?> localNetworkJob = networkJob; if (localNetworkJob != null && !localNetworkJob.isCancelled()) { localNetworkJob.cancel(true); networkJob = null; } }
From source file:org.openhab.binding.nest.internal.handler.NestBridgeHandler.java
/** * Clean up the handler.// w w w. j a va2 s .c om */ @Override public void dispose() { logger.debug("Nest bridge disposed"); stopStreamingUpdates(); ScheduledFuture<?> localInitializeJob = initializeJob; if (localInitializeJob != null && !localInitializeJob.isCancelled()) { localInitializeJob.cancel(true); initializeJob = null; } ScheduledFuture<?> localTransmitJob = transmitJob; if (localTransmitJob != null && !localTransmitJob.isCancelled()) { localTransmitJob.cancel(true); transmitJob = null; } this.authorizer = null; this.redirectUrlSupplier = null; this.streamingRestClient = null; }
From source file:org.openhab.binding.zoneminder.handler.ZoneMinderServerBridgeHandler.java
/** * Method to stop the datarefresh task./* ww w .j a v a 2s . c om*/ */ protected void stopTask(ScheduledFuture<?> task) { try { if (task != null && !task.isCancelled()) { logger.debug("{}: Stopping ZoneMinder Bridge Monitor Task. Task='{}'", getLogIdentifier(), task.toString()); task.cancel(true); } } catch (Exception ex) { } }