Search in sources :

Example 6 with Service

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

the class MBeanFactory method getParentContainerFromParent.

/**
 * Get Parent ContainerBase to add its child component
 * from parent's ObjectName
 */
private ContainerBase 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);
        Host host = (Host) engine.findChild(hostName);
        String pathStr = getPathStr(path);
        StandardContext context = (StandardContext) 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");
            StandardHost host = (StandardHost) engine.findChild(hostName);
            return host;
        }
    }
    return null;
}
Also used : StandardEngine(org.apache.catalina.core.StandardEngine) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) StandardHost(org.apache.catalina.core.StandardHost) Host(org.apache.catalina.Host)

Example 7 with Service

use of org.apache.catalina.Service in project tomcat70 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?
 *
 * @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 = (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 8 with Service

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

the class MBeanFactory method createStandardServiceEngine.

/**
 * Creates a new StandardService and StandardEngine.
 *
 * @param domain       Domain name for the container instance
 * @param defaultHost  Name of the default host to be used in the Engine
 * @param baseDir      Base directory value for Engine
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardServiceEngine(String domain, String defaultHost, String baseDir) throws Exception {
    if (!(container instanceof Server)) {
        throw new Exception("Container not Server");
    }
    StandardEngine engine = new StandardEngine();
    engine.setDomain(domain);
    engine.setName(domain);
    engine.setDefaultHost(defaultHost);
    engine.setBaseDir(baseDir);
    Service service = new StandardService();
    service.setContainer(engine);
    service.setName(domain);
    ((Server) container).addService(service);
    return engine.getObjectName().toString();
}
Also used : StandardEngine(org.apache.catalina.core.StandardEngine) 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 9 with Service

use of org.apache.catalina.Service in project tomcat70 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
 */
public void addExecutor(String type) throws MBeanException {
    Service service;
    try {
        service = (Service) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (RuntimeOperationsException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    Executor executor;
    try {
        executor = (Executor) Class.forName(type).newInstance();
    } catch (InstantiationException e) {
        throw new MBeanException(e);
    } catch (IllegalAccessException e) {
        throw new MBeanException(e);
    } catch (ClassNotFoundException e) {
        throw new MBeanException(e);
    }
    service.addExecutor(executor);
}
Also used : Executor(org.apache.catalina.Executor) InstanceNotFoundException(javax.management.InstanceNotFoundException) Service(org.apache.catalina.Service) MBeanException(javax.management.MBeanException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 10 with Service

use of org.apache.catalina.Service in project tomcat70 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
 */
public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException {
    Service service;
    try {
        service = (Service) getManagedResource();
    } catch (InstanceNotFoundException e) {
        throw new MBeanException(e);
    } catch (RuntimeOperationsException e) {
        throw new MBeanException(e);
    } catch (InvalidTargetObjectTypeException e) {
        throw new MBeanException(e);
    }
    Connector connector = new Connector();
    if ((address != null) && (address.length() > 0)) {
        connector.setProperty("address", address);
    }
    connector.setPort(port);
    connector.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1");
    connector.setSecure(isSSL);
    connector.setScheme(isSSL ? "https" : "http");
    service.addConnector(connector);
}
Also used : Connector(org.apache.catalina.connector.Connector) InstanceNotFoundException(javax.management.InstanceNotFoundException) Service(org.apache.catalina.Service) MBeanException(javax.management.MBeanException) InvalidTargetObjectTypeException(javax.management.modelmbean.InvalidTargetObjectTypeException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

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