/** * Shutdown this session instance, only waiting a definite amount of time. * * <p>This closes all connections used by this sessions. Note that if you want to shutdown the * full {@code Cluster} instance this session is part of, you should use {@link Cluster#shutdown} * instead (which will call this method for all session but also release some additional * resources). * * <p>Note that this method is not thread safe in the sense that if another shutdown is perform in * parallel, it might return {@code true} even if the instance is not yet fully shutdown. * * @param timeout how long to wait for the session to shutdown. * @param unit the unit for the timeout. * @return {@code true} if the session has been properly shutdown within the {@code timeout}, * {@code false} otherwise. */ public boolean shutdown(long timeout, TimeUnit unit) { try { return manager.shutdown(timeout, unit); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return false; } }
public Manager(Cluster cluster, Collection<Host> hosts) { this.cluster = cluster; this.pools = new ConcurrentHashMap<Host, HostConnectionPool>(hosts.size()); this.poolsState = new HostConnectionPool.PoolState(); // Create pool to initial nodes (and wait for them to be created) for (Host host : hosts) { try { addOrRenewPool(host).get(); } catch (ExecutionException e) { // This is not supposed to happen throw new DriverInternalError(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
private PreparedStatement toPreparedStatement(String query, Connection.Future future) { try { Message.Response response = Uninterruptibles.getUninterruptibly(future); switch (response.type) { case RESULT: ResultMessage rm = (ResultMessage) response; switch (rm.kind) { case PREPARED: ResultMessage.Prepared pmsg = (ResultMessage.Prepared) rm; PreparedStatement stmt = PreparedStatement.fromMessage( pmsg, manager.cluster.getMetadata(), query, manager.poolsState.keyspace); try { manager.cluster.manager.prepare(pmsg.statementId, stmt, future.getAddress()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // This method doesn't propagate interruption, at least not for now. However, if // we've // interrupted preparing queries on other node it's not a problem as we'll // re-prepare // later if need be. So just ignore. } return stmt; default: throw new DriverInternalError( String.format( "%s response received when prepared statement was expected", rm.kind)); } case ERROR: ResultSetFuture.extractCause( ResultSetFuture.convertException(((ErrorMessage) response).error)); break; default: throw new DriverInternalError( String.format( "%s response received when prepared statement was expected", response.type)); } throw new AssertionError(); } catch (ExecutionException e) { ResultSetFuture.extractCauseFromExecutionException(e); throw new AssertionError(); } }