Search in sources :

Example 21 with Service

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

the class MBeanFactory method getService.

private Service getService(ObjectName oname) throws Exception {
    if (container instanceof Service) {
        // Don't bother checking the domain - this is the only option
        return (Service) container;
    }
    StandardService service = null;
    String domain = oname.getDomain();
    if (container instanceof Server) {
        Service[] services = ((Server) container).findServices();
        for (Service value : services) {
            service = (StandardService) value;
            if (domain.equals(service.getObjectName().getDomain())) {
                break;
            }
        }
    }
    if (service == null || !service.getObjectName().getDomain().equals(domain)) {
        throw new Exception(sm.getString("mBeanFactory.noService", domain));
    }
    return service;
}
Also used : MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardService(org.apache.catalina.core.StandardService)

Example 22 with Service

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

the class MBeanFactory method getParentContainerFromParent.

/**
 * Get Parent Container to add its child component
 * from parent's ObjectName
 */
private Container getParentContainerFromParent(ObjectName pname) throws Exception {
    String type = pname.getKeyProperty("type");
    String j2eeType = pname.getKeyProperty("j2eeType");
    Service service = getService(pname);
    StandardEngine engine = (StandardEngine) service.getContainer();
    if ((j2eeType != null) && (j2eeType.equals("WebModule"))) {
        String name = pname.getKeyProperty("name");
        name = name.substring(2);
        int i = name.indexOf('/');
        String hostName = name.substring(0, i);
        String path = name.substring(i);
        Container host = engine.findChild(hostName);
        String pathStr = getPathStr(path);
        Container context = host.findChild(pathStr);
        return context;
    } else if (type != null) {
        if (type.equals("Engine")) {
            return engine;
        } else if (type.equals("Host")) {
            String hostName = pname.getKeyProperty("host");
            Container host = engine.findChild(hostName);
            return host;
        }
    }
    return null;
}
Also used : Container(org.apache.catalina.Container) StandardEngine(org.apache.catalina.core.StandardEngine) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Example 23 with Service

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

the class ServiceMBean method addConnector.

/**
 * Add a new Connector to the set of defined Connectors, and associate it
 * with this Service's Container.
 *
 * @param address The IP address on which to bind
 * @param port TCP port number to listen on
 * @param isAjp Create a AJP/1.3 Connector
 * @param isSSL Create a secure Connector
 *
 * @throws MBeanException error creating the connector
 */
public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException {
    Service service = doGetManagedResource();
    String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
    Connector connector = new Connector(protocol);
    if ((address != null) && (address.length() > 0)) {
        connector.setProperty("address", address);
    }
    connector.setPort(port);
    connector.setSecure(isSSL);
    connector.setScheme(isSSL ? "https" : "http");
    service.addConnector(connector);
}
Also used : Connector(org.apache.catalina.connector.Connector) Service(org.apache.catalina.Service)

Example 24 with Service

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

the class ServiceMBean method findExecutors.

/**
 * Retrieves all executors.
 * @return an array of string representations of the executors
 * @throws MBeanException error accessing the associated service
 */
public String[] findExecutors() throws MBeanException {
    Service service = doGetManagedResource();
    Executor[] executors = service.findExecutors();
    String[] str = new String[executors.length];
    for (int i = 0; i < executors.length; i++) {
        str[i] = executors[i].toString();
    }
    return str;
}
Also used : Executor(org.apache.catalina.Executor) Service(org.apache.catalina.Service)

Example 25 with Service

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

the class ServiceMBean method addExecutor.

/**
 * Adds a named executor to the service
 * @param type Classname of the Executor to be added
 * @throws MBeanException error creating the executor
 */
public void addExecutor(String type) throws MBeanException {
    Service service = doGetManagedResource();
    Executor executor = (Executor) newInstance(type);
    service.addExecutor(executor);
}
Also used : Executor(org.apache.catalina.Executor) Service(org.apache.catalina.Service)

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