Search in sources :

Example 6 with BusLifeCycleManager

use of org.apache.cxf.buslifecycle.BusLifeCycleManager in project cxf by apache.

the class InstrumentationManagerImpl method init.

@PostConstruct
public void init() {
    if (bus != null && bus.getExtension(MBeanServer.class) != null) {
        enabled = true;
        createMBServerConnectorFactory = false;
        mbs = bus.getExtension(MBeanServer.class);
    }
    if (isEnabled()) {
        if (mbs == null) {
            // return platform mbean server if the option is specified.
            if (usePlatformMBeanServer) {
                mbs = ManagementFactory.getPlatformMBeanServer();
            } else {
                String mbeanServerID = mbeanServerIDMap.get(mbeanServerName);
                List<MBeanServer> servers = null;
                if (mbeanServerID != null) {
                    servers = CastUtils.cast(MBeanServerFactory.findMBeanServer(mbeanServerID));
                }
                if (servers == null || servers.isEmpty()) {
                    mbs = MBeanServerFactory.createMBeanServer(mbeanServerName);
                    try {
                        mbeanServerID = (String) mbs.getAttribute(getDelegateName(), "MBeanServerId");
                        mbeanServerIDMap.put(mbeanServerName, mbeanServerID);
                    } catch (JMException e) {
                    // ignore
                    }
                } else {
                    mbs = servers.get(0);
                }
            }
        }
        if (createMBServerConnectorFactory) {
            mcf = MBServerConnectorFactory.getInstance();
            mcf.setMBeanServer(mbs);
            mcf.setThreaded(isThreaded());
            mcf.setDaemon(isDaemon());
            mcf.setServiceUrl(getJMXServiceURL());
            try {
                mcf.createConnector();
            } catch (IOException ex) {
                connectFailed = true;
                LOG.log(Level.SEVERE, "START_CONNECTOR_FAILURE_MSG", new Object[] { ex });
            }
        }
        if (!connectFailed && null != bus) {
            try {
                // Register Bus here since we can guarantee that Instrumentation
                // infrastructure has been initialized.
                ManagedBus mbus = new ManagedBus(bus);
                register(mbus);
                if (LOG.isLoggable(Level.INFO)) {
                    LOG.info("registered " + mbus.getObjectName());
                }
            } catch (JMException jmex) {
                LOG.log(Level.SEVERE, "REGISTER_FAILURE_MSG", new Object[] { bus, jmex });
            }
        }
    }
    if (null != bus) {
        bus.setExtension(this, InstrumentationManager.class);
        BusLifeCycleManager blcm = bus.getExtension(BusLifeCycleManager.class);
        if (null != blcm) {
            blcm.registerLifeCycleListener(this);
        }
    }
}
Also used : ManagedBus(org.apache.cxf.bus.ManagedBus) JMException(javax.management.JMException) BusLifeCycleManager(org.apache.cxf.buslifecycle.BusLifeCycleManager) IOException(java.io.IOException) MBeanServer(javax.management.MBeanServer) PostConstruct(javax.annotation.PostConstruct)

Example 7 with BusLifeCycleManager

use of org.apache.cxf.buslifecycle.BusLifeCycleManager in project cxf by apache.

the class ExtensionManagerBus method initialize.

public void initialize() {
    setState(BusState.INITIALIZING);
    Collection<? extends BusCreationListener> ls = getExtension(ConfiguredBeanLocator.class).getBeansOfType(BusCreationListener.class);
    for (BusCreationListener l : ls) {
        l.busCreated(this);
    }
    doInitializeInternal();
    BusLifeCycleManager lifeCycleManager = this.getExtension(BusLifeCycleManager.class);
    if (null != lifeCycleManager) {
        lifeCycleManager.initComplete();
    }
    setState(BusState.RUNNING);
}
Also used : BusCreationListener(org.apache.cxf.buslifecycle.BusCreationListener) ConfiguredBeanLocator(org.apache.cxf.configuration.ConfiguredBeanLocator) BusLifeCycleManager(org.apache.cxf.buslifecycle.BusLifeCycleManager)

Aggregations

BusLifeCycleManager (org.apache.cxf.buslifecycle.BusLifeCycleManager)7 Bus (org.apache.cxf.Bus)4 BusLifeCycleListener (org.apache.cxf.buslifecycle.BusLifeCycleListener)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 PostConstruct (javax.annotation.PostConstruct)1 JMException (javax.management.JMException)1 MBeanServer (javax.management.MBeanServer)1 ManagedBus (org.apache.cxf.bus.ManagedBus)1 ExtensionManagerBus (org.apache.cxf.bus.extension.ExtensionManagerBus)1 BusCreationListener (org.apache.cxf.buslifecycle.BusCreationListener)1 ConfiguredBeanLocator (org.apache.cxf.configuration.ConfiguredBeanLocator)1 Before (org.junit.Before)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1