use of org.apache.catalina.Service in project tomcat by apache.
the class Tomcat method getConnector.
// ------- Extra customization -------
// You can tune individual Tomcat objects, using internal APIs
/**
* Get the default HTTP connector that is used by the embedded
* Tomcat. It is first configured connector in the service.
* If there's no connector defined, it will create and add a default
* connector using the port and address specified in this Tomcat
* instance, and return it for further customization.
*
* @return The connector object
*/
public Connector getConnector() {
Service service = getService();
if (service.findConnectors().length > 0) {
return service.findConnectors()[0];
}
// The same as in standard Tomcat configuration.
// This creates a NIO HTTP connector.
Connector connector = new Connector("HTTP/1.1");
connector.setPort(port);
service.addConnector(connector);
return connector;
}
use of org.apache.catalina.Service in project tomcat by apache.
the class Tomcat method getEngine.
/**
* Access to the engine, for further customization.
* @return The engine
*/
public Engine getEngine() {
Service service = getServer().findServices()[0];
if (service.getContainer() != null) {
return service.getContainer();
}
Engine engine = new StandardEngine();
engine.setName("Tomcat");
engine.setDefaultHost(hostname);
engine.setRealm(createDefaultRealm());
service.setContainer(engine);
return engine;
}
use of org.apache.catalina.Service in project tomcat by apache.
the class StandardServer method destroyInternal.
@Override
protected void destroyInternal() throws LifecycleException {
// Destroy our defined Services
for (Service service : services) {
service.destroy();
}
globalNamingResources.destroy();
unregister(onameMBeanFactory);
unregister(onameStringCache);
if (utilityExecutor != null) {
utilityExecutor.shutdownNow();
unregister("type=UtilityExecutor");
utilityExecutor = null;
}
super.destroyInternal();
}
use of org.apache.catalina.Service in project tomcat by apache.
the class StandardServer method startInternal.
/**
* Start nested components ({@link Service}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 {
fireLifecycleEvent(CONFIGURE_START_EVENT, null);
setState(LifecycleState.STARTING);
globalNamingResources.start();
// Start our defined Services
synchronized (servicesLock) {
for (Service service : services) {
service.start();
}
}
if (periodicEventDelay > 0) {
monitorFuture = getUtilityExecutor().scheduleWithFixedDelay(() -> startPeriodicLifecycleEvent(), 0, 60, TimeUnit.SECONDS);
}
}
use of org.apache.catalina.Service 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();
}
}
}
}
Aggregations