@Test public void testWithLazyConnectionAndNoAccess() throws Exception { MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); bean.setServiceUrl(serviceUrl); bean.setConnectOnStartup(false); bean.afterPropertiesSet(); MBeanServerConnection connection = bean.getObject(); assertTrue(AopUtils.isAopProxy(connection)); bean.destroy(); }
/** * Creates a {@code JMXConnector} for the given settings * and exposes the associated {@code MBeanServerConnection}. */ @Override public void afterPropertiesSet() throws IOException { if (this.serviceUrl == null) { throw new IllegalArgumentException("Property 'serviceUrl' is required"); } if (this.connectOnStartup) { connect(); } else { createLazyConnection(); } }
@Test(expected = IllegalArgumentException.class) public void testWithNoServiceUrl() throws Exception { MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); bean.afterPropertiesSet(); }
private static boolean isConnected() throws Exception { boolean connected = false; if (!JobRegistryBackgroundJobRunner.getErrors().isEmpty()) { throw JobRegistryBackgroundJobRunner.getErrors().get(0); } if (launcher == null) { MBeanServerConnectionFactoryBean connectionFactory = new MBeanServerConnectionFactoryBean(); try { launcher = (JobOperator) getMBean(connectionFactory, "spring:service=batch,bean=jobOperator", JobOperator.class); loader = (JobLoader) getMBean(connectionFactory, "spring:service=batch,bean=jobLoader", JobLoader.class); } catch (MBeanServerNotFoundException e) { return false; } } try { launcher.getJobNames(); connected = loader.getConfigurations().size() > 0; logger.info("Configurations loaded: " + loader.getConfigurations()); } catch (InvalidInvocationException e) { // ignore } return connected; }
private static Object getMBean(MBeanServerConnectionFactoryBean connectionFactory, String objectName, Class<?> interfaceType) throws MalformedObjectNameException { MBeanProxyFactoryBean factory = new MBeanProxyFactoryBean(); factory.setObjectName(objectName); factory.setProxyInterface(interfaceType); factory.setServer(connectionFactory.getObject()); factory.afterPropertiesSet(); return factory.getObject(); } }
@Test public void testTestWithLazyConnection() throws Exception { Assume.group(TestGroup.JMXMP); MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); bean.setServiceUrl(serviceUrl); bean.setConnectOnStartup(false); bean.afterPropertiesSet(); MBeanServerConnection connection = bean.getObject(); assertTrue(AopUtils.isAopProxy(connection)); JMXConnectorServer connector = null; try { connector = getConnectorServer(); connector.start(); assertEquals("Incorrect MBean count", getServer().getMBeanCount(), connection.getMBeanCount()); } finally { bean.destroy(); if (connector != null) { connector.stop(); } } }
/** * Creates a {@code JMXConnector} for the given settings * and exposes the associated {@code MBeanServerConnection}. */ @Override public void afterPropertiesSet() throws IOException { if (this.serviceUrl == null) { throw new IllegalArgumentException("Property 'serviceUrl' is required"); } if (this.connectOnStartup) { connect(); } else { createLazyConnection(); } }
@Test public void testTestValidConnection() throws Exception { Assume.group(TestGroup.JMXMP); JMXConnectorServer connectorServer = getConnectorServer(); connectorServer.start(); try { MBeanServerConnectionFactoryBean bean = new MBeanServerConnectionFactoryBean(); bean.setServiceUrl(serviceUrl); bean.afterPropertiesSet(); try { MBeanServerConnection connection = bean.getObject(); assertNotNull("Connection should not be null", connection); // perform simple MBean count test assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount()); } finally { bean.destroy(); } } finally { connectorServer.stop(); } }
/** * Creates a {@code JMXConnector} for the given settings * and exposes the associated {@code MBeanServerConnection}. */ @Override public void afterPropertiesSet() throws IOException { if (this.serviceUrl == null) { throw new IllegalArgumentException("Property 'serviceUrl' is required"); } if (this.connectOnStartup) { connect(); } else { createLazyConnection(); } }
return action.perform(instance, getLocalConnection()); } else { MBeanServerConnectionFactoryBean factoryBean = new MBeanServerConnectionFactoryBean(); String address = instance.getAddress(); if (!address.startsWith("service:")) { address = "service:jmx:rmi:///jndi/rmi://" + address + "/jmxrmi"; factoryBean.setServiceUrl(address); Properties properties = new Properties(); properties.put("jmx.remote.credentials", new String[]{username, instance.getPassword()}); factoryBean.setEnvironment(properties); factoryBean.afterPropertiesSet(); MBeanServerConnection connection = factoryBean.getObject(); T result; try { } finally { try { factoryBean.destroy(); } catch (Exception ignored) {