@Override public void start() throws Exception { if (this.executor == null) { this.executor = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelKubernetesLeaderNotifier"); } }
private void terminateApplicationContext(final ConfigurableApplicationContext applicationContext, final CamelContext camelContext, int seconds) { ScheduledExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelSpringBootTerminateTask"); Runnable task = () -> { LOG.info("CamelSpringBoot triggering shutdown of the JVM."); // we need to run a daemon thread to stop ourselves so this thread pool can be stopped nice also new Thread(applicationContext::close).start(); }; executorService.schedule(task, seconds, TimeUnit.SECONDS); }
@Override protected void doStart() throws Exception { this.scheduledExecutorService = this.executorServiceManager.newSingleThreadScheduledExecutor(this, "ConsulEventConsumer"); super.doStart(); }
private void terminateMainControllerAfter(final CamelContext camelContext, int seconds, final AtomicBoolean completed, final CountDownLatch latch) { ScheduledExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelSpringBootTerminateTask"); Runnable task = () -> { LOG.info("CamelSpringBoot triggering shutdown of the JVM."); try { camelContext.stop(); } catch (Throwable e) { LOG.warn("Error during stopping CamelContext", e); } finally { completed.set(true); latch.countDown(); } }; executorService.schedule(task, seconds, TimeUnit.SECONDS); }
/** * Returns the thread executor used for scheduling delayed connection events. Creates the executor * if it does not already exist */ private ScheduledExecutorService getExecutor() { if (this.mScheduledExecutor == null) { mScheduledExecutor = mJmxEndpoint.getCamelContext().getExecutorServiceManager() .newSingleThreadScheduledExecutor(this, "JMXConnectionExecutor"); } return mScheduledExecutor; }
@Override public void start() throws Exception { if (serializedExecutor == null) { LOG.debug("{} Starting leadership controller...", logPrefix()); serializedExecutor = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelKubernetesLeadershipController"); leaderNotifier = new TimedLeaderNotifier(this.camelContext, this.eventHandler); leaderNotifier.start(); serializedExecutor.execute(this::refreshStatus); } }
@Override protected void doStart() throws Exception { client = this.configuration.createConsulClient(getCamelContext()); scheduler = getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "ConsulServiceRegistry"); }
@Override protected void doStart() throws Exception { ObjectHelper.notNull(camelContext, "CamelContext", this); timeoutLogger = new CamelLogger(LOG, timeoutLoggingLevel); if (scheduledExecutorService == null) { scheduledExecutorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "NettyTimeoutCorrelationManager"); } if (workerPool == null) { workerPool = camelContext.getExecutorServiceManager().newDefaultThreadPool(this, "NettyTimeoutWorkerPool"); } map = new NettyStateTimeoutMap(scheduledExecutorService); ServiceHelper.startService(map); }
@Override protected void doStart() throws Exception { if (lock != null) { lock.unlock(); lock = null; } if (channel == null) { channel = new JChannel(jgroupsConfig); lockService = new LockService(channel); } channel.connect(jgroupsClusterName); lock = lockService.getLock(lockName); // Camel context should be set at this stage. final CamelContext context = ObjectHelper.notNull(getCamelContext(), "CamelContext"); executor = context.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "JGroupsLockClusterView-" + getClusterService().getId() + "-" + lockName); executor.execute(new Runnable() { @Override public void run() { LOG.info("Attempting to become master acquiring the lock for group: " + lockName + " in JGroups cluster" + jgroupsClusterName + " with configuration: " + jgroupsConfig); lock.lock(); isMaster = true; fireLeadershipChangedEvent(Optional.ofNullable(localMember)); LOG.info("Became master by acquiring the lock for group: " + lockName + " in JGroups cluster" + jgroupsClusterName + " with configuration: " + jgroupsConfig); } }); }
protected ReplyManager createReplyManager() throws Exception { // use a temporary queue ReplyManager replyManager = new TemporaryQueueReplyManager(getEndpoint().getCamelContext()); replyManager.setEndpoint(getEndpoint()); String name = "RabbitMQReplyManagerTimeoutChecker[" + getEndpoint().getExchangeName() + "]"; ScheduledExecutorService replyManagerExecutorService = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(name, name); replyManager.setScheduledExecutorService(replyManagerExecutorService); log.debug("Staring ReplyManager: {}", name); ServiceHelper.startService(replyManager); return replyManager; } }
@Override protected void doStart() throws Exception { // need to remember auth as Hadoop will override that, which otherwise means the Auth is broken afterwards Configuration auth = HdfsComponent.getJAASConfiguration(); try { super.doStart(); // setup hdfs if configured to do on startup if (getEndpoint().getConfig().isConnectOnStartup()) { ostream = setupHdfs(true); } SplitStrategy idleStrategy = null; for (SplitStrategy strategy : config.getSplitStrategies()) { if (strategy.type == SplitStrategyType.IDLE) { idleStrategy = strategy; break; } } if (idleStrategy != null) { scheduler = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "HdfsIdleCheck"); log.debug("Creating IdleCheck task scheduled to run every {} millis", config.getCheckIdleInterval()); scheduler.scheduleAtFixedRate(new IdleCheck(idleStrategy), config.getCheckIdleInterval(), config.getCheckIdleInterval(), TimeUnit.MILLISECONDS); } } finally { HdfsComponent.setJAASConfiguration(auth); } }
private void startService() { // validate StringHelper.notEmpty(lockMapName, "lockMapName", this); StringHelper.notEmpty(lockKey, "lockKey", this); StringHelper.notEmpty(lockValue, "lockValue", this); ObjectHelper.notNull(camelContext, "camelContext", this); try { this.manager.start(); this.executorService = getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "InfinispanRoutePolicy"); if (lifespanTimeUnit.convert(lifespan, TimeUnit.SECONDS) < 2) { throw new IllegalArgumentException("Lock lifespan can not be less that 2 seconds"); } if (manager.isCacheContainerEmbedded()) { BasicCache<String, String> cache = manager.getCache(lockMapName); this.service = new EmbeddedCacheService(InfinispanUtil.asEmbedded(cache)); } else { // By default, previously existing values for java.util.Map operations // are not returned for remote caches but policy needs it so force it. BasicCache<String, String> cache = manager.getCache(lockMapName, true); this.service = new RemoteCacheService(InfinispanUtil.asRemote(cache)); } service.start(); } catch (Exception e) { throw new RuntimeCamelException(e); } }
protected ReplyManager createReplyManager(String replyTo) throws Exception { // use a regular queue ReplyManager replyManager = new QueueReplyManager(getEndpoint().getCamelContext()); replyManager.setEndpoint(getEndpoint()); String name = "JmsReplyManagerTimeoutChecker[" + replyTo + "]"; ScheduledExecutorService replyManagerScheduledExecutorService = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(name, name); replyManager.setScheduledExecutorService(replyManagerScheduledExecutorService); name = "JmsReplyManagerOnTimeout[" + replyTo + "]"; // allow the timeout thread to timeout so during normal operation we do not have a idle thread int max = getEndpoint().getReplyToOnTimeoutMaxConcurrentConsumers(); if (max <= 0) { throw new IllegalArgumentException("The option replyToOnTimeoutMaxConcurrentConsumers must be >= 1"); } ExecutorService replyManagerExecutorService = getEndpoint().getCamelContext().getExecutorServiceManager().newThreadPool(replyManager, name, 0, max); replyManager.setOnTimeoutExecutorService(replyManagerExecutorService); ServiceHelper.startService(replyManager); return replyManager; }
protected ReplyManager createReplyManager() throws Exception { // use a temporary queue ReplyManager replyManager = new TemporaryQueueReplyManager(getEndpoint().getCamelContext()); replyManager.setEndpoint(getEndpoint()); String name = "JmsReplyManagerTimeoutChecker[" + getEndpoint().getEndpointConfiguredDestinationName() + "]"; ScheduledExecutorService replyManagerScheduledExecutorService = getEndpoint().getCamelContext().getExecutorServiceManager().newSingleThreadScheduledExecutor(name, name); replyManager.setScheduledExecutorService(replyManagerScheduledExecutorService); name = "JmsReplyManagerOnTimeout[" + getEndpoint().getEndpointConfiguredDestinationName() + "]"; // allow the timeout thread to timeout so during normal operation we do not have a idle thread int max = getEndpoint().getReplyToOnTimeoutMaxConcurrentConsumers(); if (max <= 0) { throw new IllegalArgumentException("The option replyToOnTimeoutMaxConcurrentConsumers must be >= 1"); } ExecutorService replyManagerExecutorService = getEndpoint().getCamelContext().getExecutorServiceManager().newThreadPool(replyManager, name, 0, max); replyManager.setOnTimeoutExecutorService(replyManagerExecutorService); ServiceHelper.startService(replyManager); return replyManager; }