Executor getExecutor(final ExecutorType type) { return getExecutor(type.getExecutorName(this.servername)); }
/** * 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); }
@Override public String toString() { return "Event #" + getSeqid() + " of type " + eventType + " (" + getInformativeName() + ")"; }
public void submit(final EventHandler eh) { Executor executor = getExecutor(eh.getEventType().getExecutorServiceType()); if (executor == null) { // This happens only when events are submitted after shutdown() was // called, so dropping them should be "ok" since it means we're // shutting down. LOG.error("Cannot submit [" + eh + "] because the executor is missing." + " Is this process shutting down?"); } else { executor.submit(eh); } }
public void startExecutorService(final ExecutorType type, final int maxThreads) { String name = type.getExecutorName(this.servername); if (isExecutorServiceRunning(name)) { LOG.debug("Executor service " + toString() + " already running on " + this.servername); return; } startExecutorService(name, maxThreads); }
/** * 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); } }
protected void dumpExecutors(ExecutorService service, PrintWriter out) throws IOException { if (service == null) { out.println("ExecutorService is not initialized"); return; } Map<String, ExecutorStatus> statuses = service.getAllExecutorStatuses(); for (ExecutorStatus status : statuses.values()) { status.dumpTo(out, " "); } } }
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()); }
@VisibleForTesting public ThreadPoolExecutor getExecutorThreadPool(final ExecutorType type) { return getExecutor(type).getThreadPoolExecutor(); }
@Override public void run() { try (TraceScope scope = TraceUtil.createTrace(this.getClass().getSimpleName(), parent)) { process(); } catch(Throwable t) { handleException(t); } }
public void executeProcedure(long procId, RSProcedureCallable callable) { executorService.submit(new RSProcedureHandler(this, procId, callable)); }
public Map<String, ExecutorStatus> getAllExecutorStatuses() { Map<String, ExecutorStatus> ret = Maps.newHashMap(); for (Map.Entry<String, Executor> e : executorMap.entrySet()) { ret.put(e.getKey(), e.getValue().getStatus()); } return ret; }
@After public void teardown() throws Exception { if (executorService != null) { executorService.shutdown(); } TEST_UTIL.shutdownMiniZKCluster(); }
/** * Default prioritized runnable comparator which implements a FIFO ordering. * <p> * Subclasses should not override this. Instead, if they want to implement * priority beyond FIFO, they should override {@link #getPriority()}. */ @Override public int compareTo(Runnable o) { EventHandler eh = (EventHandler)o; if(getPriority() != eh.getPriority()) { return (getPriority() < eh.getPriority()) ? -1 : 1; } return (this.seqid < eh.seqid) ? -1 : 1; }
/** * @return Conflation of the executor type and the passed {@code serverName}. */ String getExecutorName(String serverName) { return this.toString() + "-" + serverName.replace("%", "%%"); } }
@Override public TakeSnapshotHandler prepare() throws Exception { super.prepare(); // after this, you should ensure to release this lock in case of exceptions this.tableLock.acquire(); try { this.htd = loadTableDescriptor(); // check that .tableinfo is present } catch (Exception e) { this.tableLock.release(); throw e; } return this; }
public void delayedSubmit(EventHandler eh, long delay, TimeUnit unit) { ListenableFuture<?> future = delayedSubmitTimer.schedule(() -> submit(eh), delay, unit); future.addListener(() -> { try { future.get(); } catch (Exception e) { LOG.error("Failed to submit the event handler {} to executor", eh, e); } }, MoreExecutors.directExecutor()); }