@Override public Future<Boolean> connect(final String clientId) throws Exception { if (isConnected()) { throw new Exception("You are already connected"); } // keep track of the original one, so we can detect change this.originalClientId = clientId; // this will help us do the connect synchronously connectLatch = new CountDownLatch(1); final Future connectFuture = connection.connect(); FutureTask<Boolean> asdf = new FutureTask<Boolean>( new Callable<Boolean>() { @Override public Boolean call() { // TODO: notify callers somehow? try { connectFuture.get(45, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } if (connection.isConnected()) { connection.send(new ConnectCommand(clientId)); // block while the signal server is thinking/hanging. try { connectLatch.await(45, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); } } final boolean result = isConnected(); // queue it up, or else the "connect()" call will still block while the slow-ass // observers fire. connectEvent.notifyObservers(this, result); return result; } }); // this background thread stops us from blocking. executor.execute(asdf); return asdf; }