Search in sources :

Example 16 with Service

use of org.apache.catalina.Service in project tomcat by apache.

the class Tomcat method getConnector.

// ------- Extra customization -------
// You can tune individual Tomcat objects, using internal APIs
/**
 * Get the default HTTP connector that is used by the embedded
 * Tomcat. It is first configured connector in the service.
 * If there's no connector defined, it will create and add a default
 * connector using the port and address specified in this Tomcat
 * instance, and return it for further customization.
 *
 * @return The connector object
 */
public Connector getConnector() {
    Service service = getService();
    if (service.findConnectors().length > 0) {
        return service.findConnectors()[0];
    }
    // The same as in standard Tomcat configuration.
    // This creates a NIO HTTP connector.
    Connector connector = new Connector("HTTP/1.1");
    connector.setPort(port);
    service.addConnector(connector);
    return connector;
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Example 17 with Service

use of org.apache.catalina.Service in project tomcat by apache.

the class Tomcat method getEngine.

/**
 * Access to the engine, for further customization.
 * @return The engine
 */
public Engine getEngine() {
    Service service = getServer().findServices()[0];
    if (service.getContainer() != null) {
        return service.getContainer();
    }
    Engine engine = new StandardEngine();
    engine.setName("Tomcat");
    engine.setDefaultHost(hostname);
    engine.setRealm(createDefaultRealm());
    service.setContainer(engine);
    return engine;
}
Also used : StandardEngine(org.apache.catalina.core.StandardEngine) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine)

Example 18 with Service

use of org.apache.catalina.Service in project tomcat by apache.

the class StandardServer method destroyInternal.

@Override
protected void destroyInternal() throws LifecycleException {
    // Destroy our defined Services
    for (Service service : services) {
        service.destroy();
    }
    globalNamingResources.destroy();
    unregister(onameMBeanFactory);
    unregister(onameStringCache);
    if (utilityExecutor != null) {
        utilityExecutor.shutdownNow();
        unregister("type=UtilityExecutor");
        utilityExecutor = null;
    }
    super.destroyInternal();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.apache.catalina.Service)

Example 19 with Service

use of org.apache.catalina.Service in project tomcat by apache.

the class StandardServer method startInternal.

/**
 * Start nested components ({@link Service}s) and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {
    fireLifecycleEvent(CONFIGURE_START_EVENT, null);
    setState(LifecycleState.STARTING);
    globalNamingResources.start();
    // Start our defined Services
    synchronized (servicesLock) {
        for (Service service : services) {
            service.start();
        }
    }
    if (periodicEventDelay > 0) {
        monitorFuture = getUtilityExecutor().scheduleWithFixedDelay(() -> startPeriodicLifecycleEvent(), 0, 60, TimeUnit.SECONDS);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Service(org.apache.catalina.Service)

Example 20 with Service

use of org.apache.catalina.Service in project tomcat by apache.

the class ThreadLocalLeakPreventionListener method stopIdleThreads.

/**
 * Updates each ThreadPoolExecutor with the current time, which is the time
 * when a context is being stopped.
 *
 * @param context
 *            the context being stopped, used to discover all the Connectors
 *            of its parent Service.
 */
private void stopIdleThreads(Context context) {
    if (serverStopping) {
        return;
    }
    if (!(context instanceof StandardContext) || !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
        log.debug("Not renewing threads when the context is stopping. " + "It is not configured to do it.");
        return;
    }
    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    Connector[] connectors = service.findConnectors();
    if (connectors != null) {
        for (Connector connector : connectors) {
            ProtocolHandler handler = connector.getProtocolHandler();
            Executor executor = null;
            if (handler != null) {
                executor = handler.getExecutor();
            }
            if (executor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
                threadPoolExecutor.contextStopping();
            } else if (executor instanceof StandardThreadExecutor) {
                StandardThreadExecutor stdThreadExecutor = (StandardThreadExecutor) executor;
                stdThreadExecutor.contextStopping();
            }
        }
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Connector(org.apache.catalina.connector.Connector) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) Service(org.apache.catalina.Service) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) Engine(org.apache.catalina.Engine)

Aggregations

Service (org.apache.catalina.Service)62 StandardService (org.apache.catalina.core.StandardService)25 Engine (org.apache.catalina.Engine)20 Connector (org.apache.catalina.connector.Connector)20 StandardEngine (org.apache.catalina.core.StandardEngine)16 ObjectName (javax.management.ObjectName)13 StandardHost (org.apache.catalina.core.StandardHost)12 Container (org.apache.catalina.Container)8 Executor (org.apache.catalina.Executor)8 Server (org.apache.catalina.Server)8 MBeanServer (javax.management.MBeanServer)7 InstanceNotFoundException (javax.management.InstanceNotFoundException)6 MBeanException (javax.management.MBeanException)6 Host (org.apache.catalina.Host)6 File (java.io.File)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 StandardContext (org.apache.catalina.core.StandardContext)5 JarFile (java.util.jar.JarFile)3