Java 类org.apache.catalina.Engine 实例源码

项目:lazycat    文件:ApplicationContext.java   
private void populateSessionTrackingModes() {
    // URL re-writing is always enabled by default
    defaultSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);
    supportedSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);

    if (context.getCookies()) {
        defaultSessionTrackingModes.add(SessionTrackingMode.COOKIE);
        supportedSessionTrackingModes.add(SessionTrackingMode.COOKIE);
    }

    // SSL not enabled by default as it can only used on its own
    // Context > Host > Engine > Service
    Service s = ((Engine) context.getParent().getParent()).getService();
    Connector[] connectors = s.findConnectors();
    // Need at least one SSL enabled connector to use the SSL session ID.
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getAttribute("SSLEnabled"))) {
            supportedSessionTrackingModes.add(SessionTrackingMode.SSL);
            break;
        }
    }
}
项目:tomcat7    文件:HostConfig.java   
/**
 * Return a File object representing the "configuration root" directory
 * for our associated Host.
 */
protected File configBase() {

    if (configBase != null) {
        return configBase;
    }

    if (host.getXmlBase()!=null) {
        configBase = returnCanonicalPath(host.getXmlBase());
    } else {
        StringBuilder xmlDir = new StringBuilder("conf");
        Container parent = host.getParent();
        if (parent instanceof Engine) {
            xmlDir.append('/');
            xmlDir.append(parent.getName());
        }
        xmlDir.append('/');
        xmlDir.append(host.getName());
        configBase = returnCanonicalPath(xmlDir.toString());
    }
    return (configBase);

}
项目:lazycat    文件:MapperListener.java   
@Override
public void startInternal() throws LifecycleException {

    setState(LifecycleState.STARTING);

    // Find any components that have already been initialized since the
    // MBean listener won't be notified as those components will have
    // already registered their MBeans
    findDefaultHost();

    Engine engine = (Engine) connector.getService().getContainer();
    addListeners(engine);

    Container[] conHosts = engine.findChildren();
    for (Container conHost : conHosts) {
        Host host = (Host) conHost;
        if (!LifecycleState.NEW.equals(host.getState())) {
            // Registering the host will register the context and wrappers
            registerHost(host);
        }
    }
}
项目:tomcat7    文件:EngineConfig.java   
/**
 * Process the START event for an associated Engine.
 *
 * @param event The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the engine we are associated with
    try {
        engine = (Engine) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
项目:tomcat7    文件:MapperListener.java   
@Override
public void startInternal() throws LifecycleException {

    setState(LifecycleState.STARTING);

    // Find any components that have already been initialized since the
    // MBean listener won't be notified as those components will have
    // already registered their MBeans
    findDefaultHost();

    Engine engine = (Engine) connector.getService().getContainer();
    addListeners(engine);

    Container[] conHosts = engine.findChildren();
    for (Container conHost : conHosts) {
        Host host = (Host) conHost;
        if (!LifecycleState.NEW.equals(host.getState())) {
            // Registering the host will register the context and wrappers
            registerHost(host);
        }
    }
}
项目:tomcat7    文件:MBeanUtils.java   
/**
 * Determine the name of the domain to register MBeans for from a given
 * Container.
 * 
 * @param container
 *
 * @deprecated  To be removed since to creates a circular dependency. Will
 *              be replaced in Tomcat 8 by a new method on {@link
 *              Container}.
 */
@Deprecated
public static String getDomain(Container container) {

    String domain = null;

    Container c = container;

    while (!(c instanceof Engine) && c != null) {
        c = c.getParent();
    }

    if (c != null) {
        domain = c.getName();
    }

    return domain;
}
项目:lazycat    文件:RealmBase.java   
/**
 * Return the Server object that is the ultimate parent for the container
 * with which this Realm is associated. If the server cannot be found (eg
 * because the container hierarchy is not complete), <code>null</code> is
 * returned.
 */
protected Server getServer() {
    Container c = container;
    if (c instanceof Context) {
        c = c.getParent();
    }
    if (c instanceof Host) {
        c = c.getParent();
    }
    if (c instanceof Engine) {
        Service s = ((Engine) c).getService();
        if (s != null) {
            return s.getServer();
        }
    }
    return null;
}
项目:tomcat7    文件:RealmBase.java   
/**
 * Return the Server object that is the ultimate parent for the container
 * with which this Realm is associated. If the server cannot be found (eg
 * because the container hierarchy is not complete), <code>null</code> is
 * returned.
 */
protected Server getServer() {
    Container c = container;
    if (c instanceof Context) {
        c = c.getParent();
    }
    if (c instanceof Host) {
        c = c.getParent();
    }
    if (c instanceof Engine) {
        Service s = ((Engine)c).getService();
        if (s != null) {
            return s.getServer();
        }
    }
    return null;
}
项目:tomcat7    文件:ApplicationContext.java   
private void populateSessionTrackingModes() {
    // URL re-writing is always enabled by default
    defaultSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);
    supportedSessionTrackingModes = EnumSet.of(SessionTrackingMode.URL);

    if (context.getCookies()) {
        defaultSessionTrackingModes.add(SessionTrackingMode.COOKIE);
        supportedSessionTrackingModes.add(SessionTrackingMode.COOKIE);
    }

    // SSL not enabled by default as it can only used on its own
    // Context > Host > Engine > Service
    Service s = ((Engine) context.getParent().getParent()).getService();
    Connector[] connectors = s.findConnectors();
    // Need at least one SSL enabled connector to use the SSL session ID.
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getAttribute("SSLEnabled"))) {
            supportedSessionTrackingModes.add(SessionTrackingMode.SSL);
            break;
        }
    }
}
项目:tomcat7    文件:TestHostConfigAutomaticDeployment.java   
private static File getConfigBaseFile(Host host) {
    String path = null;
    if (host.getXmlBase() != null) {
        path = host.getXmlBase();
    } else {
        StringBuilder xmlDir = new StringBuilder("conf");
        Container parent = host.getParent();
        if (parent instanceof Engine) {
            xmlDir.append('/');
            xmlDir.append(parent.getName());
        }
        xmlDir.append('/');
        xmlDir.append(host.getName());
        path = xmlDir.toString();
    }

    return getCanonicalPath(path);
}
项目:lams    文件:Embedded.java   
/**
 * Add a new Engine to the set of defined Engines.
 *
 * @param engine The engine to be added
 */
public synchronized void addEngine(Engine engine) {

    if( log.isDebugEnabled() )
        log.debug("Adding engine (" + engine.getInfo() + ")");

    // Add this Engine to our set of defined Engines
    Engine results[] = new Engine[engines.length + 1];
    for (int i = 0; i < engines.length; i++)
        results[i] = engines[i];
    results[engines.length] = engine;
    engines = results;

    // Start this Engine if necessary
    if (started && (engine instanceof Lifecycle)) {
        try {
            ((Lifecycle) engine).start();
        } catch (LifecycleException e) {
            log.error("Engine.start", e);
        }
    }

    this.container = engine;
}
项目:lams    文件:ContextConfig.java   
protected String getHostConfigPath(String resourceName) {
    StringBuffer result = new StringBuffer();
    Container container = context;
    Container host = null;
    Container engine = null;
    while (container != null) {
        if (container instanceof Host)
            host = container;
        if (container instanceof Engine)
            engine = container;
        container = container.getParent();
    }
    if (engine != null) {
        result.append(engine.getName()).append('/');
    }
    if (host != null) {
        result.append(host.getName()).append('/');
    }
    result.append(resourceName);
    return result.toString();
}
项目:lams    文件:EngineConfig.java   
/**
 * Process the START event for an associated Engine.
 *
 * @param event The lifecycle event that has occurred
 */
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the engine we are associated with
    try {
        engine = (Engine) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
项目:lams    文件:ServerLifecycleListener.java   
/**
 * Create the MBeans for the specified Service and its nested components.
 *
 * @param service Service for which to create MBeans
 *
 * @exception Exception if an exception is thrown during MBean creation
 */
protected void createMBeans(Service service) throws Exception {

    // Create the MBean for the Service itself
    if (log.isDebugEnabled())
        log.debug("Creating MBean for Service " + service);
    //MBeanUtils.createMBean(service);
    if (service instanceof StandardService) {
        ((StandardService) service).addPropertyChangeListener(this);
    }

    // Create the MBeans for the corresponding Connectors
    Connector connectors[] = service.findConnectors();
    for (int j = 0; j < connectors.length; j++) {
        createMBeans(connectors[j]);
    }

    // Create the MBean for the associated Engine and friends
    Engine engine = (Engine) service.getContainer();
    if (engine != null) {
        createMBeans(engine);
    }

}
项目:lams    文件:ServerLifecycleListener.java   
/**
     * Deregister the MBeans for the specified Service and its nested
     * components.
     *
     * @param service Service for which to destroy MBeans
     *
     * @exception Exception if an exception is thrown during MBean destruction
     */
    protected void destroyMBeans(Service service) throws Exception {

        // Deregister the MBeans for the associated Engine
        Engine engine = (Engine) service.getContainer();
        if (engine != null) {
            //destroyMBeans(engine);
        }

//        // Deregister the MBeans for the corresponding Connectors
//        Connector connectors[] = service.findConnectors();
//        for (int j = 0; j < connectors.length; j++) {
//            destroyMBeans(connectors[j], service);
//        }

        // Deregister the MBean for the Service itself
        if (log.isDebugEnabled()) {
            log.debug("Destroying MBean for Service " + service);
        }
        //MBeanUtils.destroyMBean(service);
        if (service instanceof StandardService) {
            ((StandardService) service).removePropertyChangeListener(this);
        }

    }
项目:lams    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>Engine</code> object.
 *
 * @param engine The Engine to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Engine engine)
    throws Exception {

    String mname = createManagedName(engine);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(engine);
    ObjectName oname = createObjectName(domain, engine);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:lams    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>Engine</code> object.
 *
 * @param engine The Engine to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
static void destroyMBean(Engine engine)
    throws Exception {

    String mname = createManagedName(engine);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, engine);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:lams    文件:RewriteValve.java   
/**
 * Find the configuration path where the rewrite configuration file
 * will be stored.
 * 
 * @param resourceName
 * @return
 */
protected String getHostConfigPath(String resourceName) {
    StringBuffer result = new StringBuffer();
    Container container = getContainer();
    Container host = null;
    Container engine = null;
    while (container != null) {
        if (container instanceof Host)
            host = container;
        if (container instanceof Engine)
            engine = container;
        container = container.getParent();
    }
    if (engine != null) {
        result.append(engine.getName()).append('/');
    }
    if (host != null) {
        result.append(host.getName()).append('/');
    }
    result.append(resourceName);
    return result.toString();
}
项目:lams    文件:ClusterListener.java   
/**
 * Reset configuration for a particular proxy following an error.
 */
protected void reset(int pos) {

    Service[] services = ServerFactory.getServer().findServices();
    for (int i = 0; i < services.length; i++) {
        Engine engine = (Engine) services[i].getContainer();
        removeAll((Engine) services[i].getContainer(), pos);
        config(engine, pos);
        Container[] children = engine.findChildren();
        for (int j = 0; j < children.length; j++) {
            Container[] children2 = children[j].findChildren();
            for (int k = 0; k < children2.length; k++) {
                addContext((Context) children2[k], pos);
            }
        }
    }

}
项目:jerrydog    文件:Embedded.java   
/**
 * Add a new Engine to the set of defined Engines.
 *
 * @param engine The engine to be added
 */
public synchronized void addEngine(Engine engine) {

    if (debug >= 1)
        logger.log("Adding engine (" + engine.getInfo() + ")");

    // Add this Engine to our set of defined Engines
    Engine results[] = new Engine[engines.length + 1];
    for (int i = 0; i < engines.length; i++)
        results[i] = engines[i];
    results[engines.length] = engine;
    engines = results;

    // Start this Engine if necessary
    if (started && (engine instanceof Lifecycle)) {
        try {
            ((Lifecycle) engine).start();
        } catch (LifecycleException e) {
            logger.log("Engine.start", e);
        }
    }

}
项目:jerrydog    文件:EngineConfig.java   
/**
 * Process the START event for an associated Engine.
 *
 * @param event The lifecycle event that has occurred
 */
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the engine we are associated with
    try {
        engine = (Engine) event.getLifecycle();
        if (engine instanceof StandardEngine) {
            int engineDebug = ((StandardEngine) engine).getDebug();
            if (engineDebug > this.debug)
                this.debug = engineDebug;
        }
    } catch (ClassCastException e) {
        log(sm.getString("engineConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
项目:lazycat    文件:EngineConfig.java   
/**
 * Process the START event for an associated Engine.
 *
 * @param event
 *            The lifecycle event that has occurred
 */
@Override
public void lifecycleEvent(LifecycleEvent event) {

    // Identify the engine we are associated with
    try {
        engine = (Engine) event.getLifecycle();
    } catch (ClassCastException e) {
        log.error(sm.getString("engineConfig.cce", event.getLifecycle()), e);
        return;
    }

    // Process the event that has occurred
    if (event.getType().equals(Lifecycle.START_EVENT))
        start();
    else if (event.getType().equals(Lifecycle.STOP_EVENT))
        stop();

}
项目:lazycat    文件:Embedded.java   
/**
 * Add a new Engine to the set of defined Engines.
 *
 * @param engine
 *            The engine to be added
 */
public synchronized void addEngine(Engine engine) {

    if (log.isDebugEnabled())
        log.debug("Adding engine (" + engine.getInfo() + ")");

    // Add this Engine to our set of defined Engines
    Engine results[] = new Engine[engines.length + 1];
    for (int i = 0; i < engines.length; i++)
        results[i] = engines[i];
    results[engines.length] = engine;
    engines = results;

    // Start this Engine if necessary
    if (getState().isAvailable()) {
        try {
            engine.start();
        } catch (LifecycleException e) {
            log.error("Engine.start", e);
        }
    }

    this.container = engine;
}
项目:apache-tomcat-7.0.73-with-comment    文件:MBeanUtils.java   
/**
 * Determine the name of the domain to register MBeans for from a given
 * Container.
 * 
 * @param container
 *
 * @deprecated  To be removed since to creates a circular dependency. Will
 *              be replaced in Tomcat 8 by a new method on {@link
 *              Container}.
 */
@Deprecated
public static String getDomain(Container container) {

    String domain = null;

    Container c = container;

    while (!(c instanceof Engine) && c != null) {
        c = c.getParent();
    }

    if (c != null) {
        domain = c.getName();
    }

    return domain;
}
项目:jerrydog    文件:MBeanUtils.java   
/**
 * Create, register, and return an MBean for this
 * <code>Engine</code> object.
 *
 * @param engine The Engine to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(Engine engine)
    throws Exception {

    String mname = createManagedName(engine);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(engine);
    ObjectName oname = createObjectName(domain, engine);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
项目:jerrydog    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>Engine</code> object.
 *
 * @param engine The Engine to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 */
public static void destroyMBean(Engine engine)
    throws Exception {

    String mname = createManagedName(engine);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        return;
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, engine);
    mserver.unregisterMBean(oname);

}
项目:apache-tomcat-7.0.73-with-comment    文件:Embedded.java   
/**
 * Add a new Engine to the set of defined Engines.
 *
 * @param engine The engine to be added
 */
public synchronized void addEngine(Engine engine) {

    if( log.isDebugEnabled() )
        log.debug("Adding engine (" + engine.getInfo() + ")");

    // Add this Engine to our set of defined Engines
    Engine results[] = new Engine[engines.length + 1];
    for (int i = 0; i < engines.length; i++)
        results[i] = engines[i];
    results[engines.length] = engine;
    engines = results;

    // Start this Engine if necessary
    if (getState().isAvailable()) {
        try {
            engine.start();
        } catch (LifecycleException e) {
            log.error("Engine.start", e);
        }
    }

    this.container = engine;
}
项目:apache-tomcat-7.0.73-with-comment    文件:MapperListener.java   
@Override
public void startInternal() throws LifecycleException {

    setState(LifecycleState.STARTING);

    // Find any components that have already been initialized since the
    // MBean listener won't be notified as those components will have
    // already registered their MBeans
    findDefaultHost();

    Engine engine = (Engine) connector.getService().getContainer();
 //递归为所有的容器注册MapperListener监听器 对已经形成的容器建立体系 便于查找
    addListeners(engine);

    Container[] conHosts = engine.findChildren();
    for (Container conHost : conHosts) {
        Host host = (Host) conHost;
        if (!LifecycleState.NEW.equals(host.getState())) {
            // Registering the host will register the context and wrappers
            registerHost(host);
        }
    }
}
项目:tomcat7    文件:DeltaManager.java   
/**
 * Start this component and implement the requirements
 * of {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected synchronized void startInternal() throws LifecycleException {

    super.startInternal();

    // Load unloaded sessions, if any
    try {
        if (cluster == null) {
            log.error(sm.getString("deltaManager.noCluster", getName()));
            return;
        } else {
            if (log.isInfoEnabled()) {
                String type = "unknown" ;
                if( cluster.getContainer() instanceof Host){
                    type = "Host" ;
                } else if( cluster.getContainer() instanceof Engine){
                    type = "Engine" ;
                }
                log.info(sm.getString("deltaManager.registerCluster", getName(), type, cluster.getClusterName()));
            }
        }
        if (log.isInfoEnabled()) log.info(sm.getString("deltaManager.startClustering", getName()));

        getAllClusterSessions();

    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log.error(sm.getString("deltaManager.managerLoad"), t);
    }

    setState(LifecycleState.STARTING);
}
项目:apache-tomcat-7.0.73-with-comment    文件:NamingContextListener.java   
private javax.naming.Context getGlobalNamingContext() {
    if (container instanceof Context) {
        Engine e = (Engine) ((Context) container).getParent().getParent();
        return e.getService().getServer().getGlobalNamingContext();
    }
    return null;
}
项目:tomcat7    文件:SimpleTcpCluster.java   
/**
 * @param name
 * @param manager
 * @return TODO
 */
@Override
public String getManagerName(String name, Manager manager) {
    String clusterName = name ;
    if (clusterName == null) clusterName = manager.getContainer().getName();
    if (getContainer() instanceof Engine) {
        Context context = (Context) manager.getContainer() ;
        Container host = context.getParent();
        if (host instanceof Host && clusterName != null && 
                !(clusterName.startsWith(host.getName() +"#"))) {
            clusterName = host.getName() +"#" + clusterName ;
        }
    }
    return clusterName;
}
项目:apache-tomcat-7.0.73-with-comment    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>Engine</code> object.
 *
 * @param engine The Engine to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 *
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Engine engine)
    throws Exception {
    String domain = engine.getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, engine);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:tomcat7    文件:MapperListener.java   
@Override
public void stopInternal() throws LifecycleException {
    setState(LifecycleState.STOPPING);

    Engine engine = (Engine) connector.getService().getContainer();
    removeListeners(engine);
}
项目:tomcat7    文件:MapperListener.java   
private void findDefaultHost() {

        Engine engine = (Engine) connector.getService().getContainer();
        String defaultHost = engine.getDefaultHost();

        boolean found = false;

        if (defaultHost != null && defaultHost.length() >0) {
            Container[] containers = engine.findChildren();

            for (Container container : containers) {
                Host host = (Host) container;
                if (defaultHost.equalsIgnoreCase(host.getName())) {
                    found = true;
                    break;
                }

                String[] aliases = host.findAliases();
                for (String alias : aliases) {
                    if (defaultHost.equalsIgnoreCase(alias)) {
                        found = true;
                        break;
                    }
                }
            }
        }

        if(found) {
            mapper.setDefaultHostName(defaultHost);
        } else {
            log.warn(sm.getString("mapperListener.unknownDefaultHost",
                    defaultHost, connector));
        }
    }
项目:tomcat7    文件:MBeanFactory.java   
/**
 * 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());

}
项目:tomcat7    文件:MBeanFactory.java   
/**
 * 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 = (Engine) service.getContainer();
    Host host = (Host) engine.findChild(hostName);

    // Remove this component from its parent component
    if(host!=null) {
        engine.removeChild(host);
    }
}
项目:tomcat7    文件:MBeanUtils.java   
/**
 * Deregister the MBean for this
 * <code>Engine</code> object.
 *
 * @param engine The Engine to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 *
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Engine engine)
    throws Exception {
    String domain = engine.getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, engine);
    if( mserver.isRegistered(oname) )
        mserver.unregisterMBean(oname);

}
项目:tomcat7    文件:MBeanUtils.java   
/**
 * Calculate the key properties string to be added to an object's
 * {@link ObjectName} to indicate that it is associated with that container.
 * 
 * @param container The container the object is associated with 
 * @return          A string suitable for appending to the ObjectName
 * @deprecated  To be removed since to creates a circular dependency. Will
 *              be replaced in Tomcat 8 by a new method on {@link
 *              Container}.
 */
@Deprecated
public static String getContainerKeyProperties(Container container) {

    Container c = container;
    StringBuilder keyProperties = new StringBuilder();
    int containerCount = 0;

    // Work up container hierarchy, add a component to the name for
    // each container
    while (!(c instanceof Engine)) {
        if (c instanceof Wrapper) {
            keyProperties.append(",servlet=");
            keyProperties.append(c.getName());
        } else if (c instanceof Context) {
            keyProperties.append(",context=");
            ContextName cn = new ContextName(c.getName(), false);
            keyProperties.append(cn.getDisplayName());
        } else if (c instanceof Host) {
            keyProperties.append(",host=");
            keyProperties.append(c.getName());
        } else if (c == null) {
            // May happen in unit testing and/or some embedding scenarios
            keyProperties.append(",container");
            keyProperties.append(containerCount++);
            keyProperties.append("=null");
            break;
        } else {
            // Should never happen...
            keyProperties.append(",container");
            keyProperties.append(containerCount++);
            keyProperties.append('=');
            keyProperties.append(c.getName());
        }
        c = c.getParent();
    }

    return keyProperties.toString();
}
项目:apache-tomcat-7.0.73-with-comment    文件:ThreadLocalLeakPreventionListener.java   
protected void processContainerRemoveChild(Container parent,
    Container child) {

    if (log.isDebugEnabled())
        log.debug("Process removeChild[parent=" + parent + ",child=" +
            child + "]");

    if (child instanceof Context) {
        Context context = (Context) child;
        context.removeLifecycleListener(this);
    } else if (child instanceof Host || child instanceof Engine) {
        child.removeContainerListener(this);
    }
}
项目:tomcat7    文件:NamingResources.java   
private Server getServer() {
    if (container instanceof Server) {
        return (Server) container;
    }
    if (container instanceof Context) {
        // Could do this in one go. Lots of casts so split out for clarity
        Engine engine =
            (Engine) ((Context) container).getParent().getParent();
        return engine.getService().getServer();
    }
    return null;
}