Search in sources :

Example 1 with DebugSettings

use of org.apache.wicket.jmx.wrapper.DebugSettings in project wicket by apache.

the class Initializer method init.

@Override
public void init(final org.apache.wicket.Application application) {
    try {
        String name = application.getName();
        String agentId = null;
        try {
            agentId = System.getProperty("wicket.mbean.server.agentid");
        } catch (SecurityException e) {
            // Ignore - we're not allowed to read this property.
            log.warn("not allowed to read property wicket.mbean.server.agentid due to security settings; ignoring");
        }
        if (agentId != null) {
            ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(agentId);
            if (!mbeanServers.isEmpty()) {
                // get first
                mbeanServer = mbeanServers.get(0);
            } else {
                log.error("unable to find mbean server with agent id " + agentId);
            }
        }
        if (mbeanServer == null) {
            String impl = null;
            try {
                impl = System.getProperty("wicket.mbean.server.class");
            } catch (SecurityException e) {
                // Ignore - we're not allowed to read this property.
                log.warn("not allowed to read property wicket.mbean.server.class due to security settings; ignoring");
            }
            if (impl != null) {
                ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
                if (!mbeanServers.isEmpty()) {
                    for (MBeanServer mbs : mbeanServers) {
                        if (mbs.getClass().getName().equals(impl)) {
                            mbeanServer = mbs;
                            break;
                        }
                    }
                }
                if (mbeanServer == null) {
                    log.error("unable to find mbean server of type '{}'", impl);
                }
            }
        }
        if (mbeanServer == null) {
            mbeanServer = ManagementFactory.getPlatformMBeanServer();
        // never null
        }
        log.info("registering Wicket mbeans with server '{}'", mbeanServer);
        // register top level application object, but first check whether
        // multiple instances of the same application (name) are running and
        // if so adjust the name
        String domain = "org.apache.wicket.app." + name;
        ObjectName appBeanName = new ObjectName(domain + ":type=Application");
        String tempDomain = domain;
        int i = 0;
        while (mbeanServer.isRegistered(appBeanName)) {
            tempDomain = name + "-" + i++;
            appBeanName = new ObjectName(tempDomain + ":type=Application");
        }
        domain = tempDomain;
        Application appBean = new Application(application);
        register(application, appBean, appBeanName);
        register(application, new ApplicationSettings(application), new ObjectName(domain + ":type=Application,name=ApplicationSettings"));
        register(application, new DebugSettings(application), new ObjectName(domain + ":type=Application,name=DebugSettings"));
        register(application, new MarkupSettings(application), new ObjectName(domain + ":type=Application,name=MarkupSettings"));
        register(application, new ResourceSettings(application), new ObjectName(domain + ":type=Application,name=ResourceSettings"));
        register(application, new PageSettings(application), new ObjectName(domain + ":type=Application,name=PageSettings"));
        register(application, new RequestCycleSettings(application), new ObjectName(domain + ":type=Application,name=RequestCycleSettings"));
        register(application, new SecuritySettings(application), new ObjectName(domain + ":type=Application,name=SecuritySettings"));
        register(application, new SessionSettings(application), new ObjectName(domain + ":type=Application,name=SessionSettings"));
        register(application, new StoreSettings(application), new ObjectName(domain + ":type=Application,name=StoreSettings"));
        RequestLogger sessionsBean = new RequestLogger(application);
        ObjectName sessionsBeanName = new ObjectName(domain + ":type=RequestLogger");
        register(application, sessionsBean, sessionsBeanName);
    } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
        throw new WicketRuntimeException(e);
    }
}
Also used : MarkupSettings(org.apache.wicket.jmx.wrapper.MarkupSettings) MalformedObjectNameException(javax.management.MalformedObjectNameException) RequestCycleSettings(org.apache.wicket.jmx.wrapper.RequestCycleSettings) PageSettings(org.apache.wicket.jmx.wrapper.PageSettings) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) SecuritySettings(org.apache.wicket.jmx.wrapper.SecuritySettings) SessionSettings(org.apache.wicket.jmx.wrapper.SessionSettings) ObjectName(javax.management.ObjectName) DebugSettings(org.apache.wicket.jmx.wrapper.DebugSettings) StoreSettings(org.apache.wicket.jmx.wrapper.StoreSettings) ApplicationSettings(org.apache.wicket.jmx.wrapper.ApplicationSettings) ResourceSettings(org.apache.wicket.jmx.wrapper.ResourceSettings) RequestLogger(org.apache.wicket.jmx.wrapper.RequestLogger) Application(org.apache.wicket.jmx.wrapper.Application) MBeanRegistrationException(javax.management.MBeanRegistrationException) MBeanServer(javax.management.MBeanServer)

Aggregations

InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MBeanServer (javax.management.MBeanServer)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 ObjectName (javax.management.ObjectName)1 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 Application (org.apache.wicket.jmx.wrapper.Application)1 ApplicationSettings (org.apache.wicket.jmx.wrapper.ApplicationSettings)1 DebugSettings (org.apache.wicket.jmx.wrapper.DebugSettings)1 MarkupSettings (org.apache.wicket.jmx.wrapper.MarkupSettings)1 PageSettings (org.apache.wicket.jmx.wrapper.PageSettings)1 RequestCycleSettings (org.apache.wicket.jmx.wrapper.RequestCycleSettings)1 RequestLogger (org.apache.wicket.jmx.wrapper.RequestLogger)1 ResourceSettings (org.apache.wicket.jmx.wrapper.ResourceSettings)1 SecuritySettings (org.apache.wicket.jmx.wrapper.SecuritySettings)1 SessionSettings (org.apache.wicket.jmx.wrapper.SessionSettings)1 StoreSettings (org.apache.wicket.jmx.wrapper.StoreSettings)1