|
@@ -38,40 +38,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
*/
|
|
|
public final class ConnectionProfile {
|
|
|
|
|
|
- /**
|
|
|
- * 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,
|
|
|
- @Nullable TimeValue connectTimeout,
|
|
|
- @Nullable TimeValue handshakeTimeout) {
|
|
|
- Builder builder = new Builder();
|
|
|
- builder.addConnections(1, channelType);
|
|
|
- final EnumSet<TransportRequestOptions.Type> otherTypes = EnumSet.allOf(TransportRequestOptions.Type.class);
|
|
|
- otherTypes.remove(channelType);
|
|
|
- builder.addConnections(0, otherTypes.stream().toArray(TransportRequestOptions.Type[]::new));
|
|
|
- if (connectTimeout != null) {
|
|
|
- builder.setConnectTimeout(connectTimeout);
|
|
|
- }
|
|
|
- if (handshakeTimeout != null) {
|
|
|
- builder.setHandshakeTimeout(handshakeTimeout);
|
|
|
- }
|
|
|
- return builder.build();
|
|
|
- }
|
|
|
-
|
|
|
- private final List<ConnectionTypeHandle> handles;
|
|
|
- private final int numConnections;
|
|
|
- private final TimeValue connectTimeout;
|
|
|
- private final TimeValue handshakeTimeout;
|
|
|
-
|
|
|
- private ConnectionProfile(List<ConnectionTypeHandle> handles, int numConnections, TimeValue connectTimeout,
|
|
|
- TimeValue handshakeTimeout) {
|
|
|
- this.handles = handles;
|
|
|
- this.numConnections = numConnections;
|
|
|
- this.connectTimeout = connectTimeout;
|
|
|
- this.handshakeTimeout = handshakeTimeout;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* takes a {@link ConnectionProfile} resolves it to a fully specified (i.e., no nulls) profile
|
|
|
*/
|
|
@@ -79,7 +45,8 @@ public final class ConnectionProfile {
|
|
|
Objects.requireNonNull(fallbackProfile);
|
|
|
if (profile == null) {
|
|
|
return fallbackProfile;
|
|
|
- } else if (profile.getConnectTimeout() != null && profile.getHandshakeTimeout() != null) {
|
|
|
+ } else if (profile.getConnectTimeout() != null && profile.getHandshakeTimeout() != null
|
|
|
+ && profile.getCompressionEnabled() != null) {
|
|
|
return profile;
|
|
|
} else {
|
|
|
ConnectionProfile.Builder builder = new ConnectionProfile.Builder(profile);
|
|
@@ -89,6 +56,9 @@ public final class ConnectionProfile {
|
|
|
if (profile.getHandshakeTimeout() == null) {
|
|
|
builder.setHandshakeTimeout(fallbackProfile.getHandshakeTimeout());
|
|
|
}
|
|
|
+ if (profile.getCompressionEnabled() == null) {
|
|
|
+ builder.setCompressionEnabled(fallbackProfile.getCompressionEnabled());
|
|
|
+ }
|
|
|
return builder.build();
|
|
|
}
|
|
|
}
|
|
@@ -108,6 +78,7 @@ public final class ConnectionProfile {
|
|
|
Builder builder = new Builder();
|
|
|
builder.setConnectTimeout(TransportService.TCP_CONNECT_TIMEOUT.get(settings));
|
|
|
builder.setHandshakeTimeout(TransportService.TCP_CONNECT_TIMEOUT.get(settings));
|
|
|
+ builder.setCompressionEnabled(Transport.TRANSPORT_TCP_COMPRESS.get(settings));
|
|
|
builder.addConnections(connectionsPerNodeBulk, TransportRequestOptions.Type.BULK);
|
|
|
builder.addConnections(connectionsPerNodePing, TransportRequestOptions.Type.PING);
|
|
|
// if we are not master eligible we don't need a dedicated channel to publish the state
|
|
@@ -118,13 +89,77 @@ public final class ConnectionProfile {
|
|
|
return builder.build();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Builds a connection profile that is dedicated to a single channel type. Allows passing compression
|
|
|
+ * settings.
|
|
|
+ */
|
|
|
+ public static ConnectionProfile buildSingleChannelProfile(TransportRequestOptions.Type channelType, boolean compressionEnabled) {
|
|
|
+ return buildSingleChannelProfile(channelType, null, null, compressionEnabled);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Builds a connection profile that is dedicated to a single channel type. Allows passing connection and
|
|
|
+ * handshake timeouts.
|
|
|
+ */
|
|
|
+ public static ConnectionProfile buildSingleChannelProfile(TransportRequestOptions.Type channelType, @Nullable TimeValue connectTimeout,
|
|
|
+ @Nullable TimeValue handshakeTimeout) {
|
|
|
+ return buildSingleChannelProfile(channelType, connectTimeout, handshakeTimeout, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Builds a connection profile that is dedicated to a single channel type. Allows passing connection and
|
|
|
+ * handshake timeouts and compression settings.
|
|
|
+ */
|
|
|
+ public static ConnectionProfile buildSingleChannelProfile(TransportRequestOptions.Type channelType, @Nullable TimeValue connectTimeout,
|
|
|
+ @Nullable TimeValue handshakeTimeout, @Nullable Boolean compressionEnabled) {
|
|
|
+ Builder builder = new Builder();
|
|
|
+ builder.addConnections(1, channelType);
|
|
|
+ final EnumSet<TransportRequestOptions.Type> otherTypes = EnumSet.allOf(TransportRequestOptions.Type.class);
|
|
|
+ otherTypes.remove(channelType);
|
|
|
+ builder.addConnections(0, otherTypes.toArray(new TransportRequestOptions.Type[0]));
|
|
|
+ if (connectTimeout != null) {
|
|
|
+ builder.setConnectTimeout(connectTimeout);
|
|
|
+ }
|
|
|
+ if (handshakeTimeout != null) {
|
|
|
+ builder.setHandshakeTimeout(handshakeTimeout);
|
|
|
+ }
|
|
|
+ if (compressionEnabled != null) {
|
|
|
+ builder.setCompressionEnabled(compressionEnabled);
|
|
|
+ }
|
|
|
+ return builder.build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private final List<ConnectionTypeHandle> handles;
|
|
|
+ private final int numConnections;
|
|
|
+ private final TimeValue connectTimeout;
|
|
|
+ private final TimeValue handshakeTimeout;
|
|
|
+ private final Boolean compressionEnabled;
|
|
|
+
|
|
|
+ private ConnectionProfile(List<ConnectionTypeHandle> handles, int numConnections, TimeValue connectTimeout,
|
|
|
+ TimeValue handshakeTimeout, Boolean compressionEnabled) {
|
|
|
+ this.handles = handles;
|
|
|
+ this.numConnections = numConnections;
|
|
|
+ this.connectTimeout = connectTimeout;
|
|
|
+ this.handshakeTimeout = handshakeTimeout;
|
|
|
+ this.compressionEnabled = compressionEnabled;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* A builder to build a new {@link ConnectionProfile}
|
|
|
*/
|
|
|
public static class Builder {
|
|
|
private final List<ConnectionTypeHandle> handles = new ArrayList<>();
|
|
|
private final Set<TransportRequestOptions.Type> addedTypes = EnumSet.noneOf(TransportRequestOptions.Type.class);
|
|
|
- private int offset = 0;
|
|
|
+ private int numConnections = 0;
|
|
|
+ private Boolean compressionEnabled;
|
|
|
private TimeValue connectTimeout;
|
|
|
private TimeValue handshakeTimeout;
|
|
|
|
|
@@ -135,10 +170,11 @@ public final class ConnectionProfile {
|
|
|
/** copy constructor, using another profile as a base */
|
|
|
public Builder(ConnectionProfile source) {
|
|
|
handles.addAll(source.getHandles());
|
|
|
- offset = source.getNumConnections();
|
|
|
+ numConnections = source.getNumConnections();
|
|
|
handles.forEach(th -> addedTypes.addAll(th.types));
|
|
|
connectTimeout = source.getConnectTimeout();
|
|
|
handshakeTimeout = source.getHandshakeTimeout();
|
|
|
+ compressionEnabled = source.getCompressionEnabled();
|
|
|
}
|
|
|
/**
|
|
|
* Sets a connect timeout for this connection profile
|
|
@@ -160,6 +196,13 @@ public final class ConnectionProfile {
|
|
|
this.handshakeTimeout = handshakeTimeout;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets compression enabled for this connection profile
|
|
|
+ */
|
|
|
+ public void setCompressionEnabled(boolean compressionEnabled) {
|
|
|
+ this.compressionEnabled = compressionEnabled;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Adds a number of connections for one or more types. Each type can only be added once.
|
|
|
* @param numConnections the number of connections to use in the pool for the given connection types
|
|
@@ -175,8 +218,8 @@ public final class ConnectionProfile {
|
|
|
}
|
|
|
}
|
|
|
addedTypes.addAll(Arrays.asList(types));
|
|
|
- handles.add(new ConnectionTypeHandle(offset, numConnections, EnumSet.copyOf(Arrays.asList(types))));
|
|
|
- offset += numConnections;
|
|
|
+ handles.add(new ConnectionTypeHandle(this.numConnections, numConnections, EnumSet.copyOf(Arrays.asList(types))));
|
|
|
+ this.numConnections += numConnections;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -189,7 +232,8 @@ public final class ConnectionProfile {
|
|
|
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), offset, connectTimeout, handshakeTimeout);
|
|
|
+ return new ConnectionProfile(Collections.unmodifiableList(handles), numConnections, connectTimeout, handshakeTimeout,
|
|
|
+ compressionEnabled);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -208,6 +252,14 @@ public final class ConnectionProfile {
|
|
|
return handshakeTimeout;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Returns boolean indicating if compression is enabled or <code>null</code> if no explicit compression
|
|
|
+ * is set on this profile.
|
|
|
+ */
|
|
|
+ public Boolean getCompressionEnabled() {
|
|
|
+ return compressionEnabled;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Returns the total number of connections for this profile
|
|
|
*/
|