Search in sources :

Example 1 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class ThreadLocalLeakPreventionListener method stopIdleThreads.

/**
     * 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();
            }
        }
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Connector(org.apache.catalina.connector.Connector) Executor(java.util.concurrent.Executor) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) Service(org.apache.catalina.Service) ThreadPoolExecutor(org.apache.tomcat.util.threads.ThreadPoolExecutor) Engine(org.apache.catalina.Engine)

Example 2 with Connector

use of org.apache.catalina.connector.Connector 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 3 with Connector

use of org.apache.catalina.connector.Connector in project tomcat 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 error creating the connector
     */
public void addConnector(String address, int port, boolean isAjp, boolean isSSL) throws MBeanException {
    Service service = doGetManagedResource();
    String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
    Connector connector = new Connector(protocol);
    if ((address != null) && (address.length() > 0)) {
        connector.setProperty("address", address);
    }
    connector.setPort(port);
    connector.setSecure(isSSL);
    connector.setScheme(isSSL ? "https" : "http");
    service.addConnector(connector);
}
Also used : Connector(org.apache.catalina.connector.Connector) Service(org.apache.catalina.Service)

Example 4 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class ConnectorSF method storeChildren.

@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aConnector, StoreDescription parentDesc) throws Exception {
    if (aConnector instanceof Connector) {
        Connector connector = (Connector) aConnector;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = connector.findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <UpgradeProtocol> elements
        UpgradeProtocol[] upgradeProtocols = connector.findUpgradeProtocols();
        storeElementArray(aWriter, indent, upgradeProtocols);
        // Store nested <SSLHostConfig> elements
        SSLHostConfig[] hostConfigs = connector.findSslHostConfigs();
        storeElementArray(aWriter, indent, hostConfigs);
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) UpgradeProtocol(org.apache.coyote.UpgradeProtocol) LifecycleListener(org.apache.catalina.LifecycleListener) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig)

Example 5 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class ConnectorStoreAppender method printAttributes.

@Override
public void printAttributes(PrintWriter writer, int indent, boolean include, Object bean, StoreDescription desc) throws Exception {
    // Render a className attribute if requested
    if (include && desc != null && !desc.isStandard()) {
        writer.print(" className=\"");
        writer.print(bean.getClass().getName());
        writer.print("\"");
    }
    Connector connector = (Connector) bean;
    String protocol = connector.getProtocol();
    List<String> propertyKeys = getPropertyKeys(connector);
    // Create blank instance
    //defaultInstance(bean);
    Object bean2 = new Connector(protocol);
    Iterator<String> propertyIterator = propertyKeys.iterator();
    while (propertyIterator.hasNext()) {
        String key = propertyIterator.next();
        Object value = IntrospectionUtils.getProperty(bean, key);
        if (desc.isTransientAttribute(key)) {
            // Skip the specified exceptions
            continue;
        }
        if (value == null) {
            // Null values are not persisted
            continue;
        }
        if (!isPersistable(value.getClass())) {
            continue;
        }
        Object value2 = IntrospectionUtils.getProperty(bean2, key);
        if (value.equals(value2)) {
            // The property has its default value
            continue;
        }
        if (isPrintValue(bean, bean2, key, desc)) {
            printValue(writer, indent, key, value);
        }
    }
    if (protocol != null && !"HTTP/1.1".equals(protocol)) {
        super.printValue(writer, indent, "protocol", protocol);
    }
    String executorName = connector.getExecutorName();
    if (!Connector.INTERNAL_EXECUTOR_NAME.equals(executorName)) {
        super.printValue(writer, indent, "executor", executorName);
    }
}
Also used : Connector(org.apache.catalina.connector.Connector)

Aggregations

Connector (org.apache.catalina.connector.Connector)66 Test (org.junit.Test)16 Service (org.apache.catalina.Service)14 File (java.io.File)10 Tomcat (org.apache.catalina.startup.Tomcat)10 Context (org.apache.catalina.Context)6 Engine (org.apache.catalina.Engine)6 Properties (java.util.Properties)5 StandardService (org.apache.catalina.core.StandardService)5 SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Executor (org.apache.catalina.Executor)4 HashMap (java.util.HashMap)3 ObjectName (javax.management.ObjectName)3 Container (org.apache.catalina.Container)3 LifecycleException (org.apache.catalina.LifecycleException)3 Wrapper (org.apache.catalina.Wrapper)3 InetAddress (java.net.InetAddress)2