use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class ConnectionSharingChannelPoolManagerFactory method shutdown.
@Override
public void shutdown(Callback<None> callback) {
MultiCallback multiCallback = new MultiCallback(callback, 3);
shutdownChannelPoolManagers(multiCallback, channelPoolManagerMapRest);
shutdownChannelPoolManagers(multiCallback, channelPoolManagerMapStream);
shutdownChannelPoolManagers(multiCallback, channelPoolManagerMapHttp2Stream);
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class ConnectionSharingChannelPoolManagerFactory method shutdownChannelPoolManagers.
private void shutdownChannelPoolManagers(Callback<None> callback, Map<ChannelPoolManagerKey, ChannelPoolManager> channelPoolManagerMap) {
if (channelPoolManagerMap.size() == 0) {
callback.onSuccess(None.none());
} else {
MultiCallback multiCallback = new MultiCallback(callback, channelPoolManagerMap.size());
channelPoolManagerMap.forEach((channelPoolManagerKey, channelPoolManager) -> channelPoolManager.shutdown(multiCallback, () -> {
}, () -> {
}, 1000));
}
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class TestSmoothRateLimiter method testSubmitExceedsMaxBufferedButNoReject.
@Test(timeOut = TEST_TIMEOUT)
public void testSubmitExceedsMaxBufferedButNoReject() throws InterruptedException, ExecutionException, TimeoutException {
SmoothRateLimiter rateLimiter = new SmoothRateLimiter(_scheduledExecutorService, _executor, _clock, _queue, 0, SmoothRateLimiter.BufferOverflowMode.SCHEDULE_WITH_WARNING, RATE_LIMITER_NAME_TEST);
rateLimiter.setRate(ONE_PERMIT_PER_PERIOD, ONE_SECOND_PERIOD, UNLIMITED_BURST);
int numberOfTasks = 100;
FutureCallback<None> callback = new FutureCallback<>();
Callback<None> callbacks = new MultiCallback(callback, numberOfTasks);
for (int i = 0; i < numberOfTasks; i++) {
try {
rateLimiter.submit(callbacks);
} catch (RejectedExecutionException e) {
Assert.fail("It should have just run a task and not throw a RejectedExecutionException");
}
}
callback.get(5, TimeUnit.SECONDS);
Assert.assertTrue("The tasks should run", callback.isDone());
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class LastSeenLoadBalancerWithFacilities method shutdown.
@Override
public void shutdown(final PropertyEventThread.PropertyEventShutdownCallback callback) {
LOG.info("Shutting down");
MultiCallback multiCallback = new MultiCallback(new Callback<None>() {
@Override
public void onError(Throwable e) {
callback.done();
}
@Override
public void onSuccess(None result) {
callback.done();
}
}, 4);
_loadBalancer.shutdown(() -> multiCallback.onSuccess(None.none()));
try {
_zkPersistentConnection.shutdown();
} catch (InterruptedException e) {
LOG.info("Error in shutting down connection while shutting down load balancer");
}
_lsClusterStore.shutdown(multiCallback);
_lsServiceStore.shutdown(multiCallback);
_lsUrisStore.shutdown(multiCallback);
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpAndDownMultipleTimesFinalDown.
@Test(invocationCount = 10, timeOut = 10000)
public void testMarkUpAndDownMultipleTimesFinalDown() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZooKeeperConnectionManager manager = createManager(true, announcer);
// set up many concurrent callbacks
FutureCallback<None> allMarkupsDownsSucceed = new FutureCallback<>();
int count = 1;
Callback<None> markUpAllServersCallback = new MultiCallback(allMarkupsDownsSucceed, count * 2);
ExecutorService executorService = Executors.newScheduledThreadPool(100);
for (int i = 0; i < count; i++) {
executorService.execute(() -> {
manager.markUpAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
manager.markDownAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
});
}
allMarkupsDownsSucceed.get();
// data validation
ZooKeeperEphemeralStore<UriProperties> store = createAndStartUriStore();
AssertionMethods.assertWithTimeout(1000, () -> {
UriProperties properties = store.get(_cluster);
assertNotNull(properties);
assertNull(properties.getPartitionDataMap(URI.create(_uri)), _uri);
});
shutdownManager(manager);
executorService.shutdown();
}
Aggregations