org.apache.catalina.Executor Java Examples

The following examples show how to use org.apache.catalina.Executor. 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: StandardService.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Override
protected void destroyInternal() throws LifecycleException {
    // Destroy our defined Connectors
    synchronized (connectors) {
        for (Connector connector : connectors) {
            try {
                connector.destroy();
            } catch (Exception e) {
                log.error(sm.getString(
                        "standardService.connector.destroyFailed",
                        connector), e);
            }
        }
    }

    // Destroy any Executors
    for (Executor executor : findExecutors()) {
        executor.destroy();
    }

    if (container != null) {
        container.destroy();
    }

    super.destroyInternal();
}
 
Example #2
Source File: StandardService.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Adds a named executor to the service
 * @param ex Executor
 */
@Override
public void addExecutor(Executor ex) {
    synchronized (executors) {
        if (!executors.contains(ex)) {
            executors.add(ex);
            if (getState().isAvailable()) {
                try {
                    ex.start();
                } catch (LifecycleException x) {
                    log.error("Executor.start", x);
                }
            }
        }
    }
}
 
Example #3
Source File: ConnectorCreateRule.java    From Tomcat8-Source-Read with MIT License 6 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);
    }
    String sslImplementationName = attributes.getValue("sslImplementationName");
    if (sslImplementationName != null) {
        setSSLImplementationName(con, sslImplementationName);
    }
    digester.push(con);
}
 
Example #4
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 #5
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 #6
Source File: TomcatCustomServer.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
protected void initExecutor() {
    final TypeReference<ExecutorConf> type = new TypeReference<ExecutorConf>() {
    };
    final ExecutorConf conf = new ExecutorConf(JSON.parseObject(context.getProperty(TOMCAT_EXECUTOR), type));
    LOGGER.debug("{}", conf.toString());
    final Executor executor = conf.init();
    getService().addExecutor(executor);
}
 
Example #7
Source File: ConnectorCreateRule.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public void _setExecutor(Connector con, Executor ex) throws Exception {
    Method m = IntrospectionUtils.findMethod(con.getProtocolHandler().getClass(),"setExecutor",new Class[] {java.util.concurrent.Executor.class});
    if (m!=null) {
        m.invoke(con.getProtocolHandler(), new Object[] {ex});
    }else {
        log.warn("Connector ["+con+"] does not support external executors. Method setExecutor(java.util.concurrent.Executor) not found.");
    }
}
 
Example #8
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 #9
Source File: StandardService.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Invoke a pre-startup initialization. This is used to allow connectors
 * to bind to restricted ports under Unix operating environments.
 */
@Override
protected void initInternal() throws LifecycleException {

    super.initInternal();
    
    if (container != null) {
        container.init();
    }

    // Initialize any Executors
    for (Executor executor : findExecutors()) {
        if (executor instanceof LifecycleMBeanBase) {
            ((LifecycleMBeanBase) executor).setDomain(getDomain());
        }
        executor.init();
    }

    // Initialize our defined Connectors
    synchronized (connectors) {
        for (Connector connector : connectors) {
            try {
                connector.init();
            } catch (Exception e) {
                String message = sm.getString(
                        "standardService.connector.initFailed", connector);
                log.error(message, e);

                if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
                    throw new LifecycleException(message);
            }
        }
    }
}
 
Example #10
Source File: StandardService.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Start nested components ({@link Executor}s, {@link Connector}s and
 * {@link Container}s) 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 void startInternal() throws LifecycleException {

    if(log.isInfoEnabled())
        log.info(sm.getString("standardService.start.name", this.name));
    setState(LifecycleState.STARTING);

    // Start our defined Container first
    if (container != null) {
        synchronized (container) {
            container.start();
        }
    }

    synchronized (executors) {
        for (Executor executor: executors) {
            executor.start();
        }
    }

    // Start our defined Connectors second
    synchronized (connectors) {
        for (Connector connector: connectors) {
            try {
                // If it has already failed, don't try and start it
                if (connector.getState() != LifecycleState.FAILED) {
                    connector.start();
                }
            } catch (Exception e) {
                log.error(sm.getString(
                        "standardService.connector.startFailed",
                        connector), e);
            }
        }
    }
}
 
Example #11
Source File: StandardService.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Removes an executor from the service
 * @param ex Executor
 */
@Override
public void removeExecutor(Executor ex) {
    synchronized (executors) {
        if ( executors.remove(ex) && getState().isAvailable() ) {
            try {
                ex.stop();
            } catch (LifecycleException e) {
                log.error("Executor.stop", e);
            }
        }
    }
}
 
Example #12
Source File: StandardService.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves executor by name, null if not found
 * @param executorName String
 * @return Executor
 */
@Override
public Executor getExecutor(String executorName) {
    synchronized (executors) {
        for (Executor executor: executors) {
            if (executorName.equals(executor.getName()))
                return executor;
        }
    }
    return null;
}
 
Example #13
Source File: StandardService.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves all executors
 * @return Executor[]
 */
@Override
public Executor[] findExecutors() {
    synchronized (executors) {
        Executor[] arr = new Executor[executors.size()];
        executors.toArray(arr);
        return arr;
    }
}
 
Example #14
Source File: StandardService.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a named executor to the service
 * @param ex Executor
 */
@Override
public void addExecutor(Executor ex) {
    synchronized (executors) {
        if (!executors.contains(ex)) {
            executors.add(ex);
            if (getState().isAvailable())
                try {
                    ex.start();
                } catch (LifecycleException x) {
                    log.error("Executor.start", x);
                }
        }
    }
}
 
Example #15
Source File: ConnectorCreateRule.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public void _setExecutor(Connector con, Executor ex) throws Exception {
    Method m = IntrospectionUtils.findMethod(con.getProtocolHandler().getClass(),"setExecutor",new Class[] {java.util.concurrent.Executor.class});
    if (m!=null) {
        m.invoke(con.getProtocolHandler(), new Object[] {ex});
    }else {
        log.warn("Connector ["+con+"] does not support external executors. Method setExecutor(java.util.concurrent.Executor) not found.");
    }
}
 
Example #16
Source File: StandardService.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
protected void destroyInternal() throws LifecycleException {
    mapperListener.destroy();

    // Destroy our defined Connectors
    synchronized (connectorsLock) {
        for (Connector connector : connectors) {
            try {
                connector.destroy();
            } catch (Exception e) {
                log.error(sm.getString(
                        "standardService.connector.destroyFailed", connector), e);
            }
        }
    }

    // Destroy any Executors
    for (Executor executor : findExecutors()) {
        executor.destroy();
    }

    if (engine != null) {
        engine.destroy();
    }

    super.destroyInternal();
}
 
Example #17
Source File: StandardService.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Removes an executor from the service
 * @param ex Executor
 */
@Override
public void removeExecutor(Executor ex) {
    synchronized (executors) {
        if ( executors.remove(ex) && getState().isAvailable() ) {
            try {
                ex.stop();
            } catch (LifecycleException e) {
                log.error("Executor.stop", e);
            }
        }
    }
}
 
Example #18
Source File: StandardService.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Retrieves executor by name, null if not found
 * @param executorName String
 * @return Executor
 */
@Override
public Executor getExecutor(String executorName) {
    synchronized (executors) {
        for (Executor executor: executors) {
            if (executorName.equals(executor.getName()))
                return executor;
        }
    }
    return null;
}
 
Example #19
Source File: StandardService.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Retrieves all executors
 * @return Executor[]
 */
@Override
public Executor[] findExecutors() {
    synchronized (executors) {
        Executor[] arr = new Executor[executors.size()];
        executors.toArray(arr);
        return arr;
    }
}
 
Example #20
Source File: StandardServiceSF.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Store the specified service element children.
 *
 * @param aWriter Current output writer
 * @param indent Indentation level
 * @param aService Service to store
 * @param parentDesc The element description
 * @throws Exception Configuration storing error
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aService,
        StoreDescription parentDesc) throws Exception {
    if (aService instanceof StandardService) {
        StandardService service = (StandardService) aService;
        // Store nested <Listener> elements
        LifecycleListener listeners[] = ((Lifecycle) service)
                .findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);

        // Store nested <Executor> elements
        Executor[] executors = service.findExecutors();
        storeElementArray(aWriter, indent, executors);

        Connector connectors[] = service.findConnectors();
        storeElementArray(aWriter, indent, connectors);

        // Store nested <Engine> element
        Engine container = service.getContainer();
        if (container != null) {
            StoreDescription elementDesc = getRegistry().findDescription(container.getClass());
            if (elementDesc != null) {
                IStoreFactory factory = elementDesc.getStoreFactory();
                factory.store(aWriter, indent, container);
            }
        }
    }
}
 
Example #21
Source File: ServiceMBean.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Retrieves all executors.
 * @return an array of string representations of the executors
 * @throws MBeanException error accessing the associated service
 */
public String[] findExecutors() throws MBeanException {

    Service service = doGetManagedResource();

    Executor[] executors = service.findExecutors();
    String[] str = new String[executors.length];

    for(int i = 0; i < executors.length; i++){
        str[i] = executors[i].toString();
    }

    return str;
}
 
Example #22
Source File: ConnectorCreateRule.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private static void setExecutor(Connector con, Executor ex) throws Exception {
    Method m = IntrospectionUtils.findMethod(con.getProtocolHandler().getClass(),"setExecutor",new Class[] {java.util.concurrent.Executor.class});
    if (m!=null) {
        m.invoke(con.getProtocolHandler(), new Object[] {ex});
    }else {
        log.warn(sm.getString("connector.noSetExecutor", con));
    }
}
 
Example #23
Source File: StandardService.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Invoke a pre-startup initialization. This is used to allow connectors
 * to bind to restricted ports under Unix operating environments.
 *
 * Service的初始化,通过包括:
 * 1. Engine的初始化工作。
 * 2. 部分线程池的初始化工作。
 * 3. MapperListener的初始化工作。
 * 4. 多个Connector的初始化。
 */
@Override
protected void initInternal() throws LifecycleException {

    super.initInternal();
    /**
     * 初始化engine。可以点击进去看。
     * 我们可以猜到,后面肯定是Host,Context,Wrapper,Servlet.
     *  but,事实并不是如此。此时只是初始化过程.并不会初始化其余容器。其他几个容器的初始化操作是在start阶段完成的。
     *  {@link StandardEngine#initInternal()}
     */
    if (engine != null) {
        engine.init();
    }

    // Initialize any Executors
    //初始化一些线程池
    for (Executor executor : findExecutors()) {
        if (executor instanceof JmxEnabled) {
            ((JmxEnabled) executor).setDomain(getDomain());
        }
        executor.init();
    }

    // Initialize mapper listener
    //初始化映射监听器。(Mapper作为从Service -->Mapper -->Adpter -->Container的链接。)
    mapperListener.init();

    // Initialize our defined Connectors
    synchronized (connectorsLock) {
        for (Connector connector : connectors) {
            try {
                /**
                 * Connector的初始化操作。
                 * {@link Connector#initInternal()}
                 */
                connector.init();
            } catch (Exception e) {
                String message = sm.getString(
                        "standardService.connector.initFailed", connector);
                log.error(message, e);

                if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
                    throw new LifecycleException(message);
            }
        }
    }
}
 
Example #24
Source File: StandardService.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 *
 * 1.BootStrap反射调用Catalina的start。
 * 2.Catalina去调用了StandardServer的start方法。
 * 3.StandardServer调用StandardService的start方法。
 * 4.StandardService调用StandarEngine的start方法。
 *
 *
 * MapperListener start。
 * Connector start。
 * Start nested components ({@link Executor}s, {@link Connector}s and
 * {@link Container}s) and implement the requirements of
 * {@link org.apache.catalina.util.LifecycleBase#startInternal()}.
 * 启动:Executors, Connectors。
 *
 * @exception LifecycleException if this component detects a fatal error
 *  that prevents this component from being used
 */
@Override
protected void startInternal() throws LifecycleException {

    if(log.isInfoEnabled())
        log.info(sm.getString("standardService.start.name", this.name));
    setState(LifecycleState.STARTING);

    // Start our defined Container first
    /***
     * 1.{@link StandardEngine#startInternal()}
     */
    if (engine != null) {
        synchronized (engine) {
            /** Engin引擎启动。
             * {@link StandardEngine#startInternal()}
             */
            engine.start();
        }
    }

    synchronized (executors) {
        for (Executor executor: executors) {
            /**
             * 线程池的启动。
             */
            executor.start();
        }
    }
    /**
     * Connector和Container之间的映射器的启动。
     * {@link MapperListener#startInternal()}
     */
    mapperListener.start();

    // Start our defined Connectors second
    synchronized (connectorsLock) {
        for (Connector connector: connectors) {
            try {
                // If it has already failed, don't try and start it
                if (connector.getState() != LifecycleState.FAILED) {
                    /**
                     * {@link Connector#startInternal()}
                     */
                    connector.start();
                }
            } catch (Exception e) {
                log.error(sm.getString(
                        "standardService.connector.startFailed",
                        connector), e);
            }
        }
    }
}
 
Example #25
Source File: ServiceMBean.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Adds a named executor to the service
 * @param type Classname of the Executor to be added
 * @throws MBeanException error creating the executor
 */
public void addExecutor(String type) throws MBeanException {
    Service service = doGetManagedResource();
    Executor executor = (Executor) newInstance(type);
    service.addExecutor(executor);
}
 
Example #26
Source File: ServiceMBean.java    From Tomcat8-Source-Read with MIT License 2 votes vote down vote up
/**
 * Retrieves executor by name
 * @param name Name of the executor to be retrieved
 * @return a string representation of the executor
 * @throws MBeanException error accessing the associated service
 */
public String getExecutor(String name) throws MBeanException{
    Service service = doGetManagedResource();
    Executor executor = service.getExecutor(name);
    return executor.toString();
}