Search in sources :

Example 31 with Service

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

the class MBeanFactory method createStandardHost.

/**
 * Create a new StandardHost.
 *
 * @param parent MBean Name of the associated parent component
 * @param name Unique name of this Host
 * @param appBase Application base directory name
 * @param autoDeploy Should we auto deploy?
 * @param deployOnStartup Deploy on server startup?
 * @param deployXML Should we deploy Context XML config files property?
 * @param unpackWARs Should we unpack WARs when auto deploying?
 * @return the object name of the created host
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardHost(String parent, String name, String appBase, boolean autoDeploy, boolean deployOnStartup, boolean deployXML, boolean unpackWARs) throws Exception {
    // Create a new StandardHost instance
    StandardHost host = new StandardHost();
    host.setName(name);
    host.setAppBase(appBase);
    host.setAutoDeploy(autoDeploy);
    host.setDeployOnStartup(deployOnStartup);
    host.setDeployXML(deployXML);
    host.setUnpackWARs(unpackWARs);
    // add HostConfig for active reloading
    HostConfig hostConfig = new HostConfig();
    host.addLifecycleListener(hostConfig);
    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    Engine engine = service.getContainer();
    engine.addChild(host);
    // Return the corresponding MBean name
    return host.getObjectName().toString();
}
Also used : StandardHost(org.apache.catalina.core.StandardHost) HostConfig(org.apache.catalina.startup.HostConfig) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName)

Example 32 with Service

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

the class ServiceMBean method getExecutor.

/**
 * Retrieves executor by name
 * @param name Name of the executor to be retrieved
 * @return a string representation of the executor
 * @throws MBeanException error accessing the associated service
 */
public String getExecutor(String name) throws MBeanException {
    Service service = doGetManagedResource();
    Executor executor = service.getExecutor(name);
    return executor.toString();
}
Also used : Executor(org.apache.catalina.Executor) Service(org.apache.catalina.Service)

Example 33 with Service

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

the class StandardServerSF method storeChildren.

/**
 * Store the specified server element children.
 *
 * @param aWriter Current output writer
 * @param indent Indentation level
 * @param aObject Server to store
 * @param parentDesc The element description
 * @throws Exception Configuration storing error
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aObject, StoreDescription parentDesc) throws Exception {
    if (aObject instanceof StandardServer) {
        StandardServer server = (StandardServer) aObject;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = server.findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        /*LifecycleListener listener = null;
            for (int i = 0; listener == null && i < listeners.length; i++)
                if (listeners[i] instanceof ServerLifecycleListener)
                    listener = listeners[i];
            if (listener != null) {
                StoreDescription elementDesc = getRegistry()
                        .findDescription(
                                StandardServer.class.getName()
                                        + ".[ServerLifecycleListener]");
                if (elementDesc != null) {
                    elementDesc.getStoreFactory().store(aWriter, indent,
                            listener);
                }
            }*/
        // Store nested <GlobalNamingResources> element
        NamingResourcesImpl globalNamingResources = server.getGlobalNamingResources();
        StoreDescription elementDesc = getRegistry().findDescription(NamingResourcesImpl.class.getName() + ".[GlobalNamingResources]");
        if (elementDesc != null) {
            elementDesc.getStoreFactory().store(aWriter, indent, globalNamingResources);
        }
        // Store nested <Service> elements
        Service[] services = server.findServices();
        storeElementArray(aWriter, indent, services);
    }
}
Also used : StandardServer(org.apache.catalina.core.StandardServer) NamingResourcesImpl(org.apache.catalina.deploy.NamingResourcesImpl) Service(org.apache.catalina.Service) LifecycleListener(org.apache.catalina.LifecycleListener)

Example 34 with Service

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

the class ThreadLocalLeakPreventionListener method registerListenersForServer.

private void registerListenersForServer(Server server) {
    for (Service service : server.findServices()) {
        Engine engine = service.getContainer();
        engine.addContainerListener(this);
        registerListenersForEngine(engine);
    }
}
Also used : Service(org.apache.catalina.Service) Engine(org.apache.catalina.Engine)

Example 35 with Service

use of org.apache.catalina.Service in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method tomcatAdditionalConnectors.

@Test
public void tomcatAdditionalConnectors() throws Exception {
    TomcatServletWebServerFactory factory = getFactory();
    Connector[] listeners = new Connector[4];
    for (int i = 0; i < listeners.length; i++) {
        Connector connector = mock(Connector.class);
        given(connector.getState()).willReturn(LifecycleState.STOPPED);
        listeners[i] = connector;
    }
    factory.addAdditionalTomcatConnectors(listeners);
    this.webServer = factory.getWebServer();
    Map<Service, Connector[]> connectors = ((TomcatWebServer) this.webServer).getServiceConnectors();
    assertThat(connectors.values().iterator().next().length).isEqualTo(listeners.length + 1);
}
Also used : Connector(org.apache.catalina.connector.Connector) Service(org.apache.catalina.Service) Test(org.junit.Test)

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