MBeanProxyInvocationHandler implements InvocationHandler { @Override public Object invoke(Object proxy, Method method, Object[] arguments) throws MBeanException, ListenerNotFoundException, InvalidObjectException, OpenDataException { if (logger.isTraceEnabled()) { logger.trace("Invoking Method {}", method.getName()); } Class methodClass = method.getDeclaringClass(); if (methodClass.equals(NotificationBroadcaster.class) || methodClass.equals(NotificationEmitter.class)) { return invokeBroadcasterMethod(method, arguments); } String methodName = method.getName(); Class[] parameterTypes = method.getParameterTypes(); Class returnType = method.getReturnType(); int argumentCount = arguments == null ? 0 : arguments.length; if (methodName.equals("setLastRefreshedTime")) { proxyImpl.setLastRefreshedTime((Long) arguments[0]); return null; } if (methodName.equals("getLastRefreshedTime")) { return proxyImpl.getLastRefreshedTime(); } if (methodName.equals("sendNotification")) { sendNotification(arguments[0]); return null; } if (shouldDoLocally(method)) { return doLocally(method, arguments); } if (isMXBean) { MXBeanProxyInvocationHandler p = findMXBeanProxy(objectName, methodClass, this); return p.invoke(proxy, method, arguments); } if (methodName.startsWith("get") && methodName.length() > 3 && argumentCount == 0 && !returnType.equals(Void.TYPE)) { return delegateToObjectState(methodName.substring(3)); } if (methodName.startsWith("is") && methodName.length() > 2 && argumentCount == 0 && (returnType.equals(Boolean.TYPE) || returnType.equals(Boolean.class))) { return delegateToObjectState(methodName.substring(2)); } String[] signature = new String[parameterTypes.length]; for (int i = 0; i < parameterTypes.length; i++) { signature[i] = parameterTypes[i].getName(); } return delegateToFunctionService(objectName, methodName, arguments, signature); } private  MBeanProxyInvocationHandler(DistributedMember member, ObjectName objectName,
      Region<String, Object> monitoringRegion, boolean isMXBean); @VisibleForTesting  MBeanProxyInvocationHandler(DistributedMember member, ObjectName objectName,
      Region<String, Object> monitoringRegion, boolean isMXBean,
      NotificationBroadcasterSupport emitter, ProxyInterface proxyImpl); @Override Object invoke(Object proxy, Method method, Object[] arguments);  }
@Test public void invoke_methodName_getLastRefreshedTime_delegatesToProxyImpl() throws Exception { MBeanProxyInvocationHandler mBeanProxyInvocationHandler = new MBeanProxyInvocationHandler(member, objectName, monitoringRegion, isMXBean, emitter, proxyImpl); Method getLastRefreshedTimeMethod = proxyImpl.getClass() .getMethod("getLastRefreshedTime"); mBeanProxyInvocationHandler.invoke(proxyImpl, getLastRefreshedTimeMethod, new Object[] {}); verify(proxyImpl) .getLastRefreshedTime(); }
@Test public void invoke_methodName_setLastRefreshedTime_delegatesToProxyImpl() throws Exception { MBeanProxyInvocationHandler mBeanProxyInvocationHandler = new MBeanProxyInvocationHandler(member, objectName, monitoringRegion, isMXBean, emitter, proxyImpl); Method setLastRefreshedTimeMethod = proxyImpl.getClass() .getMethod("setLastRefreshedTime", long.class); long lastRefreshedTimeParameter = 24; mBeanProxyInvocationHandler.invoke(proxyImpl, setLastRefreshedTimeMethod, new Object[] {lastRefreshedTimeParameter}); verify(proxyImpl) .setLastRefreshedTime(eq(lastRefreshedTimeParameter)); }
@Test public void invoke_methodName_sendNotification_delegatesToProxyImpl() throws Exception { ProxyWithNotificationBroadcasterSupport proxyWithNotificationBroadcasterSupport = mock(ProxyWithNotificationBroadcasterSupport.class); MBeanProxyInvocationHandler mBeanProxyInvocationHandler = new MBeanProxyInvocationHandler(member, objectName, monitoringRegion, isMXBean, emitter, proxyWithNotificationBroadcasterSupport); Method setLastRefreshedTimeMethod = proxyWithNotificationBroadcasterSupport.getClass() .getMethod("setLastRefreshedTime", long.class); long lastRefreshedTimeParameter = 24; mBeanProxyInvocationHandler.invoke(proxyWithNotificationBroadcasterSupport, setLastRefreshedTimeMethod, new Object[] {lastRefreshedTimeParameter}); verify(proxyWithNotificationBroadcasterSupport) .setLastRefreshedTime(eq(lastRefreshedTimeParameter)); }