@Override protected Connection tryReconnect() throws ConnectionException { if (isShutdown) throw new ConnectionException(null, "Control connection was shut down"); try { return reconnectInternal(queryPlan(), false); } catch (NoHostAvailableException e) { throw new ConnectionException(null, e.getMessage()); } catch (UnsupportedProtocolVersionException e) { // reconnectInternal only propagate those if we've not decided on the protocol version // yet, // which should only happen on the initial connection and thus in connect() but never // here. throw new AssertionError(); } }
/** @jira_ticket JAVA-1139 */ @Test(groups = "unit") public void getMessage_should_return_message_if_address_is_null() { assertEquals(new ConnectionException(null, "Test message").getMessage(), "Test message"); }
@Override public ConnectionException copy() { return new ConnectionException(address, getRawMessage(), this); }
/** @jira_ticket JAVA-1139 */ @Test(groups = "unit") public void getHost_should_return_null_if_address_is_null() { assertNull(new ConnectionException(null, "Test message").getHost()); }
@Override protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { if (logger.isDebugEnabled()) logger.debug( "Failed reconnection to {} ({}), scheduling retry in {} milliseconds", host, e.getMessage(), nextDelayMs); return true; }
@Override public String getMessage() { return address == null ? getRawMessage() : String.format("[%s] %s", address, getRawMessage()); }
@Override protected boolean onConnectionException(ConnectionException e, long nextDelayMs) { if (logger.isDebugEnabled()) logger.debug("Failed one-time reconnection to {} ({})", host, e.getMessage()); return false; }
/** @jira_ticket JAVA-1139 */ @Test(groups = "unit") public void getHost_should_return_null_if_address_is_null() { assertNull(new ConnectionException(null, "Test message").getHost()); }
@Override public String getMessage() { return address == null ? getRawMessage() : String.format("[%s] %s", address, getRawMessage()); }
final CloseFuture closeAsync() { CloseFuture future = closeFuture.get(); if (future != null) return future; phase.set(Phase.CLOSING); for (PendingBorrow pendingBorrow : pendingBorrows) { pendingBorrow.setException( new ConnectionException(host.getSocketAddress(), "Pool is shutdown")); } future = new CloseFuture.Forwarding(discardAvailableConnections()); return closeFuture.compareAndSet(null, future) ? future : closeFuture.get(); // We raced, it's ok, return the future that was actually set }
/** @jira_ticket JAVA-1139 */ @Test(groups = "unit") public void getMessage_should_return_message_if_address_is_unresolved() { assertEquals( new ConnectionException( InetSocketAddress.createUnresolved("127.0.0.1", 9042), "Test message") .getMessage(), "[127.0.0.1:9042] Test message"); }
void refreshNodeListAndTokenMap() { Connection c = connectionRef.get(); // At startup, when we add the initial nodes, this will be null, which is ok if (c == null || c.isClosed()) return; try { refreshNodeListAndTokenMap(c, cluster, false, true); } catch (ConnectionException e) { logger.debug( "[Control connection] Connection error while refreshing node list and token map ({})", e.getMessage()); signalError(); } catch (ExecutionException e) { // If we're being shutdown during refresh, this can happen. That's fine so don't scare the // user. if (!isShutdown) logger.error( "[Control connection] Unexpected error while refreshing node list and token map", e); signalError(); } catch (BusyConnectionException e) { logger.debug("[Control connection] Connection is busy, reconnecting"); signalError(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); logger.debug( "[Control connection] Interrupted while refreshing node list and token map, skipping it."); } }
@Override public ConnectionException copy() { return new ConnectionException(address, getRawMessage(), this); }
@Override public String getMessage() { return address == null ? getRawMessage() : String.format("[%s] %s", address, getRawMessage()); }
@Override public void onSuccess(List<Void> l) { // Some of the connections might have failed, keep only the successful ones ListIterator<Connection> it = connections.listIterator(); while (it.hasNext()) { if (it.next().isClosed()) it.remove(); } HostConnectionPool.this.connections.addAll(connections); open.set(connections.size()); if (isClosed()) { initFuture.setException( new ConnectionException( host.getSocketAddress(), "Pool was closed during initialization")); // we're not sure if closeAsync() saw the connections, so ensure they get closed forceClose(connections); } else { logger.debug( "Created connection pool to host {} ({} connections needed, {} successfully opened)", host, coreSize, connections.size()); phase.compareAndSet(Phase.INITIALIZING, Phase.READY); initFuture.set(null); } }
/** @jira_ticket JAVA-1139 */ @Test(groups = "unit") public void getMessage_should_return_message_if_address_is_resolved() { assertEquals( new ConnectionException(new InetSocketAddress("127.0.0.1", 9042), "Test message") .getMessage(), "[/127.0.0.1:9042] Test message"); } }
public void refreshSchema( SchemaElement targetType, String targetKeyspace, String targetName, List<String> signature) throws InterruptedException { logger.debug( "[Control connection] Refreshing schema for {}{}", targetType == null ? "everything" : targetKeyspace, (targetType == KEYSPACE) ? "" : "." + targetName + " (" + targetType + ")"); try { Connection c = connectionRef.get(); // At startup, when we add the initial nodes, this will be null, which is ok if (c == null || c.isClosed()) return; refreshSchema(c, targetType, targetKeyspace, targetName, signature, cluster); } catch (ConnectionException e) { logger.debug( "[Control connection] Connection error while refreshing schema ({})", e.getMessage()); signalError(); } catch (ExecutionException e) { // If we're being shutdown during schema refresh, this can happen. That's fine so don't scare // the user. if (!isShutdown) logger.error("[Control connection] Unexpected error while refreshing schema", e); signalError(); } catch (BusyConnectionException e) { logger.debug("[Control connection] Connection is busy, reconnecting"); signalError(); } }
@Override public ConnectionException copy() { return new ConnectionException(address, getRawMessage(), this); }
@Override public String getMessage() { return address == null ? getRawMessage() : String.format("[%s] %s", address, getRawMessage()); }
@Override public ListenableFuture<Void> apply(Throwable t) throws Exception { SettableFuture<Void> future = SettableFuture.create(); // Make sure the connection gets properly closed. if (t instanceof ClusterNameMismatchException || t instanceof UnsupportedProtocolVersionException) { // Just propagate closeAsync().force(); future.setException(t); } else { // Defunct to ensure that the error will be signaled (marking the host down) Throwable e = (t instanceof ConnectionException || t instanceof DriverException || t instanceof InterruptedException || t instanceof Error) ? t : new ConnectionException( Connection.this.address, String.format( "Unexpected error during transport initialization (%s)", t), t); future.setException(defunct(e)); } return future; } },