RpcServiceAdapter implements InvocationHandler { @Override @SuppressWarnings("checkstyle:hiddenField") public Object invoke(final Object proxy, final Method method, final Object[] args) { final RpcInvocationStrategy rpc = rpcNames.get(method); if (rpc != null) { if (args.length != 1) { throw new IllegalArgumentException("Input must be provided."); } return rpc.invoke((DataObject) requireNonNull(args[0])); } switch (method.getName()) { case "toString": if (method.getReturnType().equals(String.class) && method.getParameterCount() == 0) { return type.getName() + "$Adapter{delegate=" + delegate.toString() + "}"; } break; case "hashCode": if (method.getReturnType().equals(int.class) && method.getParameterCount() == 0) { return System.identityHashCode(proxy); } break; case "equals": if (method.getReturnType().equals(boolean.class) && method.getParameterCount() == 1 && method.getParameterTypes()[0] == Object.class) { return proxy == args[0]; } break; default: break; } throw new UnsupportedOperationException("Method " + method.toString() + "is unsupported."); } RpcServiceAdapter(final Class<? extends RpcService> type, final AdapterContext adapterContext,
            final DOMRpcService domService); @Override @SuppressWarnings("checkstyle:hiddenField") Object invoke(final Object proxy, final Method method, final Object[] args);  }
@SuppressWarnings("checkstyle:IllegalThrows") @Test public void invoke() throws Throwable { final BindingBrokerTestFactory bindingBrokerTestFactory = new BindingBrokerTestFactory(); bindingBrokerTestFactory.setExecutor(MoreExecutors.newDirectExecutorService()); final BindingTestContext bindingTestContext = bindingBrokerTestFactory.getTestContext(); bindingTestContext.start(); RpcServiceAdapter rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRpcServiceService.class, bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker()); Method method = TestRpcService.class.getMethod("equals", Object.class); assertTrue((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method, new Object[]{ rpcServiceAdapter.getProxy() })); assertFalse((boolean) rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method, new Object[]{ new Object() })); method = TestRpcService.class.getMethod("hashCode"); assertEquals(rpcServiceAdapter.getProxy().hashCode(), rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method, new Object[]{ })); method = TestRpcService.class.getMethod("toString"); assertEquals(rpcServiceAdapter.getProxy().toString(), rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method, new Object[]{ })); method = OpendaylightTestRpcServiceService.class.getMethod("rockTheHouse", RockTheHouseInput.class); assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method, new Object[]{ new RockTheHouseInputBuilder().build() })); rpcServiceAdapter = new RpcServiceAdapter(OpendaylightTestRoutedRpcService.class, bindingTestContext.getCodec(), bindingTestContext.getDomRpcInvoker()); method = OpendaylightTestRoutedRpcService.class.getMethod("routedSimpleRoute", RoutedSimpleRouteInput.class); assertNotNull(rpcServiceAdapter.invoke(rpcServiceAdapter.getProxy(), method, new Object[]{ new RoutedSimpleRouteInputBuilder().build() })); }