use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class LastSeenLoadBalancerWithFacilities method start.
// #################### lifecycle ####################
@Override
public void start(final Callback<None> callback) {
try {
_zkPersistentConnection.start();
} catch (IOException e) {
LOG.error("Error in starting connection while starting load balancer. The connection be already started. " + "The LoadBalancer will continue booting up", e);
}
MultiCallback multiCallback = new MultiCallback(callback, 4);
_lsClusterStore.start(multiCallback);
_lsServiceStore.start(multiCallback);
_lsUrisStore.start(multiCallback);
_loadBalancer.start(multiCallback);
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class LastSeenZKStore method shutdown.
@Override
public void shutdown(Callback<None> shutdown) {
MultiCallback multiCallback = new MultiCallback(shutdown, 2);
_fsStore.shutdown(multiCallback);
_zkAwareStore.shutdown(multiCallback);
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpDuringSessionExpirationManyCallbacks.
@Test(invocationCount = 10, timeOut = 10000, retryAnalyzer = ThreeRetries.class)
public void testMarkUpDuringSessionExpirationManyCallbacks() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZKPersistentConnection zkPersistentConnection = getZkPersistentConnection();
ZooKeeperConnectionManager manager = createManager(true, zkPersistentConnection, announcer);
// set up many concurrent callbacks
FutureCallback<None> allMarkupsSucceed = new FutureCallback<>();
int count = 1000;
Callback<None> markUpAllServersCallback = new MultiCallback(allMarkupsSucceed, 2 * count);
ExecutorService executorService = Executors.newScheduledThreadPool(100);
for (int i = 0; i < count; i++) {
executorService.execute(() -> {
manager.markDownAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
manager.markUpAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
});
}
// expiring the connection
long oldSessionId = zkPersistentConnection.getZooKeeper().getSessionId();
ZKTestUtil.expireSession("localhost:" + PORT, zkPersistentConnection.getZooKeeper(), 10, TimeUnit.SECONDS);
ZKTestUtil.waitForNewSessionEstablished(oldSessionId, zkPersistentConnection, 10, TimeUnit.SECONDS);
try {
allMarkupsSucceed.get(1, TimeUnit.MILLISECONDS);
Assert.fail("All the callbacks were resolved before expiring the connection, which means it won't test that callbacks are invoked even after session expiration");
} catch (Throwable e) {
// expected
}
allMarkupsSucceed.get();
// making sure that a new connection has been established. There should be no need to wait, because at least one markup should have been run on
// the new connection, which means that by this part of code it should already have been established
ZKTestUtil.waitForNewSessionEstablished(oldSessionId, zkPersistentConnection, 0, TimeUnit.SECONDS);
// data validation
dataValidation(_uri, _cluster, WEIGHT);
shutdownManager(manager);
executorService.shutdown();
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class ZookeeperConnectionManagerTest method testMarkUpAndDownMultipleTimesFinalUp.
@Test(invocationCount = 10, timeOut = 10000, groups = { "ci-flaky" })
public void testMarkUpAndDownMultipleTimesFinalUp() throws Exception {
ZooKeeperAnnouncer announcer = getZooKeeperAnnouncer(_cluster, _uri, WEIGHT);
ZooKeeperConnectionManager manager = createManager(true, announcer);
FutureCallback<None> managerStartCallback = new FutureCallback<>();
manager.start(managerStartCallback);
managerStartCallback.get(10, TimeUnit.SECONDS);
// set up many concurrent callbacks
FutureCallback<None> allMarkupsDownsSucceed = new FutureCallback<>();
int count = 1000;
Callback<None> markUpAllServersCallback = new MultiCallback(allMarkupsDownsSucceed, count * 2);
ExecutorService executorService = Executors.newScheduledThreadPool(100);
for (int i = 0; i < count; i++) {
executorService.execute(() -> {
manager.markDownAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
manager.markUpAllServers(new IgnoreCancelledCallback(markUpAllServersCallback));
});
}
allMarkupsDownsSucceed.get();
// data validation
dataValidation(_uri, _cluster, WEIGHT);
shutdownManager(manager);
executorService.shutdown();
}
use of com.linkedin.common.callback.MultiCallback in project rest.li by linkedin.
the class HttpNettyClient method shutdown.
@Override
public void shutdown(Callback<None> callback) {
LOG.info("Shutdown requested");
if (_state.compareAndSet(NettyClientState.RUNNING, NettyClientState.SHUTTING_DOWN)) {
LOG.info("Shutting down");
MultiCallback poolShutdown = new MultiCallback(new Callback<None>() {
private void releaseCallbacks() {
_userCallbacks.forEach(transportCallback -> transportCallback.onResponse(TransportResponseImpl.error(new TimeoutException("Operation did not complete before shutdown"))));
}
@Override
public void onError(Throwable e) {
releaseCallbacks();
callback.onError(e);
}
@Override
public void onSuccess(None result) {
releaseCallbacks();
callback.onSuccess(result);
}
}, 2);
_channelPoolManager.shutdown(poolShutdown, () -> _state.set(NettyClientState.REQUESTS_STOPPING), () -> _state.set(NettyClientState.SHUTDOWN), _shutdownTimeout);
_sslChannelPoolManager.shutdown(poolShutdown, () -> _state.set(NettyClientState.REQUESTS_STOPPING), () -> _state.set(NettyClientState.SHUTDOWN), _shutdownTimeout);
} else {
callback.onError(new IllegalStateException("Shutdown has already been requested."));
}
TimingKey.unregisterKey(TIMING_KEY);
}
Aggregations