org.apache.catalina.Service Java Examples

The following examples show how to use org.apache.catalina.Service. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tomcat.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Get the default http connector. You can set more
 * parameters - the port is already initialized.
 *
 * <p>
 * Alternatively, you can construct a Connector and set any params,
 * then call addConnector(Connector)
 *
 * @return A connector object that can be customized
 */
public Connector getConnector() {
    Service service = getService();
    if (service.findConnectors().length > 0) {
        return service.findConnectors()[0];
    }

    if (defaultConnectorCreated) {
        return null;
    }
    // The same as in standard Tomcat configuration.
    // This creates an APR HTTP connector if AprLifecycleListener has been
    // configured (created) and Tomcat Native library is available.
    // Otherwise it creates a NIO HTTP connector.
    Connector connector = new Connector("HTTP/1.1");
    connector.setPort(port);
    service.addConnector(connector);
    defaultConnectorCreated = true;
    return connector;
}
 
Example #2
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * 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 {
    Connector retobj = new Connector();
    if ((address!=null) && (address.length()>0)) {
        retobj.setProperty("address", address);
    }
    // Set port number
    retobj.setPort(port);
    // Set the protocol
    retobj.setProtocol(isAjp ? "AJP/1.3" : "HTTP/1.1");
    // 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());
}
 
Example #4
Source File: TomcatService.java    From armeria with Apache License 2.0 6 votes vote down vote up
static String toString(
        @SuppressWarnings("UnnecessaryFullyQualifiedName") org.apache.catalina.Server server) {

    requireNonNull(server, "server");

    final Service[] services = server.findServices();
    final String serviceName;
    if (services.length == 0) {
        serviceName = "<unknown>";
    } else {
        serviceName = services[0].getName();
    }

    final StringBuilder buf = new StringBuilder(128);

    buf.append("(serviceName: ");
    buf.append(serviceName);
    if (TomcatVersion.major() >= 8) {
        buf.append(", catalinaBase: ");
        buf.append(server.getCatalinaBase());
    }
    buf.append(')');

    return buf.toString();
}
 
Example #5
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * 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("Container not Server");
    }

    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();
}
 
Example #6
Source File: ApplicationContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
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;
        }
    }
}
 
Example #7
Source File: MBeanFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * 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
    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();
}
 
Example #8
Source File: RealmBase.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source File: StandardServer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Add a new Service to the set of defined Services.
 *
 * @param service The Service to be added
 */
@Override
public void addService(Service service) {

    service.setServer(this);

    synchronized (services) {
        Service results[] = new Service[services.length + 1];
        System.arraycopy(services, 0, results, 0, services.length);
        results[services.length] = service;
        services = results;

        if (getState().isAvailable()) {
            try {
                service.start();
            } catch (LifecycleException e) {
                // Ignore
            }
        }

        // Report this property change to interested listeners
        support.firePropertyChange("service", null, service);
    }

}
 
Example #10
Source File: StandardServer.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Return the specified Service (if it exists); otherwise return
 * <code>null</code>.
 *
 * @param name Name of the Service to be returned
 */
@Override
public Service findService(String name) {

    if (name == null) {
        return (null);
    }
    synchronized (services) {
        for (int i = 0; i < services.length; i++) {
            if (name.equals(services[i].getName())) {
                return (services[i]);
            }
        }
    }
    return (null);

}
 
Example #11
Source File: ContextConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private Server getServer() {
    Container c = context;
    while (c != null && !(c instanceof Engine)) {
        c = c.getParent();
    }

    if (c == null) {
        return null;
    }

    Service s = ((Engine)c).getService();

    if (s == null) {
        return null;
    }

    return s.getServer();
}
 
Example #12
Source File: MBeanUtils.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Service</code> object.
 *
 * @param service The Service 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(Service service)
    throws Exception {

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

}
 
Example #13
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #14
Source File: MBeanUtils.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector 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(Connector connector, Service service)
    throws Exception {

    // domain is engine name
    String domain = service.getContainer().getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    // Unregister associated request processor
    String worker = null;
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof Http11Protocol) {
        worker = ((Http11Protocol)handler).getName();
    } else if (handler instanceof Http11NioProtocol) {
        worker = ((Http11NioProtocol)handler).getName();
    } else if (handler instanceof Http11AprProtocol) {
        worker = ((Http11AprProtocol)handler).getName();
    } else if (handler instanceof AjpProtocol) {
        worker = ((AjpProtocol)handler).getName();
    } else if (handler instanceof AjpAprProtocol) {
        worker = ((AjpAprProtocol)handler).getName();
    }
    ObjectName query = new ObjectName(
            domain + ":type=RequestProcessor,worker=" + worker + ",*");
    Set<ObjectName> results = mserver.queryNames(query, null);
    for(ObjectName result : results) {
        mserver.unregisterMBean(result);
    }
}
 
Example #15
Source File: TomcatServerFactory.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
static int getLocalPort(Tomcat tomcat) {
    Service[] services = tomcat.getServer().findServices();
    for (Service service : services) {
        for (Connector connector : service.findConnectors()) {
            ProtocolHandler protocolHandler = connector.getProtocolHandler();
            if (protocolHandler instanceof Http11AprProtocol || protocolHandler instanceof Http11NioProtocol) {
                return connector.getLocalPort();
            }
        }
    }
    return 0;
}
 
Example #16
Source File: ThreadLocalLeakPreventionListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private void registerListenersForServer(Server server) {
    for (Service service : server.findServices()) {
        Engine engine = (Engine) service.getContainer();
        engine.addContainerListener(this);
        registerListenersForEngine(engine);
    }

}
 
Example #17
Source File: ThreadLocalLeakPreventionListener.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Updates each ThreadPoolExecutor with the current time, which is the time
 * when a context is being stopped.
 * 
 * @param context
 *            the context being stopped, used to discover all the Connectors
 *            of its parent Service.
 */
private void stopIdleThreads(Context context) {
    if (serverStopping) return;

    if (!(context instanceof StandardContext) ||
        !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
        log.debug("Not renewing threads when the context is stopping. "
            + "It is not configured to do it.");
        return;
    }

    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    Connector[] connectors = service.findConnectors();
    if (connectors != null) {
        for (Connector connector : connectors) {
            ProtocolHandler handler = connector.getProtocolHandler();
            Executor executor = null;
            if (handler != null) {
                executor = handler.getExecutor();
            }

            if (executor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor threadPoolExecutor =
                    (ThreadPoolExecutor) executor;
                threadPoolExecutor.contextStopping();
            } else if (executor instanceof StandardThreadExecutor) {
                StandardThreadExecutor stdThreadExecutor =
                    (StandardThreadExecutor) executor;
                stdThreadExecutor.contextStopping();
            }

        }
    }
}
 
Example #18
Source File: TomcatSetup.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(final Tomcat tomcat) {
    final Server server = tomcat.getServer();
    server.addLifecycleListener(event -> {
        if (Server.class.isInstance(event.getData()) && Lifecycle.AFTER_DESTROY_EVENT.equals(event.getType())
                && Boolean.getBoolean("talend.component.exit-on-destroy")) {
            System.exit(0);
        }
    });
    // if we want it to be really configurable we should add it in ComponentServerConfiguration
    // and set this instance in the standard context to be able to configure it from cdi side
    final boolean dev = Boolean.getBoolean("talend.component.server.tomcat.valve.error.debug");
    if (!dev) {
        Stream
                .of(server.findServices())
                .map(Service::getContainer)
                .flatMap(e -> Stream.of(e.findChildren()))
                .filter(StandardHost.class::isInstance)
                .map(StandardHost.class::cast)
                .forEach(host -> host.addLifecycleListener(event -> {
                    if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) {
                        StandardHost.class
                                .cast(host)
                                .setErrorReportValveClass(MinimalErrorReportValve.class.getName());
                    }
                }));
    }
}
 
Example #19
Source File: ConnectorCreateRule.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Process the beginning of this element.
 *
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 * @param attributes The attribute list for this element
 */
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
    Service svc = (Service)digester.peek();
    Executor ex = null;
    if ( attributes.getValue("executor")!=null ) {
        ex = svc.getExecutor(attributes.getValue("executor"));
    }
    Connector con = new Connector(attributes.getValue("protocol"));
    if ( ex != null )  _setExecutor(con,ex);
    
    digester.push(con);
}
 
Example #20
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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());

}
 
Example #21
Source File: StandardServer.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain the MBean domain for this server. The domain is obtained using
 * the following search order:
 * <ol>
 * <li>Name of first {@link org.apache.catalina.Engine}.</li>
 * <li>Name of first {@link Service}.</li>
 * </ol>
 */
@Override
protected String getDomainInternal() {
    
    String domain = null;
    
    Service[] services = findServices();
    if (services.length > 0) {
        Service service = services[0];
        if (service != null) {
            domain = MBeanUtils.getDomain(service);
        }
    }
    return domain;
}
 
Example #22
Source File: TomcatWebServer.java    From spring-graalvm-native with Apache License 2.0 5 votes vote down vote up
private void removeServiceConnectors() {
	for (Service service : this.tomcat.getServer().findServices()) {
		Connector[] connectors = service.findConnectors().clone();
		this.serviceConnectors.put(service, connectors);
		for (Connector connector : connectors) {
			service.removeConnector(connector);
		}
	}
}
 
Example #23
Source File: MBeanFactory.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * 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());

}
 
Example #24
Source File: MBeanFactory.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * 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");

    Connector conns[] = service.findConnectors();

    for (int i = 0; i < conns.length; i++) {
        String connAddress = String.valueOf(conns[i].getProperty("address"));
        String connPort = ""+conns[i].getPort();

        // if (((address.equals("null")) &&
        if ((connAddress==null) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
        // } else if (address.equals(connAddress))
        if (port.equals(connPort)) {
            // Remove this component from its parent component
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
    }

}
 
Example #25
Source File: ConnectorCreateRule.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Process the beginning of this element.
 *
 * @param namespace the namespace URI of the matching element, or an 
 *   empty string if the parser is not namespace aware or the element has
 *   no namespace
 * @param name the local name if the parser is namespace aware, or just 
 *   the element name otherwise
 * @param attributes The attribute list for this element
 */
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
    Service svc = (Service)digester.peek();
    Executor ex = null;
    if ( attributes.getValue("executor")!=null ) {
        ex = svc.getExecutor(attributes.getValue("executor"));
    }
    Connector con = new Connector(attributes.getValue("protocol"));
    if ( ex != null )  _setExecutor(con,ex);
    
    digester.push(con);
}
 
Example #26
Source File: TomcatCustomServer.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
protected void initConnector() {
    final TypeReference<ConnectorConf> type = new TypeReference<ConnectorConf>() {
    };
    final ConnectorConf conf = new ConnectorConf(JSON.parseObject(context.getProperty(TOMCAT_CONNECTOR), type));
    LOGGER.debug("{}", conf.toString());
    final Connector connector = conf.init();
    final Service service = getService();
    final Executor executor = service.getExecutor(conf.getExecutor());
    ((AbstractProtocol) connector.getProtocolHandler()).setExecutor(executor);
    setConnector(connector);
    service.addConnector(connector);
}
 
Example #27
Source File: SpringBootWebTwoConnectorsApplicationTests.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Override
public void onApplicationEvent(WebServerInitializedEvent event) {
    Service service = ((TomcatWebServer) event.getWebServer()).getTomcat().getService();
    for (Connector connector : service.findConnectors()) {
        if (connector.getSecure()) {
            this.httpsPort = connector.getLocalPort();
        } else {
            this.httpPort = connector.getLocalPort();
        }
    }
}
 
Example #28
Source File: ArkTomcatWebServer.java    From sofa-ark with Apache License 2.0 5 votes vote down vote up
private void removeServiceConnectors() {
    for (Service service : this.tomcat.getServer().findServices()) {
        Connector[] connectors = service.findConnectors().clone();
        this.serviceConnectors.put(service, connectors);
        for (Connector connector : connectors) {
            service.removeConnector(connector);
        }
    }
}
 
Example #29
Source File: ArkTomcatWebServer.java    From sofa-ark with Apache License 2.0 5 votes vote down vote up
private void addPreviouslyRemovedConnectors() {
    Service[] services = this.tomcat.getServer().findServices();
    for (Service service : services) {
        Connector[] connectors = this.serviceConnectors.get(service);
        if (connectors != null) {
            for (Connector connector : connectors) {
                service.addConnector(connector);
                if (!this.autoStart) {
                    stopProtocolHandler(connector);
                }
            }
            this.serviceConnectors.remove(service);
        }
    }
}
 
Example #30
Source File: ThreadLocalLeakPreventionListener.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Updates each ThreadPoolExecutor with the current time, which is the time
 * when a context is being stopped.
 * 
 * @param context
 *            the context being stopped, used to discover all the Connectors
 *            of its parent Service.
 */
private void stopIdleThreads(Context context) {
    if (serverStopping) return;

    if (!(context instanceof StandardContext) ||
        !((StandardContext) context).getRenewThreadsWhenStoppingContext()) {
        log.debug("Not renewing threads when the context is stopping. "
            + "It is not configured to do it.");
        return;
    }

    Engine engine = (Engine) context.getParent().getParent();
    Service service = engine.getService();
    Connector[] connectors = service.findConnectors();
    if (connectors != null) {
        for (Connector connector : connectors) {
            ProtocolHandler handler = connector.getProtocolHandler();
            Executor executor = null;
            if (handler != null) {
                executor = handler.getExecutor();
            }

            if (executor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor threadPoolExecutor =
                    (ThreadPoolExecutor) executor;
                threadPoolExecutor.contextStopping();
            } else if (executor instanceof StandardThreadExecutor) {
                StandardThreadExecutor stdThreadExecutor =
                    (StandardThreadExecutor) executor;
                stdThreadExecutor.contextStopping();
            }

        }
    }
}