pool = MoreExecutors.sameThreadExecutor(); } else { pool = Executors.newFixedThreadPool(threads, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Get-Partitions-Size-%d").build());
private void setup() { MetricsRegistry registry = new MetricsRegistry(); _timedExecutor = new ScheduledThreadPoolExecutor(1); _service = new ThreadPoolExecutor(10, 10, 10, TimeUnit.DAYS, new LinkedBlockingDeque<Runnable>()); _eventLoopGroup = new NioEventLoopGroup(10); _timer = new HashedWheelTimer(); NettyClientMetrics clientMetrics = new NettyClientMetrics(registry, "client_"); PooledNettyClientResourceManager rm = new PooledNettyClientResourceManager(_eventLoopGroup, _timer, clientMetrics); _pool = new KeyedPoolImpl<PooledNettyClientResourceManager.PooledClientConnection>(1, _maxActiveConnections, 300000, 10, rm, _timedExecutor, MoreExecutors.sameThreadExecutor(), registry); rm.setPool(_pool); _scatterGather = new ScatterGatherImpl(_pool, _service); for (AsyncReader r : _readerThreads) { r.start(); } }
@Override public Executor sameThreadExecutor() { return MoreExecutors.sameThreadExecutor(); } }
MyPooledResourceManager rm = new MyPooledResourceManager(true, null); AsyncPoolResourceManagerAdapter<String> adapter = new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null); MyPooledResourceManager rm = new MyPooledResourceManager(false, null); AsyncPoolResourceManagerAdapter<String> adapter = new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null);
@Test public void testCreateError() throws Exception { ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1); ExecutorService service = MoreExecutors.sameThreadExecutor(); int numKeys = 1; int numResourcesPerKey = 1; Map<ServerInstance, List<String>> resources = buildCreateMap(numKeys, numResourcesPerKey); TestResourceManager rm = new TestResourceManager(resources, resources, null, null); KeyedPool<String> kPool = new KeyedPoolImpl<>(0, 1, 1000L, 1000 * 60 * 60, rm, timedExecutor, service, null); AsyncResponseFuture<String> f = (AsyncResponseFuture<String>) kPool.checkoutObject(getKey(0), "none"); Assert.assertTrue(f.isDone()); Assert.assertNull(f.get()); Assert.assertNotNull(f.getError()); kPool.shutdown().get(); AggregatedPoolStats s = (AggregatedPoolStats) kPool.getStats(); s.refresh(); Assert.assertEquals(s.getTotalCreateErrors(), 1); }
MyPooledResourceManager rm = new MyPooledResourceManager(true, value); AsyncPoolResourceManagerAdapter<String> adapter = new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null); MyCallback callback = new MyCallback(); MyPooledResourceManager rm = new MyPooledResourceManager(true, null); AsyncPoolResourceManagerAdapter<String> adapter = new AsyncPoolResourceManagerAdapter<String>(key, rm, MoreExecutors.sameThreadExecutor(), null); MyCallback callback = new MyCallback();
MyPooledResourceManager rm = new MyPooledResourceManager(true, null); AsyncPoolResourceManagerAdapter<String> adapter = new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null); MyCallback callback = new MyCallback(); MyPooledResourceManager rm = new MyPooledResourceManager(false, null); AsyncPoolResourceManagerAdapter<String> adapter = new AsyncPoolResourceManagerAdapter<>(key, rm, MoreExecutors.sameThreadExecutor(), null); MyCallback callback = new MyCallback();
throws Exception { ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1); ExecutorService service = MoreExecutors.sameThreadExecutor(); int numKeys = 5; int numResourcesPerKey = 1;
@Test public void testDestroyError() throws Exception { ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1); ExecutorService service = MoreExecutors.sameThreadExecutor(); int numKeys = 1; int numResourcesPerKey = 1; Map<ServerInstance, List<String>> resources = buildCreateMap(numKeys, numResourcesPerKey); TestResourceManager rm = new TestResourceManager(resources, null, resources, null); KeyedPool<String> kPool = new KeyedPoolImpl<>(0, 5, 1000L, 1000 * 60 * 60, rm, timedExecutor, service, null); AsyncResponseFuture<String> f = (AsyncResponseFuture<String>) kPool.checkoutObject(getKey(0), "none"); String r = f.getOne(); Assert.assertTrue(f.isDone()); Assert.assertNull(f.getError()); // Create a countdown latch that waits for the attempt to delete the resource CountDownLatch latch = new CountDownLatch(1); rm.setCountDownLatch(latch); kPool.destroyObject(getKey(0), r); latch.await(); // shutdown kPool.shutdown().get(); AggregatedPoolStats s = (AggregatedPoolStats) kPool.getStats(); s.refresh(); Assert.assertEquals(s.getTotalDestroyErrors(), 1); }
throws Exception { ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1); ExecutorService service = MoreExecutors.sameThreadExecutor(); int numKeys = 5; int numResourcesPerKey = 5;
throws Exception { ScheduledExecutorService timedExecutor = new ScheduledThreadPoolExecutor(1); ExecutorService service = MoreExecutors.sameThreadExecutor(); int numKeys = 5; int numResourcesPerKey = 5;
/** * @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, defaultThreadFactory, MoreExecutors.sameThreadExecutor(), listener); }
public DefaultTransactionExecutor(TransactionSystemClient txClient, Iterable<TransactionAware> txAwares, RetryStrategy retryStrategy) { super(MoreExecutors.sameThreadExecutor()); this.txAwares = ImmutableList.copyOf(txAwares); this.txClient = txClient; this.retryStrategy = retryStrategy; }
public void testDirect() throws Exception { Shell shell = new BaseShell(BaseProcessFactory.ECHO); AsyncShell asyncShell = new AsyncShell(MoreExecutors.sameThreadExecutor(), shell); // BaseProcessContext ctx = BaseProcessContext.create(asyncShell, "hello").execute(); assertEquals(Status.TERMINATED, ((AsyncProcess)ctx.getProcess()).getStatus()); assertInstance(ShellResponse.Ok.class, ctx.getResponse()); assertEquals("hello", ctx.getOutput()); } }
@Override protected void configure() { bind(ListeningExecutorService.class).annotatedWith(named(PROPERTY_USER_THREADS)).toInstance(sameThreadExecutor()); bind(ListeningExecutorService.class).annotatedWith(named(PROPERTY_IO_WORKER_THREADS)).toInstance(sameThreadExecutor()); bind(HttpCommandExecutorService.class).toInstance(mock); }
@Override public void configure() { bind(ListeningExecutorService.class).annotatedWith(named(PROPERTY_USER_THREADS)).toInstance(sameThreadExecutor()); bind(ListeningExecutorService.class).annotatedWith(named(PROPERTY_IO_WORKER_THREADS)).toInstance(sameThreadExecutor()); bind(new TypeLiteral<Function<HttpRequest, HttpResponse>>() { }).toInstance(fn); bind(HttpCommandExecutorService.class).to(ExpectHttpCommandExecutorService.class); }
private AnonymousAttributesApi getAnonymousAttributesApi(URI queue) { return ContextBuilder.newBuilder( forClientMappedToAsyncClientOnEndpoint(AnonymousAttributesApi.class, AnonymousAttributesAsyncApi.class, queue.toASCIIString())) .modules(ImmutableSet.<Module> of(new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor()))) .buildApi(AnonymousAttributesApi.class); }
public Cluster(final DocumentNodeStore ds, final String repoId, int seed) throws IOException { this.ds = ds; this.gc = new MarkSweepGarbageCollector( new DocumentBlobReferenceRetriever(ds), (GarbageCollectableBlobStore) ds.getBlobStore(), MoreExecutors.sameThreadExecutor(), "./target", 5, 0, repoId); this.startDate = new Date(); this.seed = seed; this.repoId = repoId; }
@Test public void detectRegistryUpdate() throws Exception{ configHandler.initialize(nodeStore, sameThreadExecutor()); addBundlorConfigForAsset(); BundledTypesRegistry registry = configHandler.getRegistry(); assertEquals(1, registry.getBundlors().size()); DocumentBundlor assetBundlor = registry.getBundlors().get("app:Asset"); assertNotNull(assetBundlor); }
@Before public void setUp() throws IOException { indexCopier = new IndexCopier(sameThreadExecutor(), temporaryFolder.getRoot()); nrtFactory = new NRTIndexFactory(indexCopier, StatisticsProvider.NOOP); readerFactory = new DefaultIndexReaderFactory(Mounts.defaultMountInfoProvider(), indexCopier); LuceneIndexEditorContext.configureUniqueId(builder); }