Skip to content

Commit

Permalink
Delete unneeded nio client (elastic#27408)
Browse files Browse the repository at this point in the history
This is a follow up to elastic#27132. As that PR greatly simplified the
connection logic inside a low level transport implementation, much of
the functionality provided by the NioClient class is no longer
necessary. This commit removes that class.
  • Loading branch information
Tim-Brooks authored Nov 16, 2017
1 parent 3b963dc commit 35a5922
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 163 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ public NioShutdown(Logger logger) {
this.logger = logger;
}

void orderlyShutdown(OpenChannels openChannels, NioClient client, ArrayList<AcceptingSelector> acceptors,
ArrayList<SocketSelector> socketSelectors) {
// Close the client. This ensures that no new send connections will be opened. Client could be null if exception was
// throw on start up
if (client != null) {
client.close();
}
void orderlyShutdown(OpenChannels openChannels, ArrayList<AcceptingSelector> acceptors, ArrayList<SocketSelector> socketSelectors) {

// Start by closing the server channels. Once these are closed, we are guaranteed to no accept new connections
openChannels.closeServerChannels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public class NioTransport extends TcpTransport<NioChannel> {
private final ConcurrentMap<String, ChannelFactory> profileToChannelFactory = newConcurrentMap();
private final ArrayList<AcceptingSelector> acceptors = new ArrayList<>();
private final ArrayList<SocketSelector> socketSelectors = new ArrayList<>();
private NioClient client;
private RoundRobinSelectorSupplier clientSelectorSupplier;
private ChannelFactory clientChannelFactory;
private int acceptorNumber;

public NioTransport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays,
Expand Down Expand Up @@ -111,10 +112,8 @@ protected void sendMessage(NioChannel channel, BytesReference reference, ActionL
@Override
protected NioChannel initiateChannel(DiscoveryNode node, TimeValue connectTimeout, ActionListener<NioChannel> connectListener)
throws IOException {
NioSocketChannel channel = client.initiateConnection(node.getAddress().address());
if (channel == null) {
throw new ElasticsearchException("client is shutdown");
}
NioSocketChannel channel = clientChannelFactory.openNioChannel(node.getAddress().address(), clientSelectorSupplier.get());
openChannels.clientChannelOpened(channel);
channel.addConnectListener(connectListener);
return channel;
}
Expand All @@ -137,7 +136,8 @@ protected void doStart() {
}
}

client = createClient();
clientSelectorSupplier = new RoundRobinSelectorSupplier(socketSelectors);
clientChannelFactory = new ChannelFactory(new ProfileSettings(settings, "default"), contextSetter);

if (NetworkService.NETWORK_SERVER.get(settings)) {
int acceptorCount = NioTransport.NIO_ACCEPTOR_COUNT.get(settings);
Expand Down Expand Up @@ -178,7 +178,7 @@ protected void doStart() {
@Override
protected void stopInternal() {
NioShutdown nioShutdown = new NioShutdown(logger);
nioShutdown.orderlyShutdown(openChannels, client, acceptors, socketSelectors);
nioShutdown.orderlyShutdown(openChannels, acceptors, socketSelectors);

profileToChannelFactory.clear();
socketSelectors.clear();
Expand All @@ -193,10 +193,4 @@ final void exceptionCaught(NioSocketChannel channel, Throwable cause) {
final Throwable t = unwrapped != null ? unwrapped : cause;
onException(channel, t instanceof Exception ? (Exception) t : new ElasticsearchException(t));
}

private NioClient createClient() {
Supplier<SocketSelector> selectorSupplier = new RoundRobinSelectorSupplier(socketSelectors);
ChannelFactory channelFactory = new ChannelFactory(new ProfileSettings(settings, "default"), contextSetter);
return new NioClient(openChannels, selectorSupplier, channelFactory);
}
}

This file was deleted.

0 comments on commit 35a5922

Please sign in to comment.