use of org.apache.wicket.jmx.wrapper.PageSettings 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);
}
}
Aggregations