Remove implementations of `TransportChannel` (#27388)

Right now we have unnecessary implementations of `TransportChannel`.
Additionally, there are methods on the interface that are not used. This
commit removes unnecessary implementations and methods.
This commit is contained in:
Tim Brooks 2017-11-15 09:48:07 -07:00 committed by GitHub
parent 50a2459adf
commit a8f916911a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 35 additions and 138 deletions

View File

@ -25,7 +25,6 @@ import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskManager; import org.elasticsearch.tasks.TaskManager;
import java.io.IOException; import java.io.IOException;
import java.util.function.Supplier;
public class RequestHandlerRegistry<Request extends TransportRequest> { public class RequestHandlerRegistry<Request extends TransportRequest> {
@ -64,7 +63,7 @@ public class RequestHandlerRegistry<Request extends TransportRequest> {
} else { } else {
boolean success = false; boolean success = false;
try { try {
handler.messageReceived(request, new TransportChannelWrapper(taskManager, task, channel), task); handler.messageReceived(request, new TaskTransportChannel(taskManager, task, channel), task);
success = true; success = true;
} finally { } finally {
if (success == false) { if (success == false) {
@ -91,38 +90,4 @@ public class RequestHandlerRegistry<Request extends TransportRequest> {
return handler.toString(); return handler.toString();
} }
private static class TransportChannelWrapper extends DelegatingTransportChannel {
private final Task task;
private final TaskManager taskManager;
TransportChannelWrapper(TaskManager taskManager, Task task, TransportChannel channel) {
super(channel);
this.task = task;
this.taskManager = taskManager;
}
@Override
public void sendResponse(TransportResponse response) throws IOException {
endTask();
super.sendResponse(response);
}
@Override
public void sendResponse(TransportResponse response, TransportResponseOptions options) throws IOException {
endTask();
super.sendResponse(response, options);
}
@Override
public void sendResponse(Exception exception) throws IOException {
endTask();
super.sendResponse(exception);
}
private void endTask() {
taskManager.unregister(task);
}
}
} }

View File

@ -20,24 +20,22 @@
package org.elasticsearch.transport; package org.elasticsearch.transport;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.tasks.TaskManager;
import java.io.IOException; import java.io.IOException;
/** public class TaskTransportChannel implements TransportChannel {
* Wrapper around transport channel that delegates all requests to the
* underlying channel
*/
public class DelegatingTransportChannel implements TransportChannel {
private final Task task;
private final TaskManager taskManager;
private final TransportChannel channel; private final TransportChannel channel;
protected DelegatingTransportChannel(TransportChannel channel) { TaskTransportChannel(TaskManager taskManager, Task task, TransportChannel channel) {
this.channel = channel; this.channel = channel;
} this.task = task;
this.taskManager = taskManager;
@Override
public String action() {
return channel.action();
} }
@Override @Override
@ -45,11 +43,6 @@ public class DelegatingTransportChannel implements TransportChannel {
return channel.getProfileName(); return channel.getProfileName();
} }
@Override
public long getRequestId() {
return channel.getRequestId();
}
@Override @Override
public String getChannelType() { public String getChannelType() {
return channel.getChannelType(); return channel.getChannelType();
@ -57,25 +50,32 @@ public class DelegatingTransportChannel implements TransportChannel {
@Override @Override
public void sendResponse(TransportResponse response) throws IOException { public void sendResponse(TransportResponse response) throws IOException {
endTask();
channel.sendResponse(response); channel.sendResponse(response);
} }
@Override @Override
public void sendResponse(TransportResponse response, TransportResponseOptions options) throws IOException { public void sendResponse(TransportResponse response, TransportResponseOptions options) throws IOException {
endTask();
channel.sendResponse(response, options); channel.sendResponse(response, options);
} }
@Override @Override
public void sendResponse(Exception exception) throws IOException { public void sendResponse(Exception exception) throws IOException {
endTask();
channel.sendResponse(exception); channel.sendResponse(exception);
} }
public TransportChannel getChannel() {
return channel;
}
@Override @Override
public Version getVersion() { public Version getVersion() {
return channel.getVersion(); return channel.getVersion();
} }
public TransportChannel getChannel() {
return channel;
}
private void endTask() {
taskManager.unregister(task);
}
} }

View File

@ -24,18 +24,19 @@ import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
public final class TcpTransportChannel<Channel> implements TransportChannel { public final class TcpTransportChannel<Channel> implements TransportChannel {
private final TcpTransport<Channel> transport; private final TcpTransport<Channel> transport;
protected final Version version; private final Version version;
protected final String action; private final String action;
protected final long requestId; private final long requestId;
private final String profileName; private final String profileName;
private final long reservedBytes; private final long reservedBytes;
private final AtomicBoolean released = new AtomicBoolean(); private final AtomicBoolean released = new AtomicBoolean();
private final String channelType; private final String channelType;
private final Channel channel; private final Channel channel;
public TcpTransportChannel(TcpTransport<Channel> transport, Channel channel, String channelType, String action, TcpTransportChannel(TcpTransport<Channel> transport, Channel channel, String channelType, String action,
long requestId, Version version, String profileName, long reservedBytes) { long requestId, Version version, String profileName, long reservedBytes) {
this.version = version; this.version = version;
this.channel = channel; this.channel = channel;
this.transport = transport; this.transport = transport;
@ -51,11 +52,6 @@ public final class TcpTransportChannel<Channel> implements TransportChannel {
return profileName; return profileName;
} }
@Override
public String action() {
return this.action;
}
@Override @Override
public void sendResponse(TransportResponse response) throws IOException { public void sendResponse(TransportResponse response) throws IOException {
sendResponse(response, TransportResponseOptions.EMPTY); sendResponse(response, TransportResponseOptions.EMPTY);
@ -78,6 +74,7 @@ public final class TcpTransportChannel<Channel> implements TransportChannel {
release(true); release(true);
} }
} }
private Exception releaseBy; private Exception releaseBy;
private void release(boolean isExceptionResponse) { private void release(boolean isExceptionResponse) {
@ -91,23 +88,18 @@ public final class TcpTransportChannel<Channel> implements TransportChannel {
} }
} }
@Override
public long getRequestId() {
return requestId;
}
@Override @Override
public String getChannelType() { public String getChannelType() {
return channelType; return channelType;
} }
public Channel getChannel() {
return channel;
}
@Override @Override
public Version getVersion() { public Version getVersion() {
return version; return version;
} }
public Channel getChannel() {
return channel;
}
} }

View File

@ -28,12 +28,8 @@ import java.io.IOException;
*/ */
public interface TransportChannel { public interface TransportChannel {
String action();
String getProfileName(); String getProfileName();
long getRequestId();
String getChannelType(); String getChannelType();
void sendResponse(TransportResponse response) throws IOException; void sendResponse(TransportResponse response) throws IOException;

View File

@ -1117,8 +1117,8 @@ public class TransportService extends AbstractLifecycleComponent {
final TransportService service; final TransportService service;
final ThreadPool threadPool; final ThreadPool threadPool;
DirectResponseChannel(Logger logger, DiscoveryNode localNode, String action, long requestId, DirectResponseChannel(Logger logger, DiscoveryNode localNode, String action, long requestId, TransportService service,
TransportService service, ThreadPool threadPool) { ThreadPool threadPool) {
this.logger = logger; this.logger = logger;
this.localNode = localNode; this.localNode = localNode;
this.action = action; this.action = action;
@ -1127,11 +1127,6 @@ public class TransportService extends AbstractLifecycleComponent {
this.threadPool = threadPool; this.threadPool = threadPool;
} }
@Override
public String action() {
return action;
}
@Override @Override
public String getProfileName() { public String getProfileName() {
return DIRECT_RESPONSE_PROFILE; return DIRECT_RESPONSE_PROFILE;
@ -1177,13 +1172,7 @@ public class TransportService extends AbstractLifecycleComponent {
if (ThreadPool.Names.SAME.equals(executor)) { if (ThreadPool.Names.SAME.equals(executor)) {
processException(handler, rtx); processException(handler, rtx);
} else { } else {
threadPool.executor(handler.executor()).execute(new Runnable() { threadPool.executor(handler.executor()).execute(() -> processException(handler, rtx));
@SuppressWarnings({"unchecked"})
@Override
public void run() {
processException(handler, rtx);
}
});
} }
} }
} }
@ -1205,11 +1194,6 @@ public class TransportService extends AbstractLifecycleComponent {
} }
} }
@Override
public long getRequestId() {
return requestId;
}
@Override @Override
public String getChannelType() { public String getChannelType() {
return "direct"; return "direct";

View File

@ -471,11 +471,6 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase {
return capturedResponse; return capturedResponse;
} }
@Override
public String action() {
return null;
}
@Override @Override
public String getProfileName() { public String getProfileName() {
return ""; return "";
@ -494,11 +489,6 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase {
public void sendResponse(Exception exception) throws IOException { public void sendResponse(Exception exception) throws IOException {
} }
@Override
public long getRequestId() {
return 0;
}
@Override @Override
public String getChannelType() { public String getChannelType() {
return "test"; return "test";

View File

@ -1237,11 +1237,6 @@ public class TransportReplicationActionTests extends ESTestCase {
public TransportChannel createTransportChannel(final PlainActionFuture<TestResponse> listener) { public TransportChannel createTransportChannel(final PlainActionFuture<TestResponse> listener) {
return new TransportChannel() { return new TransportChannel() {
@Override
public String action() {
return null;
}
@Override @Override
public String getProfileName() { public String getProfileName() {
return ""; return "";
@ -1262,11 +1257,6 @@ public class TransportReplicationActionTests extends ESTestCase {
listener.onFailure(exception); listener.onFailure(exception);
} }
@Override
public long getRequestId() {
return 0;
}
@Override @Override
public String getChannelType() { public String getChannelType() {
return "replica_test"; return "replica_test";

View File

@ -914,11 +914,6 @@ public class PublishClusterStateActionTests extends ESTestCase {
error.set(null); error.set(null);
} }
@Override
public String action() {
return "_noop_";
}
@Override @Override
public String getProfileName() { public String getProfileName() {
return "_noop_"; return "_noop_";
@ -942,11 +937,6 @@ public class PublishClusterStateActionTests extends ESTestCase {
assertThat(response.get(), nullValue()); assertThat(response.get(), nullValue());
} }
@Override
public long getRequestId() {
return 0;
}
@Override @Override
public String getChannelType() { public String getChannelType() {
return "capturing"; return "capturing";

View File

@ -47,7 +47,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.discovery.Discovery; import org.elasticsearch.discovery.Discovery;
import org.elasticsearch.discovery.zen.PublishClusterStateActionTests.AssertingAckListener; import org.elasticsearch.discovery.zen.PublishClusterStateActionTests.AssertingAckListener;
import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.plugins.ClusterPlugin;
import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ClusterServiceUtils;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.VersionUtils;
@ -378,21 +377,12 @@ public class ZenDiscoveryUnitTests extends ESTestCase {
} else { } else {
AtomicBoolean sendResponse = new AtomicBoolean(false); AtomicBoolean sendResponse = new AtomicBoolean(false);
request.messageReceived(new MembershipAction.ValidateJoinRequest(stateBuilder.build()), new TransportChannel() { request.messageReceived(new MembershipAction.ValidateJoinRequest(stateBuilder.build()), new TransportChannel() {
@Override
public String action() {
return null;
}
@Override @Override
public String getProfileName() { public String getProfileName() {
return null; return null;
} }
@Override
public long getRequestId() {
return 0;
}
@Override @Override
public String getChannelType() { public String getChannelType() {
return null; return null;