use of org.eclipse.jetty.jmx.MBeanContainer in project qi4j-sdk by Qi4j.
the class AbstractJettyMixin method startJetty.
@Override
public final void startJetty() throws Exception {
// Configure Server
configureServer(server, configuration());
// Set up HTTP
HttpConfiguration httpConfig = new HttpConfiguration();
configureHttp(httpConfig, configuration());
httpConfig = specializeHttp(httpConfig);
// Set up connector
ServerConnector connector = buildConnector(server, httpConfig);
configureConnector(connector, configuration());
// Bind Connector to Server
server.addConnector(connector);
if (mBeanServer != null) {
server.addEventListener(new MBeanContainer(mBeanServer));
}
// Prepare ServletContext
ServletContextHandler root = new ServletContextHandler(server, "/", new SessionHandler(), buildSecurityHandler(), new ServletHandler(), new ErrorHandler());
root.setDisplayName(identity);
configureContext(root, configuration());
// Register ContextListeners, Servlets and Filters
addContextListeners(root, contextListeners);
addServlets(root, servlets);
addFilters(root, filters);
// Start
server.start();
}
use of org.eclipse.jetty.jmx.MBeanContainer in project meteo by pierre.
the class JettyServer method start.
public void start(final Injector injector) throws Exception {
final long startTime = System.currentTimeMillis();
server = new Server();
// Setup JMX
final MBeanContainer mbContainer = new MBeanContainer(mbeanServer);
server.getContainer().addEventListener(mbContainer);
server.addBean(mbContainer);
mbContainer.addBean(Log.getLog());
final Connector connector = new SelectChannelConnector();
connector.setStatsOn(config.isJettyStatsOn());
connector.setHost(config.getLocalIp());
connector.setPort(config.getLocalPort());
server.addConnector(connector);
server.setStopAtShutdown(true);
final ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addEventListener(new GuiceServletContextListener() {
@Override
protected Injector getInjector() {
return injector;
}
});
// Jersey insists on using java.util.logging (JUL)
final EventListener listener = new SetupJULBridge();
context.addEventListener(listener);
// Make sure Guice filter all requests
final FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
// Backend servlet for Guice - never used
final ServletHolder sh = new ServletHolder(DefaultServlet.class);
context.addServlet(sh, "/*");
server.start();
final long secondsToStart = (System.currentTimeMillis() - startTime) / 1000;
log.info(String.format("Jetty server started in %d:%02d", secondsToStart / 60, secondsToStart % 60));
}
use of org.eclipse.jetty.jmx.MBeanContainer in project camel by apache.
the class WebsocketComponent method enableJmx.
private void enableJmx(Server server) {
MBeanContainer containerToRegister = getMbContainer();
if (containerToRegister != null) {
LOG.info("Jetty JMX Extensions is enabled");
server.addEventListener(containerToRegister);
// Since we may have many Servers running, don't tie the MBeanContainer
// to a Server lifecycle or we end up closing it while it is still in use.
//server.addBean(mbContainer);
}
}
use of org.eclipse.jetty.jmx.MBeanContainer in project gocd by gocd.
the class Jetty9ServerTest method shouldAddMBeanContainerAsEventListener.
@Test
public void shouldAddMBeanContainerAsEventListener() throws Exception {
ArgumentCaptor<MBeanContainer> captor = ArgumentCaptor.forClass(MBeanContainer.class);
jetty9Server.configure();
verify(server).addEventListener(captor.capture());
MBeanContainer mBeanContainer = captor.getValue();
assertThat(mBeanContainer.getMBeanServer(), is(not(nullValue())));
}
use of org.eclipse.jetty.jmx.MBeanContainer in project opennms by OpenNMS.
the class JettyServer method onInit.
/** {@inheritDoc} */
@Override
protected void onInit() {
final File jettyXml = new File(System.getProperty("opennms.home") + File.separator + "etc" + File.separator + "jetty.xml");
InputStream jettyXmlStream = null;
try {
m_server = new Server();
// Add JMX MBeans for the Jetty server
MBeanContainer mbeanContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
m_server.addEventListener(mbeanContainer);
m_server.addBean(mbeanContainer);
if (jettyXml.exists()) {
jettyXmlStream = jettyXml.toURI().toURL().openStream();
} else {
jettyXmlStream = getClass().getResourceAsStream("jetty.xml");
}
if (jettyXmlStream == null) {
throw new RuntimeException("Unable to locate jetty.xml in the classpath!");
}
final XmlConfiguration xmlConfiguration = new XmlConfiguration(jettyXmlStream);
xmlConfiguration.configure(m_server);
} catch (final Exception ioe) {
throw new RuntimeException(ioe);
}
m_server.setStopAtShutdown(true);
}
Aggregations