JmxHelper { public Object operation(String objectName, String method, Object... arguments) { return operation(createObjectName(objectName), method, arguments); } JmxHelper(Entity entity);  JmxHelper(String url);  JmxHelper(String url, String user, String password);  JmxHelper(String url, Entity entity, String user, String password); static String toJmxUrl(Entity entity); static String toRmiJmxUrl(String host, Integer jmxRmiServerPort, Integer rmiRegistryPort, String context); static String toJmxmpUrl(String host, Integer jmxmpPort); void setMinTimeBetweenReconnectAttempts(int val); String getUrl(); boolean isConnected(); synchronized void reconnectWithRetryDampened(); synchronized void reconnect(); @SuppressWarnings({ "rawtypes", "unchecked" }) synchronized void connect(); static JMXConnector newConnector(JMXServiceURL url, Map<String, ?> env); @SuppressWarnings({ "rawtypes", "unchecked" }) Map getConnectionEnvVars(); boolean connect(long timeoutMs); synchronized void disconnect(); void terminate(); ObjectName toLiteralObjectName(ObjectName objectName); Set<ObjectInstance> findMBeans(final ObjectName objectName); ObjectInstance findMBean(ObjectName objectName); Set<ObjectInstance> doesMBeanExistsEventually(final ObjectName objectName, Duration timeout); @Deprecated Set<ObjectInstance> doesMBeanExistsEventually(final ObjectName objectName, TimeDuration timeout); Set<ObjectInstance> doesMBeanExistsEventually(final ObjectName objectName, long timeoutMillis); Set<ObjectInstance> doesMBeanExistsEventually(String objectName, Duration timeout); @Deprecated Set<ObjectInstance> doesMBeanExistsEventually(String objectName, TimeDuration timeout); Set<ObjectInstance> doesMBeanExistsEventually(String objectName, long timeout, TimeUnit timeUnit); Set<ObjectInstance> doesMBeanExistsEventually(final ObjectName objectName, long timeout, TimeUnit timeUnit); void assertMBeanExistsEventually(ObjectName objectName, Duration timeout); @Deprecated void assertMBeanExistsEventually(ObjectName objectName, TimeDuration timeout); void assertMBeanExistsEventually(ObjectName objectName, long timeoutMillis); void assertMBeanExistsEventually(ObjectName objectName, long timeout, TimeUnit timeUnit); Object getAttribute(ObjectName objectName, final String attribute); void setAttribute(String objectName, String attribute, Object val); void setAttribute(ObjectName objectName, final String attribute, final Object val); Object operation(String objectName, String method, Object... arguments); Object operation(ObjectName objectName, final String method, final Object... arguments); void addNotificationListener(String objectName, NotificationListener listener); void addNotificationListener(String objectName, NotificationListener listener, NotificationFilter filter); void addNotificationListener(ObjectName objectName, NotificationListener listener); void addNotificationListener(final ObjectName objectName, final NotificationListener listener, final NotificationFilter filter); void removeNotificationListener(String objectName, NotificationListener listener); void removeNotificationListener(final ObjectName objectName, final NotificationListener listener); void removeNotificationListener(final ObjectName objectName, final NotificationListener listener, final NotificationFilter filter); M getProxyObject(String objectName, Class<M> mbeanInterface); M getProxyObject(ObjectName objectName, Class<M> mbeanInterface); static ObjectName createObjectName(String name); static final String JMX_URL_FORMAT; static final String RMI_JMX_URL_FORMAT; static final String JMXMP_URL_FORMAT; static final Map<String, String> CLASSES; }
@Test public void testInvokeOperationWithNoArgs() throws Exception { final String opReturnVal = "my result"; MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", new MBeanParameterInfo[0], String.class.getName(), MBeanOperationInfo.ACTION); Function<Object[], String> opImpl = new Function<Object[], String>() { @Override public String apply(Object[] args) { assertEquals(args.length, 0, "args="+args); return opReturnVal; } }; GeneralisedDynamicMBean mbean = jmxService.registerMBean(ImmutableMap.of(), ImmutableMap.of(opInfo, opImpl), objectName); assertEquals(jmxHelper.operation(objectName, opName), opReturnVal); }
@Test public void testInvokeOperationUsingObjectNameWildcard() throws Exception { final String opReturnVal = "my result"; MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", new MBeanParameterInfo[0], String.class.getName(), MBeanOperationInfo.ACTION); Function<Object[], String> opImpl = new Function<Object[], String>() { @Override public String apply(Object[] args) { assertEquals(args.length, 0, "args="+args); return opReturnVal; } }; GeneralisedDynamicMBean mbean = jmxService.registerMBean(ImmutableMap.of(), ImmutableMap.of(opInfo, opImpl), objectName); assertEquals(jmxHelper.operation(objectNameWithWildcard, opName), opReturnVal); }
@Test public void testInvokeOperationWithArgs() throws Exception { final String opReturnPrefix = "my result prefix/"; String opParam1 = "my param 1"; MBeanOperationInfo opInfo = new MBeanOperationInfo( opName, "my descr", new MBeanParameterInfo[] {new MBeanParameterInfo("myParam1", String.class.getName(), "my param1 descr")}, String.class.getName(), MBeanOperationInfo.ACTION); Function<Object[],String> opImpl = new Function<Object[],String>() { @Override public String apply(Object[] input) { return opReturnPrefix+input[0]; } }; GeneralisedDynamicMBean mbean = jmxService.registerMBean(ImmutableMap.of(), ImmutableMap.of(opInfo, opImpl), objectName); assertEquals(jmxHelper.operation(objectName, opName, opParam1), opReturnPrefix+opParam1); }