Skip to content

Commit 7fada71

Browse files
authored
Remove redundant interfaces for thrift services (apache#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.
1 parent 3f9b0c6 commit 7fada71

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

core/src/main/java/org/apache/accumulo/core/trace/TraceUtil.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import java.lang.reflect.InvocationHandler;
2222
import java.lang.reflect.InvocationTargetException;
2323
import java.lang.reflect.Proxy;
24+
import java.util.HashSet;
2425
import java.util.Map;
26+
import java.util.Set;
2527
import java.util.concurrent.Callable;
2628

2729
import org.apache.accumulo.core.Constants;
@@ -214,8 +216,19 @@ public static <T> T wrapService(final T instance) {
214216
private static <T> T wrapRpc(final InvocationHandler handler, final T instance) {
215217
@SuppressWarnings("unchecked")
216218
T proxiedInstance = (T) Proxy.newProxyInstance(instance.getClass().getClassLoader(),
217-
instance.getClass().getInterfaces(), handler);
219+
getInterfaces(instance.getClass()).toArray(new Class<?>[0]), handler);
218220
return proxiedInstance;
219221
}
220222

223+
private static Set<Class<?>> getInterfaces(Class<?> clazz) {
224+
var set = new HashSet<Class<?>>();
225+
if (clazz != null) {
226+
set.addAll(getInterfaces(clazz.getSuperclass()));
227+
for (Class<?> interfaze : clazz.getInterfaces()) {
228+
set.add(interfaze);
229+
}
230+
}
231+
return set;
232+
}
233+
221234
}

test/src/main/java/org/apache/accumulo/test/SelfStoppingScanServer.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@
2222

2323
import org.apache.accumulo.core.cli.ConfigOpts;
2424
import org.apache.accumulo.core.clientImpl.thrift.TInfo;
25-
import org.apache.accumulo.core.tabletscan.thrift.TabletScanClientService;
2625
import org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException;
2726
import org.apache.accumulo.tserver.ScanServer;
28-
import org.apache.accumulo.tserver.TabletHostingServer;
2927
import org.apache.thrift.TException;
3028

3129
/**
3230
* ScanServer implementation that will stop itself after the the 3rd scan batch scan
3331
*
3432
*/
35-
public class SelfStoppingScanServer extends ScanServer
36-
implements TabletScanClientService.Iface, TabletHostingServer {
33+
public class SelfStoppingScanServer extends ScanServer {
3734

3835
private final AtomicInteger scanCount = new AtomicInteger(0);
3936

test/src/main/java/org/apache/accumulo/test/compaction/ExternalDoNothingCompactor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import org.apache.accumulo.compactor.Compactor;
3030
import org.apache.accumulo.core.cli.ConfigOpts;
31-
import org.apache.accumulo.core.compaction.thrift.CompactorService.Iface;
3231
import org.apache.accumulo.core.compaction.thrift.TCompactionState;
3332
import org.apache.accumulo.core.compaction.thrift.TCompactionStatusUpdate;
3433
import org.apache.accumulo.core.dataImpl.KeyExtent;
@@ -45,7 +44,7 @@
4544
import org.slf4j.Logger;
4645
import org.slf4j.LoggerFactory;
4746

48-
public class ExternalDoNothingCompactor extends Compactor implements Iface {
47+
public class ExternalDoNothingCompactor extends Compactor {
4948

5049
private static final Logger LOG = LoggerFactory.getLogger(ExternalDoNothingCompactor.class);
5150

test/src/main/java/org/apache/accumulo/test/functional/MemoryConsumingCompactor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.slf4j.Logger;
3838
import org.slf4j.LoggerFactory;
3939

40-
public class MemoryConsumingCompactor extends Compactor implements CompactorService.Iface {
40+
public class MemoryConsumingCompactor extends Compactor {
4141

4242
private static final Logger LOG = LoggerFactory.getLogger(MemoryConsumingCompactor.class);
4343

0 commit comments

Comments
 (0)