org.apache.curator.utils.CloseableExecutorService Java Examples
The following examples show how to use
org.apache.curator.utils.CloseableExecutorService.
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: LeaderSelector.java From curator with Apache License 2.0 | 6 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param executorService thread pool to use * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, CloseableExecutorService executorService, LeaderSelectorListener listener) { Preconditions.checkNotNull(client, "client cannot be null"); PathUtils.validatePath(leaderPath); Preconditions.checkNotNull(listener, "listener cannot be null"); this.client = client; this.listener = new WrappedListener(this, listener); hasLeadership = false; this.executorService = executorService; mutex = new InterProcessMutex(client, leaderPath) { @Override protected byte[] getLockNodeBytes() { return (id.length() > 0) ? getIdBytes(id) : null; } }; }
Example #2
Source File: CuratorFacade.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 创建一个路径节点缓存,返回之前已调用{@link PathChildrenCache#start()}, * 你需要在使用完之后调用{@link PathChildrenCache#close()}关闭缓存节点; * 如果你忘记关闭,那么会在curator关闭的时候统一关闭。 * 更多线程安全问题,请查看类文档中提到的笔记。 * * @param path 父节点 * @param listener 缓存事件监听器,运行在逻辑线程,不必考虑线程安全。 * @return PathChildrenCache 不再使用时需要手动关闭!不要使用{@link PathChildrenCache}获取数据 * @throws Exception zk errors */ public CloseableHandle watchChildren(String path, @Nonnull PathChildrenCacheListener listener) throws Exception { // CloseableExecutorService这个还是不共享的好 CloseableExecutorService watcherService = clientMgr.newClosableExecutorService(); // 指定pathChildrenCache接收事件的线程,复用线程池,以节省开销。 PathChildrenCache pathChildrenCache = new PathChildrenCache(client, path, true, false, watcherService); // 先添加listener以确保不会遗漏事件 --- 使用EventLoop线程监听,消除同步,listener不必考虑线程安全问题。 pathChildrenCache.getListenable().addListener(listener, appEventLoop); // 避免外部忘记关闭 this.allocateNodeCache.add(pathChildrenCache); // 启动缓存 pathChildrenCache.start(PathChildrenCache.StartMode.NORMAL); return new CloseableHandle(pathChildrenCache); }
Example #3
Source File: LeaderSelector.java From xian with Apache License 2.0 | 6 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param executorService thread pool to use * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, CloseableExecutorService executorService, LeaderSelectorListener listener) { Preconditions.checkNotNull(client, "client cannot be null"); PathUtils.validatePath(leaderPath); Preconditions.checkNotNull(listener, "listener cannot be null"); this.client = client; this.listener = new WrappedListener(this, listener); hasLeadership = false; this.executorService = executorService; mutex = new InterProcessMutex(client, leaderPath) { @Override protected byte[] getLockNodeBytes() { return (id.length() > 0) ? getIdBytes(id) : null; } }; }
Example #4
Source File: ServiceCacheImpl.java From xian with Apache License 2.0 | 5 votes |
ServiceCacheImpl(ServiceDiscoveryImpl<T> discovery, String name, CloseableExecutorService executorService) { Preconditions.checkNotNull(discovery, "discovery cannot be null"); Preconditions.checkNotNull(name, "name cannot be null"); Preconditions.checkNotNull(executorService, "executorService cannot be null"); this.discovery = discovery; cache = new PathChildrenCache(discovery.getClient(), discovery.pathForName(name), true, false, executorService); cache.getListenable().addListener(this); }
Example #5
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param executorService Closeable ExecutorService to use for the PathChildrenCache's background thread. This service should be single threaded, otherwise the cache may see inconsistent results. */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService) { this.client = client.newWatcherRemoveCuratorFramework(); this.path = PathUtils.validatePath(path); this.cacheData = cacheData; this.dataIsCompressed = dataIsCompressed; this.executorService = executorService; ensureContainers = new EnsureContainers(client, path); }
Example #6
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path path to watch * @param mode caching mode * @deprecated use {@link #PathChildrenCache(CuratorFramework, String, boolean)} instead */ @Deprecated @SuppressWarnings("deprecation") public PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode) { this(client, path, mode != PathChildrenCacheMode.CACHE_PATHS_ONLY, false, new CloseableExecutorService(Executors.newSingleThreadExecutor(defaultThreadFactory), true)); }
Example #7
Source File: PathChildrenCache.java From xian with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param executorService Closeable ExecutorService to use for the PathChildrenCache's background thread. This getGroup should be single threaded, otherwise the cache may see inconsistent results. */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final CloseableExecutorService executorService) { this.client = client; this.path = PathUtils.validatePath(path); this.cacheData = cacheData; this.dataIsCompressed = dataIsCompressed; this.executorService = executorService; ensureContainers = new EnsureContainers(client, path); }
Example #8
Source File: PathChildrenCache.java From xian with Apache License 2.0 | 5 votes |
/** * @param client the client * @param path path to watch * @param mode caching mode * @deprecated use {@link #PathChildrenCache(CuratorFramework, String, boolean)} instead */ @Deprecated @SuppressWarnings("deprecation") public PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode) { this(client, path, mode != PathChildrenCacheMode.CACHE_PATHS_ONLY, false, new CloseableExecutorService(Executors.newSingleThreadExecutor(defaultThreadFactory), true)); }
Example #9
Source File: RefreshableTransportPool.java From jigsaw-payment with Apache License 2.0 | 4 votes |
public void setThreadFactory(ThreadFactory threadFactory) { this.executorService = new CloseableExecutorService( Executors.newSingleThreadExecutor(threadFactory), true); }
Example #10
Source File: CuratorClientMgr.java From fastjgame with Apache License 2.0 | 4 votes |
/** * 创建一个用于监听{@link PathChildrenCache}事件和拉取数据的executor */ public CloseableExecutorService newClosableExecutorService() { return new CloseableExecutorService(backgroundExecutor, false); }
Example #11
Source File: FragmentWorkManager.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public void start() { Metrics.newGauge(Metrics.join("fragments","active"), () -> fragmentExecutors.size()); bitContext = dbContext.get(); this.executor = Executors.newCachedThreadPool(); this.closeableExecutor = new CloseableExecutorService(executor); // start the internal rpc layer. this.allocator = context.getAllocator().newChildAllocator( "fragment-work-manager", context.getConfig().getLong("dremio.exec.rpc.bit.server.memory.data.reservation"), context.getConfig().getLong("dremio.exec.rpc.bit.server.memory.data.maximum")); this.ticketDepot = workloadTicketDepotProvider.get(); this.clerk = new QueriesClerk(ticketDepot); final ExitCallback callback = new ExitCallback() { @Override public void indicateIfSafeToExit() { FragmentWorkManager.this.indicateIfSafeToExit(); } }; maestroProxy = new MaestroProxy(maestroServiceClientFactoryProvider, jobTelemetryClientFactoryProvider, bitContext.getClusterCoordinator(), bitContext.getEndpoint(), bitContext.getOptionManager()); fragmentExecutors = new FragmentExecutors(maestroProxy, callback, pool.get(), bitContext.getOptionManager()); final ExecConnectionCreator connectionCreator = new ExecConnectionCreator(fabricServiceProvider.get().registerProtocol(new ExecProtocol(bitContext.getConfig(), allocator, fragmentExecutors))); final FragmentExecutorBuilder builder = new FragmentExecutorBuilder( clerk, maestroProxy, bitContext.getConfig(), bitContext.getClusterCoordinator(), executor, bitContext.getOptionManager(), connectionCreator, bitContext.getClasspathScan(), bitContext.getPlanReader(), bitContext.getNamespaceService(SystemUser.SYSTEM_USERNAME), sources.get(), contextInformationFactory.get(), bitContext.getFunctionImplementationRegistry(), bitContext.getDecimalFunctionImplementationRegistry(), context.getNodeDebugContextProvider(), bitContext.getSpillService(), ClusterCoordinator.Role.fromEndpointRoles(identity.get().getRoles()), jobResultsClientFactoryProvider, identity); executorService = new ExecutorServiceImpl(fragmentExecutors, bitContext, builder); statusThread = new FragmentStatusThread(fragmentExecutors, clerk, maestroProxy); statusThread.start(); Iterable<TaskPool.ThreadInfo> slicingThreads = pool.get().getSlicingThreads(); Set<Long> slicingThreadIds = Sets.newHashSet(); for (TaskPool.ThreadInfo slicingThread : slicingThreads) { slicingThreadIds.add(slicingThread.threadId); } statsCollectorThread = new ThreadsStatsCollector(slicingThreadIds); statsCollectorThread.start(); // This makes sense only on executor nodes. if (bitContext.isExecutor() && bitContext.getOptionManager().getOption(ExecConstants.ENABLE_HEAP_MONITORING)) { HeapClawBackStrategy strategy = new FailGreediestQueriesStrategy(fragmentExecutors, clerk); long thresholdPercentage = bitContext.getOptionManager().getOption(ExecConstants.HEAP_MONITORING_CLAWBACK_THRESH_PERCENTAGE); heapMonitorThread = new HeapMonitorThread(strategy, thresholdPercentage); heapMonitorThread.start(); } final String prefix = "rpc"; Metrics.newGauge(Metrics.join(prefix, "bit.data.current"), allocator::getAllocatedMemory); Metrics.newGauge(Metrics.join(prefix, "bit.data.peak"), allocator::getPeakMemoryAllocation); }
Example #12
Source File: RefreshableTransportPool.java From jigsaw-payment with Apache License 2.0 | 4 votes |
public void setExecutorService(ExecutorService executorService) { this.executorService = new CloseableExecutorService(executorService); }
Example #13
Source File: RefreshableTransportPool.java From jigsaw-payment with Apache License 2.0 | 4 votes |
public void setCloseableExecutorService( CloseableExecutorService executorService) { this.executorService = executorService; }
Example #14
Source File: ServiceCacheImpl.java From xian with Apache License 2.0 | 4 votes |
private static CloseableExecutorService convertThreadFactory(ThreadFactory threadFactory) { Preconditions.checkNotNull(threadFactory, "threadFactory cannot be null"); return new CloseableExecutorService(Executors.newSingleThreadExecutor(threadFactory)); }
Example #15
Source File: ServiceCacheImplExt.java From xian with Apache License 2.0 | 4 votes |
ServiceCacheImplExt(ServiceDiscoveryImpl<T> discovery, String name, CloseableExecutorService executorService) { super(discovery, name, executorService); nodeCache = new NodeCache(discovery.getClient(), discovery.pathForName(name)); }
Example #16
Source File: ServiceCacheImplExt.java From xian with Apache License 2.0 | 4 votes |
private static CloseableExecutorService convertThreadFactory(ThreadFactory threadFactory) { Preconditions.checkNotNull(threadFactory, "threadFactory cannot be null"); return new CloseableExecutorService(Executors.newSingleThreadExecutor(threadFactory)); }
Example #17
Source File: LeaderSelector.java From curator with Apache License 2.0 | 3 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param threadFactory factory to use for making internal threads * @param executor the executor to run in * @param listener listener * @deprecated This constructor was poorly thought out. Custom executor is useless. Use this version instead: {@link #LeaderSelector(CuratorFramework, String, ExecutorService, LeaderSelectorListener)} */ @SuppressWarnings("UnusedParameters") @Deprecated public LeaderSelector(CuratorFramework client, String leaderPath, ThreadFactory threadFactory, Executor executor, LeaderSelectorListener listener) { this(client, leaderPath, new CloseableExecutorService(wrapExecutor(executor), true), listener); }
Example #18
Source File: LeaderSelector.java From xian with Apache License 2.0 | 3 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param threadFactory factory to use for making internal threads * @param executor the executor to run in * @param listener listener * @deprecated This constructor was poorly thought out. Custom executor is useless. Use this version instead: {@link #LeaderSelector(CuratorFramework, String, ExecutorService, LeaderSelectorListener)} */ @SuppressWarnings("UnusedParameters") @Deprecated public LeaderSelector(CuratorFramework client, String leaderPath, ThreadFactory threadFactory, Executor executor, LeaderSelectorListener listener) { this(client, leaderPath, new CloseableExecutorService(wrapExecutor(executor), true), listener); }
Example #19
Source File: PathChildrenCache.java From xian with Apache License 2.0 | 3 votes |
/** * @param client the client * @param path path to watch * @param mode caching mode * @param threadFactory factory to use when creating internal threads * @deprecated use {@link #PathChildrenCache(CuratorFramework, String, boolean, ThreadFactory)} instead */ @Deprecated @SuppressWarnings("deprecation") public PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode, ThreadFactory threadFactory) { this(client, path, mode != PathChildrenCacheMode.CACHE_PATHS_ONLY, false, new CloseableExecutorService(Executors.newSingleThreadExecutor(threadFactory), true)); }
Example #20
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 3 votes |
/** * @param client the client * @param path path to watch * @param mode caching mode * @param threadFactory factory to use when creating internal threads * @deprecated use {@link #PathChildrenCache(CuratorFramework, String, boolean, ThreadFactory)} instead */ @Deprecated @SuppressWarnings("deprecation") public PathChildrenCache(CuratorFramework client, String path, PathChildrenCacheMode mode, ThreadFactory threadFactory) { this(client, path, mode != PathChildrenCacheMode.CACHE_PATHS_ONLY, false, new CloseableExecutorService(Executors.newSingleThreadExecutor(threadFactory), true)); }
Example #21
Source File: PathChildrenCache.java From xian with Apache License 2.0 | 2 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param threadFactory factory to use when creating internal threads */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, ThreadFactory threadFactory) { this(client, path, cacheData, dataIsCompressed, new CloseableExecutorService(Executors.newSingleThreadExecutor(threadFactory), true)); }
Example #22
Source File: LeaderSelector.java From curator with Apache License 2.0 | 2 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param executorService thread pool to use * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, ExecutorService executorService, LeaderSelectorListener listener) { this(client, leaderPath, new CloseableExecutorService(executorService), listener); }
Example #23
Source File: LeaderSelector.java From curator with Apache License 2.0 | 2 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, LeaderSelectorListener listener) { this(client, leaderPath, new CloseableExecutorService(Executors.newSingleThreadExecutor(defaultThreadFactory), true), listener); }
Example #24
Source File: LeaderSelector.java From xian with Apache License 2.0 | 2 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, LeaderSelectorListener listener) { this(client, leaderPath, new CloseableExecutorService(Executors.newSingleThreadExecutor(defaultThreadFactory), true), listener); }
Example #25
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 2 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param executorService ExecutorService to use for the PathChildrenCache's background thread. This service should be single threaded, otherwise the cache may see inconsistent results. */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final ExecutorService executorService) { this(client, path, cacheData, dataIsCompressed, new CloseableExecutorService(executorService)); }
Example #26
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 2 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param threadFactory factory to use when creating internal threads */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, ThreadFactory threadFactory) { this(client, path, cacheData, dataIsCompressed, new CloseableExecutorService(Executors.newSingleThreadExecutor(threadFactory), true)); }
Example #27
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 2 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param threadFactory factory to use when creating internal threads */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, ThreadFactory threadFactory) { this(client, path, cacheData, false, new CloseableExecutorService(Executors.newSingleThreadExecutor(threadFactory), true)); }
Example #28
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 2 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData) { this(client, path, cacheData, false, new CloseableExecutorService(Executors.newSingleThreadExecutor(defaultThreadFactory), true)); }
Example #29
Source File: PathChildrenCache.java From xian with Apache License 2.0 | 2 votes |
/** * @param client the client * @param path path to watch * @param cacheData if true, node contents are cached in addition to the stat * @param dataIsCompressed if true, data in the path is compressed * @param executorService ExecutorService to use for the PathChildrenCache's background thread. This getGroup should be single threaded, otherwise the cache may see inconsistent results. */ public PathChildrenCache(CuratorFramework client, String path, boolean cacheData, boolean dataIsCompressed, final ExecutorService executorService) { this(client, path, cacheData, dataIsCompressed, new CloseableExecutorService(executorService)); }
Example #30
Source File: LeaderSelector.java From xian with Apache License 2.0 | 2 votes |
/** * @param client the client * @param leaderPath the path for this leadership group * @param executorService thread pool to use * @param listener listener */ public LeaderSelector(CuratorFramework client, String leaderPath, ExecutorService executorService, LeaderSelectorListener listener) { this(client, leaderPath, new CloseableExecutorService(executorService), listener); }