@Override public void afterPropertiesSet() { // If no server was provided then try to find one. This is useful in an environment // where there is already an MBeanServer loaded. if (this.server == null) { this.server = JmxUtils.locateMBeanServer(); } }
/** * Attempt to find a locally running {@code MBeanServer}. Fails if no * {@code MBeanServer} can be found. Logs a warning if more than one * {@code MBeanServer} found, returning the first one from the list. * @return the {@code MBeanServer} if found * @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer */ public static MBeanServer locateMBeanServer() throws MBeanServerNotFoundException { return locateMBeanServer(null); }
/** * Attempt to find a locally running {@code MBeanServer}. Fails if no * {@code MBeanServer} can be found. Logs a warning if more than one * {@code MBeanServer} found, returning the first one from the list. * @return the {@code MBeanServer} if found * @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer */ public static MBeanServer locateMBeanServer() throws MBeanServerNotFoundException { return locateMBeanServer(null); }
@Override public void afterPropertiesSet() { // If no server was provided then try to find one. This is useful in an environment // where there is already an MBeanServer loaded. if (this.server == null) { this.server = JmxUtils.locateMBeanServer(); } }
/** * Attempt to locate an existing {@code MBeanServer}. * Called if {@code locateExistingServerIfPossible} is set to {@code true}. * <p>The default implementation attempts to find an {@code MBeanServer} using * a standard lookup. Subclasses may override to add additional location logic. * @param agentId the agent identifier of the MBeanServer to retrieve. * If this parameter is {@code null}, all registered MBeanServers are * considered. * @return the {@code MBeanServer} if found * @throws org.springframework.jmx.MBeanServerNotFoundException * if no {@code MBeanServer} could be found * @see #setLocateExistingServerIfPossible * @see JmxUtils#locateMBeanServer(String) * @see javax.management.MBeanServerFactory#findMBeanServer(String) */ protected MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException { return JmxUtils.locateMBeanServer(agentId); }
/** * Attempt to locate an existing {@code MBeanServer}. * Called if {@code locateExistingServerIfPossible} is set to {@code true}. * <p>The default implementation attempts to find an {@code MBeanServer} using * a standard lookup. Subclasses may override to add additional location logic. * @param agentId the agent identifier of the MBeanServer to retrieve. * If this parameter is {@code null}, all registered MBeanServers are * considered. * @return the {@code MBeanServer} if found * @throws org.springframework.jmx.MBeanServerNotFoundException * if no {@code MBeanServer} could be found * @see #setLocateExistingServerIfPossible * @see JmxUtils#locateMBeanServer(String) * @see javax.management.MBeanServerFactory#findMBeanServer(String) */ protected MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException { return JmxUtils.locateMBeanServer(agentId); }
/** * Connects to the remote {@code MBeanServer} using the configured {@code JMXServiceURL}: * to the specified JMX service, or to a local MBeanServer if no service URL specified. * @param serviceUrl the JMX service URL to connect to (may be {@code null}) * @param environment the JMX environment for the connector (may be {@code null}) * @param agentId the local JMX MBeanServer's agent id (may be {@code null}) */ public MBeanServerConnection connect(@Nullable JMXServiceURL serviceUrl, @Nullable Map<String, ?> environment, @Nullable String agentId) throws MBeanServerNotFoundException { if (serviceUrl != null) { if (logger.isDebugEnabled()) { logger.debug("Connecting to remote MBeanServer at URL [" + serviceUrl + "]"); } try { this.connector = JMXConnectorFactory.connect(serviceUrl, environment); return this.connector.getMBeanServerConnection(); } catch (IOException ex) { throw new MBeanServerNotFoundException("Could not connect to remote MBeanServer [" + serviceUrl + "]", ex); } } else { logger.debug("Attempting to locate local MBeanServer"); return JmxUtils.locateMBeanServer(agentId); } }
/** * Connects to the remote {@code MBeanServer} using the configured {@code JMXServiceURL}: * to the specified JMX service, or to a local MBeanServer if no service URL specified. * @param serviceUrl the JMX service URL to connect to (may be {@code null}) * @param environment the JMX environment for the connector (may be {@code null}) * @param agentId the local JMX MBeanServer's agent id (may be {@code null}) */ public MBeanServerConnection connect(@Nullable JMXServiceURL serviceUrl, @Nullable Map<String, ?> environment, @Nullable String agentId) throws MBeanServerNotFoundException { if (serviceUrl != null) { if (logger.isDebugEnabled()) { logger.debug("Connecting to remote MBeanServer at URL [" + serviceUrl + "]"); } try { this.connector = JMXConnectorFactory.connect(serviceUrl, environment); return this.connector.getMBeanServerConnection(); } catch (IOException ex) { throw new MBeanServerNotFoundException("Could not connect to remote MBeanServer [" + serviceUrl + "]", ex); } } else { logger.debug("Attempting to locate local MBeanServer"); return JmxUtils.locateMBeanServer(agentId); } }
public void afterPropertiesSet() throws JMException, IOException { if (this.server == null) { this.server = JmxUtils.locateMBeanServer();
@Test public void testLocatePlatformMBeanServer() { MBeanServer server = null; try { server = JmxUtils.locateMBeanServer(); } finally { if (server != null) { MBeanServerFactory.releaseMBeanServer(server); } } }
public void afterPropertiesSet() throws JMException, IOException { if (this.server == null) { this.server = JmxUtils.locateMBeanServer();
/** * Attempt to find a locally running {@code MBeanServer}. Fails if no * {@code MBeanServer} can be found. Logs a warning if more than one * {@code MBeanServer} found, returning the first one from the list. * @return the {@code MBeanServer} if found * @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer */ public static MBeanServer locateMBeanServer() throws MBeanServerNotFoundException { return locateMBeanServer(null); }
@Override public void afterPropertiesSet() { // If no server was provided then try to find one. This is useful in an environment // where there is already an MBeanServer loaded. if (this.server == null) { this.server = JmxUtils.locateMBeanServer(); } }
public MonitoredMBeanAttributeFactory(String name, String description, String mBeanName, String attributeName) { this(name, description, mBeanName, attributeName, null, JmxUtils.locateMBeanServer()); }
public MonitoredMBeanAttributeFactory(String name, String description, String mBeanName, String attributeName, String compositeDataItem) { this(name, description, mBeanName, attributeName, compositeDataItem, JmxUtils.locateMBeanServer()); }
/** * Attempt to locate an existing {@code MBeanServer}. * Called if {@code locateExistingServerIfPossible} is set to {@code true}. * <p>The default implementation attempts to find an {@code MBeanServer} using * a standard lookup. Subclasses may override to add additional location logic. * @param agentId the agent identifier of the MBeanServer to retrieve. * If this parameter is {@code null}, all registered MBeanServers are * considered. * @return the {@code MBeanServer} if found * @throws org.springframework.jmx.MBeanServerNotFoundException * if no {@code MBeanServer} could be found * @see #setLocateExistingServerIfPossible * @see JmxUtils#locateMBeanServer(String) * @see javax.management.MBeanServerFactory#findMBeanServer(String) */ protected MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException { return JmxUtils.locateMBeanServer(agentId); }
/** * Connects to the remote {@code MBeanServer} using the configured {@code JMXServiceURL}: * to the specified JMX service, or to a local MBeanServer if no service URL specified. * @param serviceUrl the JMX service URL to connect to (may be {@code null}) * @param environment the JMX environment for the connector (may be {@code null}) * @param agentId the local JMX MBeanServer's agent id (may be {@code null}) */ public MBeanServerConnection connect(@Nullable JMXServiceURL serviceUrl, @Nullable Map<String, ?> environment, @Nullable String agentId) throws MBeanServerNotFoundException { if (serviceUrl != null) { if (logger.isDebugEnabled()) { logger.debug("Connecting to remote MBeanServer at URL [" + serviceUrl + "]"); } try { this.connector = JMXConnectorFactory.connect(serviceUrl, environment); return this.connector.getMBeanServerConnection(); } catch (IOException ex) { throw new MBeanServerNotFoundException("Could not connect to remote MBeanServer [" + serviceUrl + "]", ex); } } else { logger.debug("Attempting to locate local MBeanServer"); return JmxUtils.locateMBeanServer(agentId); } }
@Test public void testBuilder() throws Exception { final MBeanServer mBeanServer = JmxUtils.locateMBeanServer(); final Set<ObjectInstance> mBeans = mBeanServer.queryMBeans(ObjectName.getInstance("io.syndesis.camel:*"), null); assertThat(mBeans).hasSize(1); final ObjectName objectName = mBeans.iterator().next().getObjectName(); final AttributeList attributes = mBeanServer.getAttributes(objectName, ATTRIBUTES); assertThat(attributes.asList()).hasSize(ATTRIBUTES.length); } }
public void afterPropertiesSet() throws JMException, IOException { if (this.server == null) { this.server = JmxUtils.locateMBeanServer();
public void afterPropertiesSet() throws Exception { csfb = new org.springframework.jmx.support.ConnectorServerFactoryBean(); csfb.setDaemon(daemon); csfb.setThreaded(threaded); csfb.setRegistrationBehavior(registrationBehavior); csfb.setEnvironmentMap(environment); csfb.setObjectName(objectName); serviceUrl = serviceUrl.replaceAll(" ", ""); csfb.setServiceUrl(serviceUrl); MBeanServer mbs = server; if (policy != null) { LOGGER.info("Configuring JMX authorization policy: {}", policy); if (mbs == null) { mbs = createProxyForPolicy(JmxUtils.locateMBeanServer()); } else { mbs = createProxyForPolicy(mbs); } } csfb.setServer(mbs); csfb.afterPropertiesSet(); LOGGER.info("JMX connector available at: {}", serviceUrl); }