Here are the examples of the java api class taken from open source projects.

1. ClientWorkFlow#callWithTimeout()

Project: zanata-server
Source File:
View license
public List<String> callWithTimeout(final File workingDirectory, String command) {"=== about to call ===\n{}", command);
    final List<String> commands = Lists.newArrayList(Splitter.on(" ").split(command));
    SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter();
    Callable<List<String>> work = () -> {
        Process process = ClientWorkFlow.invokeClient(workingDirectory, commands);
        List<String> output = ClientWorkFlow.getOutput(process);
        return output;
    try {
        return timeLimiter.callWithTimeout(work, timeoutDuration, TimeUnit.SECONDS, true);
    } catch (Exception e) {
        throw new RuntimeException(e);

2. LdapConnector#connect()

Project: graylog2-server
Source File:
View license
public LdapNetworkConnection connect(LdapConnectionConfig config) throws LdapException {
    final LdapNetworkConnection connection = new LdapNetworkConnection(config);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Connecting to LDAP server {}:{}, binding with user {}", config.getLdapHost(), config.getLdapPort(), config.getName());
    // this will perform an anonymous bind if there were no system credentials
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("ldap-connector-%d").build();
    final SimpleTimeLimiter timeLimiter = new SimpleTimeLimiter(Executors.newSingleThreadExecutor(threadFactory));
    @SuppressWarnings("unchecked") final Callable<Boolean> timeLimitedConnection = timeLimiter.newProxy(new Callable<Boolean>() {

        public Boolean call() throws Exception {
            return connection.connect();
    }, Callable.class, connectionTimeout, TimeUnit.MILLISECONDS);
    try {
        final Boolean connected =;
        if (!connected) {
            return null;
    } catch (UncheckedTimeoutException e) {
        LOG.error("Timed out connecting to LDAP server", e);
        throw new LdapException("Could not connect to LDAP server", e.getCause());
    } catch (LdapException e) {
        throw e;
    } catch (Exception e) {
        throw new LdapException("Unexpected error connecting to LDAP", e);
    return connection;