@Override public void run() { runThread = Thread.currentThread(); LOG.info("Starting runnable {}", name); SettableFuture<String> completionFuture = SettableFuture.create(); for (Service service : services) { service.addListener(createServiceListener(service.getClass().getName(), completionFuture), Threads.SAME_THREAD_EXECUTOR); } Futures.getUnchecked( Services.chainStart(services.get(0), services.subList(1, services.size()).toArray(new Service[0]))); LOG.info("Runnable started {}", name); try { // exit as soon as any service completes completionFuture.get(); } catch (InterruptedException e) { LOG.debug("Waiting on latch interrupted {}", name); } catch (ExecutionException e) { throw Throwables.propagate(e.getCause()); } }
@Override public final void initialize(TwillContext context) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler()); super.initialize(context); name = context.getSpecification().getName(); LOG.info("Initializing runnable {}", name); Map<String, String> configs = context.getSpecification().getConfigs(); try { // Load configuration hConf = new Configuration(); hConf.clear(); hConf.addResource(new File(configs.get("hConf")).toURI().toURL()); UserGroupInformation.setConfiguration(hConf); cConf = CConfiguration.create(new File(configs.get("cConf"))); LOG.debug("{} cConf {}", name, cConf); LOG.debug("{} HBase conf {}", name, hConf); Injector injector = doInit(context); services = Lists.newArrayList(); // Add common base services services.add(injector.getInstance(ZKClientService.class)); services.add(injector.getInstance(KafkaClientService.class)); services.add(injector.getInstance(BrokerService.class)); services.add(injector.getInstance(MetricsCollectionService.class)); addServices(services); Preconditions.checkArgument(!services.isEmpty(), "Should have at least one service"); LOG.info("Runnable initialized {}", name); } catch (Throwable t) { throw Throwables.propagate(t); } }
@Override public final void initialize(TwillContext context) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler()); super.initialize(context); name = context.getSpecification().getName(); LOG.info("Initializing runnable {}", name); Map<String, String> configs = context.getSpecification().getConfigs(); try { // Load configuration hConf = new Configuration(); hConf.clear(); hConf.addResource(new File(configs.get("hConf")).toURI().toURL()); UserGroupInformation.setConfiguration(hConf); cConf = CConfiguration.create(new File(configs.get("cConf"))); LOG.debug("{} cConf {}", name, cConf); LOG.debug("{} HBase conf {}", name, hConf); Injector injector = doInit(context); services = Lists.newArrayList(); // Add common base services services.add(injector.getInstance(ZKClientService.class)); services.add(injector.getInstance(KafkaClientService.class)); services.add(injector.getInstance(BrokerService.class)); services.add(injector.getInstance(MetricsCollectionService.class)); addServices(services); Preconditions.checkArgument(!services.isEmpty(), "Should have at least one service"); LOG.info("Runnable initialized {}", name); } catch (Throwable t) { throw Throwables.propagate(t); } }
@Override public void run() { runThread = Thread.currentThread(); LOG.info("Starting runnable {}", name); SettableFuture<String> completionFuture = SettableFuture.create(); for (Service service : services) { service.addListener(createServiceListener(service.getClass().getName(), completionFuture), Threads.SAME_THREAD_EXECUTOR); } Futures.getUnchecked( Services.chainStart(services.get(0), services.subList(1, services.size()).toArray(new Service[0]))); LOG.info("Runnable started {}", name); try { // exit as soon as any service completes completionFuture.get(); } catch (InterruptedException e) { LOG.debug("Waiting on latch interrupted {}", name); } catch (ExecutionException e) { throw Throwables.propagate(e.getCause()); } }