Search in sources :

Example 26 with Service

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

the class ServiceMBean method findConnectors.

/**
 * Find and return the set of Connectors associated with this Service.
 * @return an array of string representations of the connectors
 * @throws MBeanException error accessing the associated service
 */
public String[] findConnectors() throws MBeanException {
    Service service = doGetManagedResource();
    Connector[] connectors = service.findConnectors();
    String[] str = new String[connectors.length];
    for (int i = 0; i < connectors.length; i++) {
        str[i] = connectors[i].toString();
    }
    return str;
}
Also used : Connector(org.apache.catalina.connector.Connector) Service(org.apache.catalina.Service)

Example 27 with Service

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

the class MBeanFactory method getParentContainerFromChild.

/**
 * Get Parent ContainerBase to add its child component
 * from child component's ObjectName  as a String
 */
private Container getParentContainerFromChild(ObjectName oname) throws Exception {
    String hostName = oname.getKeyProperty("host");
    String path = oname.getKeyProperty("path");
    Service service = getService(oname);
    Container engine = service.getContainer();
    if (hostName == null) {
        // child's container is Engine
        return engine;
    } else if (path == null) {
        // child's container is Host
        Container host = engine.findChild(hostName);
        return host;
    } else {
        // child's container is Context
        Container host = engine.findChild(hostName);
        path = getPathStr(path);
        Container context = host.findChild(path);
        return context;
    }
}
Also used : Container(org.apache.catalina.Container) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Example 28 with Service

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

the class MBeanFactory method removeService.

/**
 * Remove an existing Service.
 *
 * @param name MBean Name of the component to remove
 *
 * @exception Exception if a component cannot be removed
 */
public void removeService(String name) throws Exception {
    if (!(container instanceof Server)) {
        throw new Exception();
    }
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Service service = getService(oname);
    ((Server) container).removeService(service);
}
Also used : MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) ObjectName(javax.management.ObjectName)

Example 29 with Service

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

the class MBeanFactory method createStandardContext.

/**
 * Create a new StandardContext.
 *
 * @param parent MBean Name of the associated parent component
 * @param path The context path for this Context
 * @param docBase Document base directory (or WAR) for this Context
 * @param xmlValidation if XML descriptors should be validated
 * @param xmlNamespaceAware if the XML processor should namespace aware
 * @return the object name of the created context
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createStandardContext(String parent, String path, String docBase, boolean xmlValidation, boolean xmlNamespaceAware) throws Exception {
    // Create a new StandardContext instance
    StandardContext context = new StandardContext();
    path = getPathStr(path);
    context.setPath(path);
    context.setDocBase(docBase);
    context.setXmlValidation(xmlValidation);
    context.setXmlNamespaceAware(xmlNamespaceAware);
    ContextConfig contextConfig = new ContextConfig();
    context.addLifecycleListener(contextConfig);
    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    ObjectName deployer = new ObjectName(pname.getDomain() + ":type=Deployer,host=" + pname.getKeyProperty("host"));
    if (mserver.isRegistered(deployer)) {
        String contextName = context.getName();
        Boolean result = (Boolean) mserver.invoke(deployer, "tryAddServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
        if (result.booleanValue()) {
            try {
                String configPath = (String) mserver.getAttribute(deployer, "configBaseName");
                String baseName = context.getBaseName();
                File configFile = new File(new File(configPath), baseName + ".xml");
                if (configFile.isFile()) {
                    context.setConfigFile(configFile.toURI().toURL());
                }
                mserver.invoke(deployer, "manageApp", new Object[] { context }, new String[] { "org.apache.catalina.Context" });
            } finally {
                mserver.invoke(deployer, "removeServiced", new Object[] { contextName }, new String[] { "java.lang.String" });
            }
        } else {
            throw new IllegalStateException(sm.getString("mBeanFactory.contextCreate.addServicedFail", contextName));
        }
    } else {
        log.warn(sm.getString("mBeanFactory.noDeployer", pname.getKeyProperty("host")));
        Service service = getService(pname);
        Engine engine = service.getContainer();
        Host host = (Host) engine.findChild(pname.getKeyProperty("host"));
        host.addChild(context);
    }
    // Return the corresponding MBean name
    return context.getObjectName().toString();
}
Also used : ContextConfig(org.apache.catalina.startup.ContextConfig) 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) File(java.io.File) StandardEngine(org.apache.catalina.core.StandardEngine) Engine(org.apache.catalina.Engine) ObjectName(javax.management.ObjectName)

Example 30 with Service

use of org.apache.catalina.Service in project tomcat 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
 * @return the object name of the created service
 *
 * @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(sm.getString("mBeanFactory.notServer"));
    }
    StandardEngine engine = new StandardEngine();
    engine.setDomain(domain);
    engine.setName(domain);
    engine.setDefaultHost(defaultHost);
    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)

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