@Override protected void serviceInit(Configuration conf) throws Exception{ // create async handler dispatcher = new AsyncDispatcher(); dispatcher.init(conf); dispatcher.register(RMStateStoreEventType.class, new ForwardingEventHandler()); dispatcher.setDrainEventsOnStop(); initInternal(conf); }
@SuppressWarnings("rawtypes") protected EventHandler getRMStateStoreEventHandler() { return dispatcher.getEventHandler(); } }
protected void startDispatcher() { // start dispatcher AsyncDispatcher asyncDispatcher = (AsyncDispatcher) dispatcher; asyncDispatcher.start(); }
protected void initDispatcher(Configuration conf) { // create async handler dispatcher = new AsyncDispatcher("AttributeNodeLabelsManager dispatcher"); AsyncDispatcher asyncDispatcher = (AsyncDispatcher) dispatcher; asyncDispatcher.init(conf); asyncDispatcher.setDrainEventsOnStop(); }
@Test(timeout=20000) public void testCommitJobFailsJob() throws Exception { Configuration conf = new Configuration(); conf.set(MRJobConfig.MR_AM_STAGING_DIR, stagingDir); AsyncDispatcher dispatcher = new AsyncDispatcher(); dispatcher.init(conf); dispatcher.start(); CyclicBarrier syncBarrier = new CyclicBarrier(2); OutputCommitter committer = new TestingOutputCommitter(syncBarrier, false); CommitterEventHandler commitHandler = createCommitterEventHandler(dispatcher, committer); commitHandler.init(conf); commitHandler.start(); JobImpl job = createRunningStubbedJob(conf, dispatcher, 2, null); completeJobTasks(job); assertJobState(job, JobStateInternal.COMMITTING); // let the committer fail and verify the job fails syncBarrier.await(); assertJobState(job, JobStateInternal.FAILED); dispatcher.stop(); commitHandler.stop(); }
@Override public void serviceInit(Configuration conf) throws Exception { try { this.dispatcher = new AsyncDispatcher(); addService(this.dispatcher); this.dispatcher.register(QueryJobEvent.Type.class, new QueryJobManagerEventHandler()); TajoConf tajoConf = TUtil.checkTypeAndGet(conf, TajoConf.class); this.historyCache = new LRUMap(tajoConf.getIntVar(TajoConf.ConfVars.HISTORY_QUERY_CACHE_SIZE)); } catch (Exception e) { LOG.error("Failed to init service " + getName() + " by exception " + e, e); } super.serviceInit(conf); }
/** * Unit test friendly. */ protected AsyncDispatcher createNMDispatcher() { return new AsyncDispatcher("NM Event dispatcher"); }
@BeforeClass public static void setUp() throws Exception { util = new TajoTestingCluster(); util.startCatalogCluster(); conf = util.getConfiguration(); conf.set(TajoConf.ConfVars.$TEST_BROADCAST_JOIN_ENABLED.varname, "false"); catalog = util.getCatalogService(); catalog.createTablespace(DEFAULT_TABLESPACE_NAME, "hdfs://localhost:!234/warehouse"); catalog.createDatabase(DEFAULT_DATABASE_NAME, DEFAULT_TABLESPACE_NAME); TPCH tpch = new TPCH(); tpch.loadSchemas(); tpch.loadOutSchema(); for (String table : tpch.getTableNames()) { TableMeta m = CatalogUtil.newTableMeta(BuiltinStorages.TEXT, util.getConfiguration()); TableDesc d = CatalogUtil.newTableDesc( IdentifierUtil.buildFQName(DEFAULT_DATABASE_NAME, table), tpch.getSchema(table), m, CommonTestingUtil.getTestDir()); TableStats stats = new TableStats(); stats.setNumBytes(TPCH.tableVolumes.get(table)); d.setStats(stats); catalog.createTable(d); } analyzer = new SQLAnalyzer(); logicalPlanner = new LogicalPlanner(catalog, TablespaceManager.getInstance()); optimizer = new LogicalOptimizer(conf, catalog, TablespaceManager.getInstance()); dispatcher = new AsyncDispatcher(); dispatcher.init(conf); dispatcher.start(); planner = new GlobalPlanner(conf, catalog); }
EventHandler<JobHistoryEvent> timelineEventHandler = new ForwardingEventHandler(); atsEventDispatcher.register(EventType.class, timelineEventHandler); atsEventDispatcher.setDrainEventsOnStop(); atsEventDispatcher.init(conf);
@Override public void register(Class<? extends Enum> eventType, EventHandler handler) { for (AsyncDispatcher dispatcher : dispatchers) { dispatcher.register(eventType, handler); } }
protected void stopDispatcher() { AsyncDispatcher asyncDispatcher = (AsyncDispatcher) dispatcher; if (null != asyncDispatcher) { asyncDispatcher.stop(); } }
@Override public void run() { while (!stopped && !Thread.currentThread().isInterrupted()) { drained = eventQueue.isEmpty(); // blockNewEvents is only set when dispatcher is draining to stop, // adding this check is to avoid the overhead of acquiring the lock // and calling notify every time in the normal run of the loop. if (blockNewEvents) { synchronized (waitForDrained) { if (drained) { waitForDrained.notify(); } } } Event event; try { event = eventQueue.take(); } catch(InterruptedException ie) { if (!stopped) { LOG.warn("AsyncDispatcher thread interrupted", ie); } return; } if (event != null) { dispatch(event); } } } };
public void setDrainEventsOnStop() { for (AsyncDispatcher dispatcher : dispatchers) { dispatcher.setDrainEventsOnStop(); } }
@SuppressWarnings("unchecked") @Test(timeout=10000) public void testSchedulerEventDispatcherForPreemptionEvents() { AsyncDispatcher rmDispatcher = new AsyncDispatcher(); CapacityScheduler sched = spy(new CapacityScheduler()); YarnConfiguration conf = new YarnConfiguration(); SchedulerEventDispatcher schedulerDispatcher = new SchedulerEventDispatcher(sched); rmDispatcher.register(SchedulerEventType.class, schedulerDispatcher); rmDispatcher.init(conf); rmDispatcher.start(); schedulerDispatcher.init(conf); schedulerDispatcher.start(); ContainerPreemptEvent event1 = new ContainerPreemptEvent( appAttemptId, container, SchedulerEventType.DROP_RESERVATION); rmDispatcher.getEventHandler().handle(event1); ContainerPreemptEvent event2 = new ContainerPreemptEvent( appAttemptId, container, SchedulerEventType.KILL_CONTAINER); rmDispatcher.getEventHandler().handle(event2); ContainerPreemptEvent event3 = new ContainerPreemptEvent( appAttemptId, container, SchedulerEventType.PREEMPT_CONTAINER); rmDispatcher.getEventHandler().handle(event3); } finally { schedulerDispatcher.stop(); rmDispatcher.stop();
protected void initDispatcher(Configuration conf) { // create async handler dispatcher = new AsyncDispatcher(); AsyncDispatcher asyncDispatcher = (AsyncDispatcher) dispatcher; asyncDispatcher.init(conf); asyncDispatcher.setDrainEventsOnStop(); }
@Override public void serviceInit(Configuration conf) throws Exception { try { this.dispatcher = new AsyncDispatcher(); addService(this.dispatcher); this.dispatcher.register(QueryJobEvent.Type.class, new QueryJobManagerEventHandler()); TajoConf tajoConf = TUtil.checkTypeAndGet(conf, TajoConf.class); this.historyCache = new LRUMap(tajoConf.getIntVar(TajoConf.ConfVars.HISTORY_QUERY_CACHE_SIZE)); } catch (Exception e) { LOG.error("Failed to init service " + getName() + " by exception " + e, e); } super.serviceInit(conf); }
public QueryMasterTask(QueryMaster.QueryMasterContext queryMasterContext, QueryId queryId, Session session, QueryContext queryContext, String jsonExpr, NodeResource allocation) { this(queryMasterContext, queryId, session, queryContext, jsonExpr, allocation, new AsyncDispatcher()); }
@Override public void register(Class<? extends Enum> eventType, EventHandler handler) { for (AsyncDispatcher dispatcher : dispatchers) { dispatcher.register(eventType, handler); } }
protected void stopDispatcher() { AsyncDispatcher asyncDispatcher = (AsyncDispatcher) dispatcher; if (null != asyncDispatcher) { asyncDispatcher.stop(); } }
@Override public void run() { while (!stopped && !Thread.currentThread().isInterrupted()) { drained = eventQueue.isEmpty(); // blockNewEvents is only set when dispatcher is draining to stop, // adding this check is to avoid the overhead of acquiring the lock // and calling notify every time in the normal run of the loop. if (blockNewEvents) { synchronized (waitForDrained) { if (drained) { waitForDrained.notify(); } } } Event event; try { event = eventQueue.take(); } catch(InterruptedException ie) { if (!stopped) { LOG.warn("AsyncDispatcher thread interrupted", ie); } return; } if (event != null) { dispatch(event); } } } };