Example usage for javax.management JMX newMXBeanProxy

List of usage examples for javax.management JMX newMXBeanProxy

Introduction

In this page you can find the example usage for javax.management JMX newMXBeanProxy.

Prototype

public static <T> T newMXBeanProxy(MBeanServerConnection connection, ObjectName objectName,
        Class<T> interfaceClass, boolean notificationEmitter) 

Source Link

Document

Make a proxy for an MXBean in a local or remote MBean Server that may also support the methods of NotificationEmitter .

This method behaves the same as #newMXBeanProxy(MBeanServerConnection,ObjectName,Class) , but additionally, if notificationEmitter is true , then the MXBean is assumed to be a NotificationBroadcaster or NotificationEmitter and the returned proxy will implement NotificationEmitter as well as interfaceClass .

Usage

From source file:org.echocat.jemoni.jmx.JmxRegistry.java

@Nonnull
public <T> T getMBeanProxy(@Nonnull ObjectName objectName, @Nonnull Class<T> mbeanInterface) {
    try {//from w  w  w  . j a va 2 s.c  o  m
        final boolean emitter = getServer().isInstanceOf(objectName, NotificationEmitter.class.getName());
        // create an MXBean proxy
        return JMX.newMXBeanProxy(getServer(), objectName, mbeanInterface, emitter);
    } catch (Exception e) {
        throw new RuntimeException("Could not create mbean proxy for " + objectName + ".", e);
    }
}

From source file:org.lsc.jmx.LscAgent.java

/**
 * Bind to the JMX Server //from   w  ww . ja v  a  2s  .  co  m
 */
public boolean jmxBind() {
    try {
        String sUrl = "service:jmx:rmi:///jndi/rmi://" + hostname + ":" + port + "/jmxrmi";
        LOGGER.info("Connecting to remote engine on : " + sUrl);
        url = new JMXServiceURL(sUrl);
        jmxC = new RMIConnector(url, null);
        jmxC.connect();
        jmxc = jmxC.getMBeanServerConnection();
        ObjectName lscServerName = new ObjectName("org.lsc.jmx:type=LscServer");
        lscServer = JMX.newMXBeanProxy(jmxc, lscServerName, LscServer.class, true);
        return true;
    } catch (MalformedObjectNameException e) {
        LOGGER.error(e.toString(), e);
    } catch (NullPointerException e) {
        LOGGER.error(e.toString(), e);
    } catch (MalformedURLException e) {
        LOGGER.error(e.toString(), e);
    } catch (IOException e) {
        LOGGER.error(e.toString(), e);
    }
    return false;
}

From source file:org.lsc.webai.services.LscRemoteCommands.java

private boolean jmxBind() {
    if (lscServer != null) {
        try {//  www  .j  a  va  2 s .co  m
            return lscServer.ping();
        } catch (UndeclaredThrowableException ce) {

        }
    }
    try {
        String sUrl = "service:jmx:rmi:///jndi/rmi://" + hostname + ":" + port + "/jmxrmi";
        LOGGER.info("Connecting to remote engine on : " + sUrl);
        url = new JMXServiceURL(sUrl);
        jmxC = new RMIConnector(url, null);
        jmxC.connect();
        jmxc = jmxC.getMBeanServerConnection();
        ObjectName lscServerName = new ObjectName("org.lsc.jmx:type=LscServer");
        lscServer = JMX.newMXBeanProxy(jmxc, lscServerName, LscServer.class, true);
        return true;
    } catch (MalformedObjectNameException e) {
        LOGGER.error(e.toString(), e);
    } catch (NullPointerException e) {
        LOGGER.error(e.toString(), e);
    } catch (MalformedURLException e) {
        LOGGER.error(e.toString(), e);
    } catch (IOException e) {
        if (!(e.getCause() instanceof ServiceUnavailableException)) {
            LOGGER.error(e.toString(), e);
        }
    }
    return false;
}

From source file:org.marketcetera.photon.internal.marketdata.MarketDataFeed.java

/**
 * Contructor. An exception will be thrown if the supplied URN is invalid or does not correspond
 * to a valid market data feed provider. Valid providers must have provider type "mdata" and be
 * singletons. The singleton instance must have an MXBean interface that implements
 * {@link AbstractMarketDataModuleMXBean} and {@link NotificationEmitter}.
 * //w w w.  j  ava  2  s.c o m
 * @param providerURN
 *            the URN of the feed provider
 * @throws I18NException
 *             if the feed provider is invalid
 */
public MarketDataFeed(final ModuleURN providerURN) throws I18NException {
    try {
        URNUtils.validateProviderURN(providerURN);
        if (!providerURN.providerType().equals(MARKET_DATA_PROVIDER_TYPE))
            throw new I18NException(Messages.MARKET_DATA_FEED_INVALID_PROVIDER_TYPE);
        mDescription = mModuleManager.getProviderInfo(providerURN).getDescription();
        List<ModuleURN> instances = mModuleManager.getModuleInstances(providerURN);
        if (instances.size() != 1)
            throw new I18NException(Messages.MARKET_DATA_FEED_NOT_SINGLETON);
        mInstanceURN = instances.get(0);
        if (!mModuleManager.getModuleInfo(mInstanceURN).isEmitter())
            throw new I18NException(Messages.MARKET_DATA_FEED_NOT_EMITTER);
        ObjectName objectName = mInstanceURN.toObjectName();
        if (!mMBeanServer.isRegistered(objectName)
                || !mMBeanServer.isInstanceOf(objectName, AbstractMarketDataModuleMXBean.class.getName()))
            throw new I18NException(Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
        mMBeanProxy = JMX.newMXBeanProxy(mMBeanServer, objectName, AbstractMarketDataModuleMXBean.class, true);
        ((NotificationEmitter) mMBeanProxy).addNotificationListener(mFeedStatusNotificationListener,
                sFeedStatusFilter, null);
    } catch (MXBeanOperationException e) {
        throw new I18NException(e, Messages.MARKET_DATA_FEED_INVALID_OBJECT_NAME);
    } catch (UndeclaredThrowableException e) {
        throw new I18NException(e.getCause(), Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
    } catch (IOException e) {
        throw new I18NException(e, Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
    } catch (InstanceNotFoundException e) {
        throw new I18NException(e, Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
    }
}

From source file:org.marketcetera.photon.internal.strategy.RemoteAgentManager.java

private EmitterModuleMXBean getMXBean() throws MXBeanOperationException {
    return JMX.newMXBeanProxy(mMBeanServer, mAgentURN.toObjectName(), EmitterModuleMXBean.class, true);
}

From source file:org.marketcetera.photon.marketdata.MarketDataFeed.java

/**
 * Contructor. An exception will be thrown if the supplied URN is invalid or
 * does not correspond to a valid market data feed provider. Valid providers
 * must have provider type "mdata" and be singletons. The singleton instance
 * must have an MXBean interface that implements
 * {@link AbstractMarketDataModuleMXBean} and {@link NotificationEmitter}.
 * //  ww w  .  j  a  v  a 2  s. c o m
 * @param providerURN
 *            the URN of the feed provider
 * @throws I18NException
 *             if the feed provider is invalid
 */
public MarketDataFeed(ModuleURN providerURN) throws I18NException {
    try {
        URNUtils.validateProviderURN(providerURN);
        if (!providerURN.providerType().equals(MARKET_DATA_PROVIDER_TYPE))
            throw new I18NException(Messages.MARKET_DATA_FEED_INVALID_PROVIDER_TYPE);
        mDescription = mModuleManager.getProviderInfo(providerURN).getDescription();
        List<ModuleURN> instances = mModuleManager.getModuleInstances(providerURN);
        if (instances.size() != 1)
            throw new I18NException(Messages.MARKET_DATA_FEED_NOT_SINGLETON);
        mInstanceURN = instances.get(0);
        if (!mModuleManager.getModuleInfo(mInstanceURN).isEmitter())
            throw new I18NException(Messages.MARKET_DATA_FEED_NOT_EMITTER);
        ObjectName objectName = mInstanceURN.toObjectName();
        if (!mMBeanServer.isRegistered(objectName)
                || !mMBeanServer.isInstanceOf(objectName, AbstractMarketDataModuleMXBean.class.getName()))
            throw new I18NException(Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
        mMBeanProxy = JMX.newMXBeanProxy(mMBeanServer, objectName, AbstractMarketDataModuleMXBean.class, true);
        ((NotificationEmitter) mMBeanProxy).addNotificationListener(mFeedStatusNotificationListener,
                sFeedStatusFilter, null);
    } catch (MXBeanOperationException e) {
        throw new I18NException(e, Messages.MARKET_DATA_FEED_INVALID_OBJECT_NAME);
    } catch (UndeclaredThrowableException e) {
        throw new I18NException(e.getCause(), Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
    } catch (IOException e) {
        throw new I18NException(e, Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
    } catch (InstanceNotFoundException e) {
        throw new I18NException(e, Messages.MARKET_DATA_FEED_INVALID_INTERFACE);
    }
}

From source file:org.marketcetera.strategy.StrategyTestBase.java

/**
 * Returns an <code>MXBean</code> interface to the given strategy.
 *
 * @param inModuleURN a <code>ModuleURN</code> value containing a strategy
 * @return a <code>StrategyMXBean</code> value
 * @throws Exception if an error occurs/*from   w w w .  ja va  2s  .  c  o m*/
 */
protected StrategyMXBean getMXProxy(ModuleURN inModuleURN) throws Exception {
    ObjectName objectName = inModuleURN.toObjectName();
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    return JMX.newMXBeanProxy(server, objectName, StrategyMXBean.class, true);
}