protected Executor(String name, int maxThreads) { this.id = seqids.incrementAndGet(); this.name = name; // create the thread pool executor this.threadPoolExecutor = new TrackingThreadPoolExecutor( maxThreads, maxThreads, keepAliveTimeInMillis, TimeUnit.MILLISECONDS, q); // name the threads for this threadpool ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setNameFormat(this.name + "-%d"); tfb.setDaemon(true); this.threadPoolExecutor.setThreadFactory(tfb.build()); }
/** * Start an executor service with a given name. If there was a service already * started with the same name, this throws a RuntimeException. * @param name Name of the service to start. */ @VisibleForTesting public void startExecutorService(String name, int maxThreads) { if (this.executorMap.get(name) != null) { throw new RuntimeException("An executor service with the name " + name + " is already running!"); } Executor hbes = new Executor(name, maxThreads); if (this.executorMap.putIfAbsent(name, hbes) != null) { throw new RuntimeException("An executor service with the name " + name + " is already running (2)!"); } LOG.debug("Starting executor service name=" + name + ", corePoolSize=" + hbes.threadPoolExecutor.getCorePoolSize() + ", maxPoolSize=" + hbes.threadPoolExecutor.getMaximumPoolSize()); }
public ExecutorStatus getStatus() { List<EventHandler> queuedEvents = Lists.newArrayList(); for (Runnable r : q) { if (!(r instanceof EventHandler)) { LOG.warn("Non-EventHandler " + r + " queued in " + name); continue; } queuedEvents.add((EventHandler)r); } List<RunningEventStatus> running = Lists.newArrayList(); for (Map.Entry<Thread, Runnable> e : threadPoolExecutor.getRunningTasks().entrySet()) { Runnable r = e.getValue(); if (!(r instanceof EventHandler)) { LOG.warn("Non-EventHandler " + r + " running in " + name); continue; } running.add(new RunningEventStatus(e.getKey(), (EventHandler)r)); } return new ExecutorStatus(this, queuedEvents, running); } }
public ExecutorStatus getStatus() { List<EventHandler> queuedEvents = Lists.newArrayList(); for (Runnable r : q) { if (!(r instanceof EventHandler)) { LOG.warn("Non-EventHandler " + r + " queued in " + name); continue; } queuedEvents.add((EventHandler)r); } List<RunningEventStatus> running = Lists.newArrayList(); for (Map.Entry<Thread, Runnable> e : threadPoolExecutor.getRunningTasks().entrySet()) { Runnable r = e.getValue(); if (!(r instanceof EventHandler)) { LOG.warn("Non-EventHandler " + r + " running in " + name); continue; } running.add(new RunningEventStatus(e.getKey(), (EventHandler)r)); } return new ExecutorStatus(this, queuedEvents, running); } }
public ExecutorStatus getStatus() { List<EventHandler> queuedEvents = Lists.newArrayList(); for (Runnable r : q) { if (!(r instanceof EventHandler)) { LOG.warn("Non-EventHandler " + r + " queued in " + name); continue; } queuedEvents.add((EventHandler)r); } List<RunningEventStatus> running = Lists.newArrayList(); for (Map.Entry<Thread, Runnable> e : threadPoolExecutor.getRunningTasks().entrySet()) { Runnable r = e.getValue(); if (!(r instanceof EventHandler)) { LOG.warn("Non-EventHandler " + r + " running in " + name); continue; } running.add(new RunningEventStatus(e.getKey(), (EventHandler)r)); } return new ExecutorStatus(this, queuedEvents, running); } }
/** * Start an executor service with a given name. If there was a service already * started with the same name, this throws a RuntimeException. * @param name Name of the service to start. */ void startExecutorService(String name, int maxThreads) { if (this.executorMap.get(name) != null) { throw new RuntimeException("An executor service with the name " + name + " is already running!"); } Executor hbes = new Executor(name, maxThreads, this.eventHandlerListeners); if (this.executorMap.putIfAbsent(name, hbes) != null) { throw new RuntimeException("An executor service with the name " + name + " is already running (2)!"); } LOG.debug("Starting executor service name=" + name + ", corePoolSize=" + hbes.threadPoolExecutor.getCorePoolSize() + ", maxPoolSize=" + hbes.threadPoolExecutor.getMaximumPoolSize()); }
/** * Start an executor service with a given name. If there was a service already * started with the same name, this throws a RuntimeException. * @param name Name of the service to start. */ void startExecutorService(String name, int maxThreads) { if (this.executorMap.get(name) != null) { throw new RuntimeException("An executor service with the name " + name + " is already running!"); } Executor hbes = new Executor(name, maxThreads, this.eventHandlerListeners); if (this.executorMap.putIfAbsent(name, hbes) != null) { throw new RuntimeException("An executor service with the name " + name + " is already running (2)!"); } LOG.debug("Starting executor service name=" + name + ", corePoolSize=" + hbes.threadPoolExecutor.getCorePoolSize() + ", maxPoolSize=" + hbes.threadPoolExecutor.getMaximumPoolSize()); }
/** * Submit the event to the queue for handling. * @param event */ void submit(final EventHandler event) { // If there is a listener for this type, make sure we call the before // and after process methods. EventHandlerListener listener = this.eventHandlerListeners.get(event.getEventType()); if (listener != null) { event.setListener(listener); } this.threadPoolExecutor.execute(event); }
protected Executor(String name, int maxThreads, final Map<EventType, EventHandlerListener> eventHandlerListeners) { this.id = seqids.incrementAndGet(); this.name = name; this.eventHandlerListeners = eventHandlerListeners; // create the thread pool executor this.threadPoolExecutor = new TrackingThreadPoolExecutor( maxThreads, maxThreads, keepAliveTimeInMillis, TimeUnit.MILLISECONDS, q); // name the threads for this threadpool ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setNameFormat(this.name + "-%d"); this.threadPoolExecutor.setThreadFactory(tfb.build()); }
/** * Submit the event to the queue for handling. * @param event */ void submit(final EventHandler event) { // If there is a listener for this type, make sure we call the before // and after process methods. EventHandlerListener listener = this.eventHandlerListeners.get(event.getEventType()); if (listener != null) { event.setListener(listener); } this.threadPoolExecutor.execute(event); }
public void shutdown() { for(Entry<String, Executor> entry: this.executorMap.entrySet()) { List<Runnable> wasRunning = entry.getValue().threadPoolExecutor.shutdownNow(); if (!wasRunning.isEmpty()) { LOG.info(entry.getValue() + " had " + wasRunning + " on shutdown"); } } this.executorMap.clear(); }
public void shutdown() { for(Entry<String, Executor> entry: this.executorMap.entrySet()) { List<Runnable> wasRunning = entry.getValue().threadPoolExecutor.shutdownNow(); if (!wasRunning.isEmpty()) { LOG.info(entry.getValue() + " had " + wasRunning + " on shutdown"); } } this.executorMap.clear(); }
protected Executor(String name, int maxThreads, final Map<EventHandler.EventType, EventHandlerListener> eventHandlerListeners) { this.id = seqids.incrementAndGet(); this.name = name; this.eventHandlerListeners = eventHandlerListeners; // create the thread pool executor this.threadPoolExecutor = new TrackingThreadPoolExecutor( maxThreads, maxThreads, keepAliveTimeInMillis, TimeUnit.MILLISECONDS, q); // name the threads for this threadpool ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); tfb.setNameFormat(this.name + "-%d"); this.threadPoolExecutor.setThreadFactory(tfb.build()); }
public void shutdown() { this.delayedSubmitTimer.shutdownNow(); for(Entry<String, Executor> entry: this.executorMap.entrySet()) { List<Runnable> wasRunning = entry.getValue().threadPoolExecutor.shutdownNow(); if (!wasRunning.isEmpty()) { LOG.info(entry.getValue() + " had " + wasRunning + " on shutdown"); } } this.executorMap.clear(); }
/** * Submit the event to the queue for handling. * @param event */ void submit(final EventHandler event) { // If there is a listener for this type, make sure we call the before // and after process methods. this.threadPoolExecutor.execute(event); }