Search in sources :

Example 6 with MultiCallback

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);
}
Also used : MultiCallback(com.linkedin.common.callback.MultiCallback)

Example 7 with MultiCallback

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));
    }
}
Also used : MultiCallback(com.linkedin.common.callback.MultiCallback)

Example 8 with MultiCallback

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());
}
Also used : SmoothRateLimiter(com.linkedin.r2.transport.http.client.SmoothRateLimiter) MultiCallback(com.linkedin.common.callback.MultiCallback) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.testng.annotations.Test)

Example 9 with MultiCallback

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);
}
Also used : MultiCallback(com.linkedin.common.callback.MultiCallback) None(com.linkedin.common.util.None)

Example 10 with 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();
}
Also used : UriProperties(com.linkedin.d2.balancer.properties.UriProperties) ExecutorService(java.util.concurrent.ExecutorService) MultiCallback(com.linkedin.common.callback.MultiCallback) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) Test(org.testng.annotations.Test)

Aggregations

MultiCallback (com.linkedin.common.callback.MultiCallback)11 None (com.linkedin.common.util.None)7 FutureCallback (com.linkedin.common.callback.FutureCallback)4 ExecutorService (java.util.concurrent.ExecutorService)4 Test (org.testng.annotations.Test)4 Callback (com.linkedin.common.callback.Callback)2 Request (com.linkedin.r2.message.Request)2 RequestContext (com.linkedin.r2.message.RequestContext)2 RestRequest (com.linkedin.r2.message.rest.RestRequest)2 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)2 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)2 TimingContextUtil (com.linkedin.r2.message.timing.TimingContextUtil)2 TimingImportance (com.linkedin.r2.message.timing.TimingImportance)2 TimingKey (com.linkedin.r2.message.timing.TimingKey)2 NettyClientState (com.linkedin.r2.netty.common.NettyClientState)2 UnknownSchemeException (com.linkedin.r2.netty.common.UnknownSchemeException)2 MessageType (com.linkedin.r2.transport.common.MessageType)2 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)2 TransportCallback (com.linkedin.r2.transport.common.bridge.common.TransportCallback)2