@Override protected void destroyInternal() throws LifecycleException { // 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 (container != null) { container.destroy(); } super.destroyInternal(); }
@Override protected void destroyInternal() throws LifecycleException { // 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 (container != null) { container.destroy(); } super.destroyInternal(); }
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); }
@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(); }
/** * 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); }
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."); } }
/** * 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); } } } }
/** * 查询所有的Executor,设置共享的线程池 * Retrieves all executors * @return Executor[] */ @Override public Executor[] findExecutors() { synchronized (executors) { Executor[] arr = new Executor[executors.size()]; executors.toArray(arr); return arr; } }
/** * 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; }
/** * 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); } } } }
/** * 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 (connectorsLock) { 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); } } } }
/** * 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(); // StandardThreadExecutor#initInternal } // Initialize our defined Connectors synchronized (connectorsLock) { 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); } } } }
/** * Process the beginning of this element. * * @param attributes The attribute list of this element */ public void begin(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); }
/** * Adds a named executor to the service * @param ex Executor */ public void addExecutor(Executor ex) { synchronized (executors) { if (!executors.contains(ex)) { executors.add(ex); if (started) try { ex.start(); } catch (LifecycleException x) { log.error("Executor.start", x); } } } }
/** * Retrieves all executors * @return Executor[] */ public Executor[] findExecutors() { synchronized (executors) { Executor[] arr = new Executor[executors.size()]; executors.toArray(arr); return arr; } }
/** * Retrieves executor by name, null if not found * @param name String * @return Executor */ public Executor getExecutor(String name) { synchronized (executors) { for (int i = 0; i < executors.size(); i++) { if (name.equals(executors.get(i).getName())) return executors.get(i); } } return null; }
/** * Removes an executor from the service * @param ex Executor */ public void removeExecutor(Executor ex) { synchronized (executors) { if ( executors.remove(ex) && started ) { try { ex.stop(); } catch (LifecycleException e) { log.error("Executor.stop", e); } } } }
/** * 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")); } //protocol 1. http 2. ajp Connector con = new Connector(attributes.getValue("protocol")); if ( ex != null ) _setExecutor(con,ex); digester.push(con); }
/** * 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); }
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."); } }
/** * 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); } } } }
/** * Retrieves all executors * * @return Executor[] */ @Override public Executor[] findExecutors() { synchronized (executors) { Executor[] arr = new Executor[executors.size()]; executors.toArray(arr); return arr; } }
/** * 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; }
/** * 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); } } } }
/** * 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 (connectorsLock) { 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); } } } }
/** * 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 (connectorsLock) { 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); } } } }
@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); }
/** * Retrieves all executors * @return Executor[] */ @Override public Executor[] findExecutors() { synchronized (executors) { Executor[] arr = new Executor[executors.size()]; executors.toArray(arr); return arr; } }
/** * 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); } } } }
/** * 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); } } } }