com.twitter.util.TimeoutException Java Examples

The following examples show how to use com.twitter.util.TimeoutException. 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: DistributedTranslog.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static void createLog(Settings settings, String indexName, String indexUUID, int shardId, String localNodeId) throws IOException {
    int retryNum = 0;
    while (true) {
        try {
            String tmpLogName = getLogName(indexName, indexUUID, shardId);
            DistributedLogNamespace logNamespace = DLNamespace.getNamespace(settings, localNodeId);
            boolean isLogExist = logNamespace.logExists(tmpLogName);
            if (!isLogExist) {
                logNamespace.createLog(tmpLogName);
                continue;
            }
            return;
        } catch (Throwable t) {
            ++ retryNum;
            if ((t instanceof TimeoutException || t.getCause() instanceof TimeoutException) && retryNum <= 5) {
                continue;
            } else {
                throw t;
            }
        }
    }
}
 
Example #2
Source File: ZKSessionLock.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Override
public void unlock() {
    Future<BoxedUnit> unlockResult = asyncUnlock();
    try {
        Await.result(unlockResult, Duration.fromMilliseconds(lockOpTimeout));
    } catch (TimeoutException toe) {
        // This shouldn't happen unless we lose a watch, and may result in a leaked lock.
        LOG.error("Timeout unlocking {} owned by {} : ", new Object[] { lockPath, lockId, toe });
    } catch (Exception e) {
        LOG.warn("{} failed to unlock {} : ", new Object[] { lockId, lockPath, e });
    }
}
 
Example #3
Source File: TestBKLogReadHandler.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testLockStreamSameSubscriber() throws Exception {
    String streamName = runtime.getMethodName();
    BKDistributedLogManager bkdlm = createNewDLM(conf, streamName);
    DLMTestUtil.generateLogSegmentNonPartitioned(bkdlm, 0, 5, 1);
    BKLogReadHandler readHandler = bkdlm.createReadHandler();
    Await.result(readHandler.lockStream());

    // same subscrbiers couldn't lock stream in parallel
    BKDistributedLogManager bkdlm10 = createNewDLM(conf, streamName);
    BKLogReadHandler s10Handler =
            bkdlm10.createReadHandler(Optional.of("s1"));
    Await.result(s10Handler.lockStream());

    BKDistributedLogManager bkdlm11 = createNewDLM(conf, streamName);
    BKLogReadHandler s11Handler =
            bkdlm11.createReadHandler(Optional.of("s1"));
    try {
        Await.result(s11Handler.lockStream(), Duration.apply(10000, TimeUnit.MILLISECONDS));
        fail("Should fail lock stream using same subscriber id");
    } catch (OwnershipAcquireFailedException oafe) {
        // expected
    } catch (TimeoutException te) {
        // expected.
    }

    readHandler.asyncClose();
    bkdlm.close();
    s10Handler.asyncClose();
    bkdlm10.close();
    s11Handler.asyncClose();
    bkdlm11.close();
}