Java Code Examples for org.apache.twill.common.Threads#createDaemonThreadFactory()
The following examples show how to use
org.apache.twill.common.Threads#createDaemonThreadFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TephraZKClientService.java From phoenix-tephra with Apache License 2.0 | 6 votes |
@Override protected void doStart() { // A single thread executor for all events ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), Threads.createDaemonThreadFactory("zk-client-EventThread")); // Just discard the execution if the executor is closed executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); eventExecutor = executor; try { zooKeeper.set(createZooKeeper()); } catch (IOException e) { notifyFailed(e); } }
Example 2
Source File: DefaultZKClientService.java From twill with Apache License 2.0 | 6 votes |
@Override protected void doStart() { // A single thread executor for all events ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), Threads.createDaemonThreadFactory("zk-client-EventThread")); // Just discard the execution if the executor is closed executor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy()); eventExecutor = executor; try { zooKeeper.set(createZooKeeper()); } catch (IOException e) { notifyFailed(e); } }
Example 3
Source File: AbstractTwillService.java From twill with Apache License 2.0 | 5 votes |
@Override protected final void startUp() throws Exception { // Single thread executor that will discard task silently if it is already terminated, which only // happens when this service is shutting down. messageCallbackExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), Threads.createDaemonThreadFactory("message-callback"), new ThreadPoolExecutor.DiscardPolicy()); // Watch for session expiration, recreate the live node if reconnected after expiration. watcherCancellable = zkClient.addConnectionWatcher(new Watcher() { private boolean expired = false; @Override public void process(WatchedEvent event) { if (event.getState() == Event.KeeperState.Expired) { LOG.warn("ZK Session expired for service {} with runId {}.", getServiceName(), runId.getId()); expired = true; } else if (event.getState() == Event.KeeperState.SyncConnected && expired) { LOG.info("Reconnected after expiration for service {} with runId {}", getServiceName(), runId.getId()); expired = false; logIfFailed(createLiveNode()); } } }); // Create the live node, if succeeded, start the service, otherwise fail out. createLiveNode().get(); // Create node for messaging ZKOperations.ignoreError(zkClient.create(getZKPath("messages"), null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null).get(); doStart(); // Starts watching for messages watchMessages(); }
Example 4
Source File: SimpleKafkaConsumer.java From twill with Apache License 2.0 | 4 votes |
private SimplePreparer() { this.requests = Maps.newHashMap(); this.threadFactory = Threads.createDaemonThreadFactory("message-callback-%d"); }