Search in sources :

Example 61 with Service

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

the class FrameworkListener method registerListenersForServer.

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

Example 62 with Service

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

the class MBeanFactory method removeConnector.

/**
 * Remove an existing Connector.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeConnector(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Service service = getService(oname);
    String port = oname.getKeyProperty("port");
    String address = oname.getKeyProperty("address");
    if (address != null) {
        address = ObjectName.unquote(address);
    }
    Connector[] conns = service.findConnectors();
    for (Connector conn : conns) {
        String connAddress = null;
        Object objConnAddress = conn.getProperty("address");
        if (objConnAddress != null) {
            connAddress = ((InetAddress) objConnAddress).getHostAddress();
        }
        String connPort = "" + conn.getPortWithOffset();
        if (address == null) {
            // 'else if' below
            if (connAddress == null && port.equals(connPort)) {
                service.removeConnector(conn);
                conn.destroy();
                break;
            }
        } else if (address.equals(connAddress) && port.equals(connPort)) {
            service.removeConnector(conn);
            conn.destroy();
            break;
        }
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) ObjectName(javax.management.ObjectName)

Example 63 with Service

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

the class MBeanFactory method createConnector.

/**
 * Create a new Connector
 *
 * @param parent MBean Name of the associated parent component
 * @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
 *
 * @exception Exception if an MBean cannot be created or registered
 */
private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL) throws Exception {
    // Set the protocol in the constructor
    String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
    Connector retobj = new Connector(protocol);
    if ((address != null) && (address.length() > 0)) {
        retobj.setProperty("address", address);
    }
    // Set port number
    retobj.setPort(port);
    // Set SSL
    retobj.setSecure(isSSL);
    retobj.setScheme(isSSL ? "https" : "http");
    // Add the new instance to its parent component
    // FIX ME - addConnector will fail
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    service.addConnector(retobj);
    // Return the corresponding MBean name
    ObjectName coname = retobj.getObjectName();
    return coname.toString();
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) ObjectName(javax.management.ObjectName)

Example 64 with Service

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

the class MBeanFactory method removeHost.

/**
 * Remove an existing Host.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeHost(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    String hostName = oname.getKeyProperty("host");
    Service service = getService(oname);
    Engine engine = service.getContainer();
    Host host = (Host) engine.findChild(hostName);
    // Remove this component from its parent component
    if (host != null) {
        engine.removeChild(host);
    }
}
Also used : StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName)

Aggregations

Service (org.apache.catalina.Service)64 StandardService (org.apache.catalina.core.StandardService)25 Connector (org.apache.catalina.connector.Connector)22 Engine (org.apache.catalina.Engine)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