public ThirtySecondsCache(MetaBroadcaster metaBroadcaster, AtmosphereConfig config) { this.metaBroadcaster = metaBroadcaster; ExecutorsFactory.getScheduler(config).scheduleAtFixedRate(this, 0, 30, TimeUnit.SECONDS); }
protected synchronized void configExecutors() { if (shared) { handleExecutors = false; isExecutorShared = true; isAsyncExecutorShared = true; } executorService = ExecutorsFactory.getMessageDispatcher(config, broadcasterId); asyncWriteService = ExecutorsFactory.getAsyncOperationExecutor(config, broadcasterId); scheduler = ExecutorsFactory.getScheduler(config); }
asyncExecutor = ExecutorsFactory.getAsyncOperationExecutor(config, "WebSocket"); } else { asyncExecutor = VoidExecutorService.VOID; scheduler = ExecutorsFactory.getScheduler(config); optimizeMapping();
logger.info("Shared ExecutorService supported: {}", sharedThreadPools); ExecutorService executorService = ExecutorsFactory.getMessageDispatcher(config, Broadcaster.ROOT_MASTER); if (executorService != null) { if (ThreadPoolExecutor.class.isAssignableFrom(executorService.getClass())) { executorService = ExecutorsFactory.getAsyncOperationExecutor(config, Broadcaster.ROOT_MASTER); if (executorService != null) { if (ThreadPoolExecutor.class.isAssignableFrom(executorService.getClass())) {
void startConsumer() { consumer.subscribe(Arrays.asList(topic)); ExecutorsFactory.getMessageDispatcher(config, "kafka").execute(new Runnable() { @Override public void run() { while (!closed.get()) { ConsumerRecords<String, String> records = consumer.poll(1000); for (ConsumerRecord<String, String> record : records) { broadcastReceivedMessage(record.value()); } } consumer.close(); ((Set<String>)config.properties().get("topics")).remove(topic); } }); }
/** * Create a {@link ScheduledExecutorService} used ot schedule I/O and non I/O events. * * @param config the {@link AtmosphereConfig} * @return {@link ScheduledExecutorService} */ public static ScheduledExecutorService getScheduler(final AtmosphereConfig config) { final boolean shared = config.framework().isShareExecutorServices(); if (!shared || config.properties().get(SCHEDULER_THREAD_POOL) == null) { int threads = config.getInitParameter(ApplicationConfig.SCHEDULER_THREADPOOL_MAXSIZE, Runtime.getRuntime().availableProcessors()); logger.trace("Max number of Atmosphere-Scheduler {}", threads); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(threads, new ThreadFactory() { private final AtomicInteger count = new AtomicInteger(); @Override public Thread newThread(final Runnable runnable) { Thread t = new Thread(runnable, "Atmosphere-Scheduler-" + count.getAndIncrement()); t.setDaemon(true); return t; } }); if (shared) { config.properties().put(SCHEDULER_THREAD_POOL, scheduler); } keepAliveThreads((ThreadPoolExecutor) scheduler, config); return scheduler; } else { return (ScheduledExecutorService) config.properties().get(SCHEDULER_THREAD_POOL); } }
ExecutorsFactory.reset(config);
keepAliveThreads(messageService, config);
private void start() { if (future != null) { future.cancel(false); } if (maxInactiveTime > 0) { logger.info("{} started with idle timeout set to {}", IdleResourceInterceptor.class.getSimpleName(), maxInactiveTime); future = ExecutorsFactory.getScheduler(config).scheduleAtFixedRate(new Runnable() { public void run() { idleResources(); } }, 0, 2, TimeUnit.SECONDS); } }
keepAliveThreads(asyncWriteService, config);
@Override public void configure(AtmosphereConfig config) { Object o = config.properties().get("shared"); if (o != null) { isShared = Boolean.parseBoolean(o.toString()); } if (isShared) { reaper = ExecutorsFactory.getScheduler(config); } else { reaper = Executors.newSingleThreadScheduledExecutor(); } this.config = config; }
@Override public void configure(AtmosphereConfig config) { Object o = config.properties().get("shared"); if (o != null) { shared = Boolean.parseBoolean(o.toString()); } if (shared) { taskScheduler = ExecutorsFactory.getScheduler(config); } else { taskScheduler = Executors.newSingleThreadScheduledExecutor(); } clientIdleTime = TimeUnit.SECONDS.toMillis( Long.valueOf(config.getInitParameter(UUIDBROADCASTERCACHE_CLIENT_IDLETIME, "60"))); invalidateCacheInterval = TimeUnit.SECONDS.toMillis( Long.valueOf(config.getInitParameter(UUIDBROADCASTERCACHE_IDLE_CACHE_INTERVAL, "30"))); uuidProvider = config.uuidProvider(); }
@Override public void configure(AtmosphereConfig config) { factory = config.getBroadcasterFactory(); factory.addBroadcasterListener(new B()); stateTracker = ExecutorsFactory.getScheduler(config); String s = config.getInitParameter(STATE_RECOVERY_TIMEOUT); if (s != null) { timeout = Long.parseLong(s); } startStateTracker(); logger.trace("{} started.", AtmosphereResourceStateRecovery.class.getName()); }
@Override public void setBroadcasterConfig(BroadcasterConfig bc) { this.bc = bc; bc.setExecutorService(null, false).setAsyncWriteService(null, false) .setScheduledExecutorService(ExecutorsFactory.getScheduler(config)); }
heartBeat = ExecutorsFactory.getScheduler(config);
@Override protected BroadcasterConfig createBroadcasterConfig(AtmosphereConfig config) { BroadcasterConfig bc = (BroadcasterConfig) config.properties().get(BroadcasterConfig.class.getName()); if (bc == null) { bc = new BroadcasterConfig(config.framework().broadcasterFilters(), config, false, getID()) .init() .setScheduledExecutorService(ExecutorsFactory.getScheduler(config)); } return bc; }
/** * All proprietary Comet based {@link Servlet} must invoke the cancelled method when the underlying WebServer * detect that the client closed the connection. * * @param req the {@link AtmosphereRequest} * @param res the {@link AtmosphereResponse} * @return action the Action operation. * @throws java.io.IOException * @throws javax.servlet.ServletException */ public Action cancelled(final AtmosphereRequest req, final AtmosphereResponse res) throws IOException, ServletException { logger.trace("Cancelling {}", req); final AtmosphereResourceImpl r = AtmosphereResourceImpl.class.cast(req.resource()); // Leave a chance to the client to send the disconnect message before processing the connection if (closingTime > 0) { ExecutorsFactory.getScheduler(config).schedule(new Callable<Object>() { @Override public Object call() throws Exception { endRequest(r, true); return null; } }, closingTime, TimeUnit.MILLISECONDS); } else { if (completeLifecycle(req.resource(), true)) { config.framework().notify(Action.TYPE.CANCELLED, req, res); } } return cancelledAction; }
completeLifecycle = false; logger.debug("Delaying closing operation for firefox and resource {}", resource.uuid()); ExecutorsFactory.getScheduler(framework.getAtmosphereConfig()).schedule(new Callable<Object>() { @Override public Object call() throws Exception {
AtmosphereCoordinator() { framework = new AtmosphereFramework(); asynchronousProcessor = new NettyCometSupport(framework().getAtmosphereConfig()); framework.setAsyncSupport(asynchronousProcessor); suspendTimer = ExecutorsFactory.getScheduler(framework.getAtmosphereConfig()); mapper = framework.endPointMapper(); }
private AtmosphereCoordinator() { framework = new AtmosphereFramework(); asynchronousProcessor = new NettyCometSupport(framework().getAtmosphereConfig()); framework.setAsyncSupport(asynchronousProcessor); suspendTimer = ExecutorsFactory.getScheduler(framework.getAtmosphereConfig()); mapper = framework.endPointMapper(); }