Search in sources :

Example 6 with MBeanContainer

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();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 7 with MBeanContainer

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));
}
Also used : Connector(org.eclipse.jetty.server.Connector) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) MBeanServer(javax.management.MBeanServer) Server(org.eclipse.jetty.server.Server) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) SelectChannelConnector(org.eclipse.jetty.server.nio.SelectChannelConnector) Injector(com.google.inject.Injector) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) EventListener(java.util.EventListener) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) GuiceServletContextListener(com.google.inject.servlet.GuiceServletContextListener)

Example 8 with MBeanContainer

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);
    }
}
Also used : MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer)

Example 9 with MBeanContainer

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())));
}
Also used : MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) Test(org.junit.Test)

Example 10 with MBeanContainer

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);
}
Also used : Server(org.eclipse.jetty.server.Server) InputStream(java.io.InputStream) MBeanContainer(org.eclipse.jetty.jmx.MBeanContainer) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) File(java.io.File)

Aggregations

MBeanContainer (org.eclipse.jetty.jmx.MBeanContainer)24 Server (org.eclipse.jetty.server.Server)15 ServerConnector (org.eclipse.jetty.server.ServerConnector)8 File (java.io.File)7 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)7 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)6 MBeanServer (javax.management.MBeanServer)5 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)5 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)5 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)5 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)4 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)4 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)4 JMXServiceURL (javax.management.remote.JMXServiceURL)3 HashLoginService (org.eclipse.jetty.security.HashLoginService)3 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)3 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)3 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)3