/** 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(); } /**
void registerNodeConnection(List<TcpChannel> nodeChannels, ConnectionProfile connectionProfile) { TimeValue pingInterval = connectionProfile.getPingInterval(); if (pingInterval.millis() < 0) { return; } final ScheduledPing scheduledPing = pingIntervals.computeIfAbsent(pingInterval, ScheduledPing::new); scheduledPing.ensureStarted(); for (TcpChannel channel : nodeChannels) { scheduledPing.addChannel(channel); channel.addCloseListener(ActionListener.wrap(() -> { scheduledPing.removeChannel(channel); })); } }
/** * 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(); } }