/** copy constructor, using another profile as a base */ public Builder(ConnectionProfile source) { handles.addAll(source.getHandles()); numConnections = source.getNumConnections(); handles.forEach(th -> addedTypes.addAll(th.types)); connectTimeout = source.getConnectTimeout(); handshakeTimeout = source.getHandshakeTimeout(); compressionEnabled = source.getCompressionEnabled(); pingInterval = source.getPingInterval(); } /**
/** * Creates a new {@link ConnectionProfile} based on the added connections. * @throws IllegalStateException if any of the {@link org.elasticsearch.transport.TransportRequestOptions.Type} enum is missing */ public ConnectionProfile build() { EnumSet<TransportRequestOptions.Type> types = EnumSet.allOf(TransportRequestOptions.Type.class); types.removeAll(addedTypes); if (types.isEmpty() == false) { throw new IllegalStateException("not all types are added for this connection profile - missing types: " + types); } return new ConnectionProfile(Collections.unmodifiableList(handles), numConnections, connectTimeout, handshakeTimeout, pingInterval, compressionEnabled); }
/** * Builds a connection profile that is dedicated to a single channel type. Use this * when opening single use connections */ public static ConnectionProfile buildSingleChannelProfile(TransportRequestOptions.Type channelType) { return buildSingleChannelProfile(channelType, null, null, null, null); }
NodeChannels(DiscoveryNode node, List<TcpChannel> channels, ConnectionProfile connectionProfile, Version handshakeVersion) { this.node = node; this.channels = Collections.unmodifiableList(channels); assert channels.size() == connectionProfile.getNumConnections() : "expected channels size to be == " + connectionProfile.getNumConnections() + " but was: [" + channels.size() + "]"; typeMapping = new EnumMap<>(TransportRequestOptions.Type.class); for (ConnectionProfile.ConnectionTypeHandle handle : connectionProfile.getHandles()) { for (TransportRequestOptions.Type type : handle.getTypes()) typeMapping.put(type, handle); } version = handshakeVersion; compress = connectionProfile.getCompressionEnabled(); }
/** * takes a {@link ConnectionProfile} resolves it to a fully specified (i.e., no nulls) profile */ public static ConnectionProfile resolveConnectionProfile(@Nullable ConnectionProfile profile, ConnectionProfile fallbackProfile) { Objects.requireNonNull(fallbackProfile); if (profile == null) { return fallbackProfile; } else if (profile.getConnectTimeout() != null && profile.getHandshakeTimeout() != null && profile.getPingInterval() != null && profile.getCompressionEnabled() != null) { return profile; } else { ConnectionProfile.Builder builder = new ConnectionProfile.Builder(profile); if (profile.getConnectTimeout() == null) { builder.setConnectTimeout(fallbackProfile.getConnectTimeout()); } if (profile.getHandshakeTimeout() == null) { builder.setHandshakeTimeout(fallbackProfile.getHandshakeTimeout()); } if (profile.getPingInterval() == null) { builder.setPingInterval(fallbackProfile.getPingInterval()); } if (profile.getCompressionEnabled() == null) { builder.setCompressionEnabled(fallbackProfile.getCompressionEnabled()); } return builder.build(); } }
/** copy constructor, using another profile as a base */ public Builder(ConnectionProfile source) { handles.addAll(source.getHandles()); offset = source.getNumConnections(); handles.forEach(th -> addedTypes.addAll(th.types)); connectTimeout = source.getConnectTimeout(); handshakeTimeout = source.getHandshakeTimeout(); } /**
/** * takes a {@link ConnectionProfile} resolves it to a fully specified (i.e., no nulls) profile */ public static ConnectionProfile resolveConnectionProfile(@Nullable ConnectionProfile profile, ConnectionProfile fallbackProfile) { Objects.requireNonNull(fallbackProfile); if (profile == null) { return fallbackProfile; } else if (profile.getConnectTimeout() != null && profile.getHandshakeTimeout() != null) { return profile; } else { ConnectionProfile.Builder builder = new ConnectionProfile.Builder(profile); if (profile.getConnectTimeout() == null) { builder.setConnectTimeout(fallbackProfile.getConnectTimeout()); } if (profile.getHandshakeTimeout() == null) { builder.setHandshakeTimeout(fallbackProfile.getHandshakeTimeout()); } return builder.build(); } }
public final class NodeChannels implements Connection { private final Map<TransportRequestOptions.Type, ConnectionProfile.ConnectionTypeHandle> typeMapping; private final List<TcpChannel> channels; private final DiscoveryNode node; private final AtomicBoolean closed = new AtomicBoolean(false); private final Version version; NodeChannels(DiscoveryNode node, List<TcpChannel> channels, ConnectionProfile connectionProfile, Version handshakeVersion) { this.node = node; this.channels = Collections.unmodifiableList(channels); assert channels.size() == connectionProfile.getNumConnections() : "expected channels size to be == " + connectionProfile.getNumConnections() + " but was: [" + channels.size() + "]"; typeMapping = new EnumMap<>(TransportRequestOptions.Type.class); for (ConnectionProfile.ConnectionTypeHandle handle : connectionProfile.getHandles()) { for (TransportRequestOptions.Type type : handle.getTypes()) typeMapping.put(type, handle); } version = handshakeVersion; } @Override public Version getVersion() { return version; } public List<TcpChannel> getChannels() { return channels; } public TcpChannel channel(TransportRequestOptions.Type type) {
private List<TcpChannel> initiateConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) { int numConnections = connectionProfile.getNumConnections(); assert numConnections > 0 : "A connection profile must be configured with at least one connection"; final List<TcpChannel> channels = new ArrayList<>(numConnections); for (int i = 0; i < numConnections; ++i) { try { TcpChannel channel = initiateChannel(node); logger.trace(() -> new ParameterizedMessage("Tcp transport client channel opened: {}", channel)); channels.add(channel); } catch (ConnectTransportException e) { CloseableChannel.closeChannels(channels, false); listener.onFailure(e); return channels; } catch (Exception e) { CloseableChannel.closeChannels(channels, false); listener.onFailure(new ConnectTransportException(node, "general node connection failure", e)); return channels; } } ChannelsConnectedListener channelsConnectedListener = new ChannelsConnectedListener(node, connectionProfile, channels, listener); for (TcpChannel channel : channels) { channel.addConnectListener(channelsConnectedListener); } TimeValue connectTimeout = connectionProfile.getConnectTimeout(); threadPool.schedule(connectTimeout, ThreadPool.Names.GENERIC, channelsConnectedListener::onTimeout); return channels; }
proxyAddress); final TransportService.HandshakeResponse handshakeResponse; ConnectionProfile profile = ConnectionProfile.buildSingleChannelProfile(TransportRequestOptions.Type.REG); Transport.Connection connection = manager.openConnection(seedNode, profile); boolean success = false; try { ConnectionProfile connectionProfile = connectionManager.getConnectionProfile(); handshakeResponse = transportService.handshake(connection, connectionProfile.getHandshakeTimeout().millis(), (c) -> remoteClusterName.get() == null ? true : c.equals(remoteClusterName.get())); } catch (IllegalStateException ex) {
public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener) { handshaker.sendHandshake(responseHandlers.newRequestId(), node, channel, profile.getHandshakeTimeout(), listener); }
+ "connect_timeout[{}], connections_per_node[{}/{}/{}/{}/{}], receive_predictor[{}->{}]", name, workerCount, profileSettings.portOrRange, profileSettings.bindHosts, profileSettings.publishHosts, compress, defaultConnectionProfile.getConnectTimeout(), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.RECOVERY), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.BULK), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.REG), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.STATE), defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.PING), receivePredictorMin, receivePredictorMax);
public void onTimeout() { if (countDown.fastForward()) { CloseableChannel.closeChannels(channels, false); listener.onFailure(new ConnectTransportException(node, "connect_timeout[" + connectionProfile.getConnectTimeout() + "]")); } } }
NodeChannels(DiscoveryNode node, List<TcpChannel> channels, ConnectionProfile connectionProfile, Version handshakeVersion) { this.node = node; this.channels = Collections.unmodifiableList(channels); assert channels.size() == connectionProfile.getNumConnections() : "expected channels size to be == " + connectionProfile.getNumConnections() + " but was: [" + channels.size() + "]"; typeMapping = new EnumMap<>(TransportRequestOptions.Type.class); for (ConnectionProfile.ConnectionTypeHandle handle : connectionProfile.getHandles()) { for (TransportRequestOptions.Type type : handle.getTypes()) typeMapping.put(type, handle); } version = handshakeVersion; }
public Transport.Connection openConnection(DiscoveryNode node, ConnectionProfile connectionProfile) { ConnectionProfile resolvedProfile = ConnectionProfile.resolveConnectionProfile(connectionProfile, defaultProfile); return internalOpenConnection(node, resolvedProfile); }
public ConnectionManager(Settings settings, Transport transport, ThreadPool threadPool) { this(ConnectionProfile.buildDefaultConnectionProfile(settings), transport, threadPool); }
NodeChannels(DiscoveryNode node, List<TcpChannel> channels, ConnectionProfile connectionProfile, Version handshakeVersion) { this.node = node; this.channels = Collections.unmodifiableList(channels); assert channels.size() == connectionProfile.getNumConnections() : "expected channels size to be == " + connectionProfile.getNumConnections() + " but was: [" + channels.size() + "]"; typeMapping = new EnumMap<>(TransportRequestOptions.Type.class); for (ConnectionProfile.ConnectionTypeHandle handle : connectionProfile.getHandles()) { for (TransportRequestOptions.Type type : handle.getTypes()) typeMapping.put(type, handle); } version = handshakeVersion; }
/** copy constructor, using another profile as a base */ public Builder(ConnectionProfile source) { handles.addAll(source.getHandles()); offset = source.getNumConnections(); handles.forEach(th -> addedTypes.addAll(th.types)); connectTimeout = source.getConnectTimeout(); handshakeTimeout = source.getHandshakeTimeout(); } /**
/** * takes a {@link ConnectionProfile} resolves it to a fully specified (i.e., no nulls) profile */ public static ConnectionProfile resolveConnectionProfile(@Nullable ConnectionProfile profile, ConnectionProfile fallbackProfile) { Objects.requireNonNull(fallbackProfile); if (profile == null) { return fallbackProfile; } else if (profile.getConnectTimeout() != null && profile.getHandshakeTimeout() != null) { return profile; } else { ConnectionProfile.Builder builder = new ConnectionProfile.Builder(profile); if (profile.getConnectTimeout() == null) { builder.setConnectTimeout(fallbackProfile.getConnectTimeout()); } if (profile.getHandshakeTimeout() == null) { builder.setHandshakeTimeout(fallbackProfile.getHandshakeTimeout()); } return builder.build(); } }
ensureOpen(); try { int numConnections = connectionProfile.getNumConnections(); assert numConnections > 0 : "A connection profile must be configured with at least one connection"; List<TcpChannel> channels = new ArrayList<>(numConnections); TcpChannel.awaitConnected(node, connectionFutures, connectionProfile.getConnectTimeout()); } catch (Exception ex) { TcpChannel.closeChannels(channels, false); Version version; try { version = executeHandshake(node, handshakeChannel, connectionProfile.getHandshakeTimeout()); } catch (Exception ex) { TcpChannel.closeChannels(channels, false);