From 7fada715a6eea5c0fe75744fe0e70d1b96dce858 Mon Sep 17 00:00:00 2001 From: Christopher Tubbs Date: Wed, 15 Jan 2025 10:52:58 -0500 Subject: [PATCH] Remove redundant interfaces for thrift services (#5260) Update Proxy/reflection code to gather all the thrift interfaces from the proxied instances, so you don't need to declare them all explicitly on each subclass. --- .../org/apache/accumulo/core/trace/TraceUtil.java | 15 ++++++++++++++- .../accumulo/test/SelfStoppingScanServer.java | 5 +---- .../compaction/ExternalDoNothingCompactor.java | 3 +-- .../test/functional/MemoryConsumingCompactor.java | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/trace/TraceUtil.java b/core/src/main/java/org/apache/accumulo/core/trace/TraceUtil.java index 78d658a38e1..63d7a793079 100644 --- a/core/src/main/java/org/apache/accumulo/core/trace/TraceUtil.java +++ b/core/src/main/java/org/apache/accumulo/core/trace/TraceUtil.java @@ -21,7 +21,9 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Proxy; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.Callable; import org.apache.accumulo.core.Constants; @@ -214,8 +216,19 @@ public static T wrapService(final T instance) { private static T wrapRpc(final InvocationHandler handler, final T instance) { @SuppressWarnings("unchecked") T proxiedInstance = (T) Proxy.newProxyInstance(instance.getClass().getClassLoader(), - instance.getClass().getInterfaces(), handler); + getInterfaces(instance.getClass()).toArray(new Class[0]), handler); return proxiedInstance; } + private static Set> getInterfaces(Class clazz) { + var set = new HashSet>(); + if (clazz != null) { + set.addAll(getInterfaces(clazz.getSuperclass())); + for (Class interfaze : clazz.getInterfaces()) { + set.add(interfaze); + } + } + return set; + } + } diff --git a/test/src/main/java/org/apache/accumulo/test/SelfStoppingScanServer.java b/test/src/main/java/org/apache/accumulo/test/SelfStoppingScanServer.java index 73284dc8c50..fe9e15ec04c 100644 --- a/test/src/main/java/org/apache/accumulo/test/SelfStoppingScanServer.java +++ b/test/src/main/java/org/apache/accumulo/test/SelfStoppingScanServer.java @@ -22,18 +22,15 @@ import org.apache.accumulo.core.cli.ConfigOpts; import org.apache.accumulo.core.clientImpl.thrift.TInfo; -import org.apache.accumulo.core.tabletscan.thrift.TabletScanClientService; import org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException; import org.apache.accumulo.tserver.ScanServer; -import org.apache.accumulo.tserver.TabletHostingServer; import org.apache.thrift.TException; /** * ScanServer implementation that will stop itself after the the 3rd scan batch scan * */ -public class SelfStoppingScanServer extends ScanServer - implements TabletScanClientService.Iface, TabletHostingServer { +public class SelfStoppingScanServer extends ScanServer { private final AtomicInteger scanCount = new AtomicInteger(0); diff --git a/test/src/main/java/org/apache/accumulo/test/compaction/ExternalDoNothingCompactor.java b/test/src/main/java/org/apache/accumulo/test/compaction/ExternalDoNothingCompactor.java index afd4b271e25..6f937a68adb 100644 --- a/test/src/main/java/org/apache/accumulo/test/compaction/ExternalDoNothingCompactor.java +++ b/test/src/main/java/org/apache/accumulo/test/compaction/ExternalDoNothingCompactor.java @@ -28,7 +28,6 @@ import org.apache.accumulo.compactor.Compactor; import org.apache.accumulo.core.cli.ConfigOpts; -import org.apache.accumulo.core.compaction.thrift.CompactorService.Iface; import org.apache.accumulo.core.compaction.thrift.TCompactionState; import org.apache.accumulo.core.compaction.thrift.TCompactionStatusUpdate; import org.apache.accumulo.core.dataImpl.KeyExtent; @@ -45,7 +44,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ExternalDoNothingCompactor extends Compactor implements Iface { +public class ExternalDoNothingCompactor extends Compactor { private static final Logger LOG = LoggerFactory.getLogger(ExternalDoNothingCompactor.class); diff --git a/test/src/main/java/org/apache/accumulo/test/functional/MemoryConsumingCompactor.java b/test/src/main/java/org/apache/accumulo/test/functional/MemoryConsumingCompactor.java index d7257302459..3467ffd05b8 100644 --- a/test/src/main/java/org/apache/accumulo/test/functional/MemoryConsumingCompactor.java +++ b/test/src/main/java/org/apache/accumulo/test/functional/MemoryConsumingCompactor.java @@ -37,7 +37,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class MemoryConsumingCompactor extends Compactor implements CompactorService.Iface { +public class MemoryConsumingCompactor extends Compactor { private static final Logger LOG = LoggerFactory.getLogger(MemoryConsumingCompactor.class);