// Initialize adapter
adapter = new CoyoteAdapter(this);
protocolHandler.setAdapter(adapter);
+ protocolHandler.setDomain(getDomain());
try {
protocolHandler.init();
* Destroy the protocol (optional).
*/
public void destroy() throws Exception;
+
+
+ /**
+ * Domain for registering handler with JMX.
+ */
+ public void setDomain(String domain);
+ public String getDomain();
}
return oname;
}
+ @Override
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ @Override
public String getDomain() {
return domain;
}
import org.apache.coyote.Adapter;
import org.apache.coyote.ProtocolHandler;
+import org.apache.coyote.RequestGroupInfo;
import org.apache.juli.logging.Log;
import org.apache.tomcat.util.modeler.Registry;
import org.apache.tomcat.util.net.AbstractEndpoint;
return ("http-" + encodedAddr + endpoint.getPort());
}
+ @Override
+ public void init() throws Exception {
+ if (this.domain != null) {
+ try {
+ tpOname = new ObjectName
+ (domain + ":" + "type=ThreadPool,name=" + getName());
+ Registry.getRegistry(null, null)
+ .registerComponent(endpoint, tpOname, null );
+ } catch (Exception e) {
+ getLog().error("Can't register endpoint");
+ }
+ rgOname=new ObjectName(domain +
+ ":type=GlobalRequestProcessor,name=" + getName());
+ Registry.getRegistry(null, null).registerComponent(
+ getRequestGroupInfo(), rgOname, null );
+ }
+
+ endpoint.setName(getName());
+
+ try {
+ endpoint.init();
+ } catch (Exception ex) {
+ getLog().error(
+ sm.getString("http11protocol.endpoint.initerror"), ex);
+ throw ex;
+ }
+ if (getLog().isInfoEnabled())
+ getLog().info(sm.getString("http11protocol.init", getName()));
+ }
+ protected abstract RequestGroupInfo getRequestGroupInfo();
+
@Override
public void pause() throws Exception {
try {
public int getSoLinger() { return endpoint.getSoLinger(); }
public void setSoLinger(int soLinger) { endpoint.setSoLinger(soLinger); }
- @Override
- public abstract void init() throws Exception;
-
// -------------------- JMX related methods --------------------
protected String domain;
return oname;
}
+ @Override
public String getDomain() {
return domain;
}
@Override
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ @Override
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
oname=name;
*/
@Override
public void init() throws Exception {
- endpoint.setName(getName());
- ((AprEndpoint)endpoint).setHandler(cHandler);
-
- try {
- endpoint.init();
- } catch (Exception ex) {
- log.error(sm.getString("http11protocol.endpoint.initerror"), ex);
- throw ex;
- }
- if(log.isInfoEnabled())
- log.info(sm.getString("http11protocol.init", getName()));
+ ((AprEndpoint)endpoint).setHandler(cHandler);
+
+ super.init();
}
@Override
public void start() throws Exception {
- if( this.domain != null ) {
- try {
- tpOname=new ObjectName
- (domain + ":" + "type=ThreadPool,name=" + getName());
- Registry.getRegistry(null, null)
- .registerComponent(endpoint, tpOname, null );
- } catch (Exception e) {
- log.error("Can't register threadpool" );
- }
- rgOname=new ObjectName
- (domain + ":type=GlobalRequestProcessor,name=" + getName());
- Registry.getRegistry(null, null).registerComponent
- ( cHandler.global, rgOname, null );
- }
-
try {
endpoint.start();
} catch (Exception ex) {
super.destroy();
}
+ @Override
+ protected RequestGroupInfo getRequestGroupInfo() {
+ return cHandler.global;
+ }
+
+
private Http11ConnectionHandler cHandler;
public boolean getUseSendfile() { return ((AprEndpoint)endpoint).getUseSendfile(); }
*/
@Override
public void init() throws Exception {
- endpoint.setName(getName());
- ((NioEndpoint)endpoint).setHandler(cHandler);
- try {
- endpoint.init();
- sslImplementation = new JSSEImplementation();
- } catch (Exception ex) {
- log.error(sm.getString("http11protocol.endpoint.initerror"), ex);
- throw ex;
- }
- if(log.isInfoEnabled())
- log.info(sm.getString("http11protocol.init", getName()));
+ ((NioEndpoint)endpoint).setHandler(cHandler);
+ super.init();
}
@Override
public void start() throws Exception {
- if( this.domain != null ) {
- try {
- tpOname=new ObjectName
- (domain + ":" + "type=ThreadPool,name=" + getName());
- Registry.getRegistry(null, null)
- .registerComponent(endpoint, tpOname, null );
- } catch (Exception e) {
- log.error("Can't register threadpool" );
- }
- rgOname=new ObjectName
- (domain + ":type=GlobalRequestProcessor,name=" + getName());
- Registry.getRegistry(null, null).registerComponent
- ( cHandler.global, rgOname, null );
- }
-
try {
+ sslImplementation = new JSSEImplementation();
endpoint.start();
} catch (Exception ex) {
log.error(sm.getString("http11protocol.endpoint.starterror"), ex);
}
+ @Override
+ protected RequestGroupInfo getRequestGroupInfo() {
+ return cHandler.global;
+ }
+
+
// -------------------- Properties--------------------
@Override
public void init() throws Exception {
- ((JIoEndpoint)endpoint).setName(getName());
+
((JIoEndpoint)endpoint).setHandler(cHandler);
+ super.init();
+ }
+
+ @Override
+ public void start() throws Exception {
// Verify the validity of the configured socket factory
try {
if (isSSLEnabled()) {
}
try {
- endpoint.init();
- } catch (Exception ex) {
- log.error(sm.getString("http11protocol.endpoint.initerror"), ex);
- throw ex;
- }
- if (log.isInfoEnabled())
- log.info(sm.getString("http11protocol.init", getName()));
-
- }
-
- @Override
- public void start() throws Exception {
- if (this.domain != null) {
- try {
- tpOname = new ObjectName
- (domain + ":" + "type=ThreadPool,name=" + getName());
- Registry.getRegistry(null, null)
- .registerComponent(endpoint, tpOname, null );
- } catch (Exception e) {
- log.error("Can't register endpoint");
- }
- rgOname=new ObjectName
- (domain + ":type=GlobalRequestProcessor,name=" + getName());
- Registry.getRegistry(null, null).registerComponent
- ( cHandler.global, rgOname, null );
- }
-
- try {
endpoint.start();
} catch (Exception ex) {
log.error(sm.getString("http11protocol.endpoint.starterror"), ex);
cHandler.recycledProcessors.clear();
super.destroy();
}
+
+
+ @Override
+ protected RequestGroupInfo getRequestGroupInfo() {
+ return cHandler.global;
+ }
+
+
// ------------------------------------------------------------- Properties
}
}
-
-
}
protected volatile boolean paused = false;
/**
- * Track the initialization state of the endpoint.
- */
- protected boolean initialized = false;
-
- /**
* Are we using an internal executor
*/
protected volatile boolean internalExecutor = false;
}
- public abstract void init() throws Exception;
+ public void init() throws Exception {
+ // TODO JMX Registration?
+ }
+
public abstract void start() throws Exception;
/**
/**
- * Initialize the endpoint.
+ * Start the APR endpoint, creating acceptor, poller and sendfile threads.
*/
@Override
- public void init()
- throws Exception {
-
- if (initialized)
- return;
+ public void start() throws Exception {
// Create the root APR memory pool
try {
useSendfile = false;
}
- initialized = true;
-
- }
-
-
- /**
- * Start the APR endpoint, creating acceptor, poller and sendfile threads.
- */
- @Override
- public void start()
- throws Exception {
- // Initialize socket if not done before
- if (!initialized) {
- init();
- }
if (!running) {
running = true;
paused = false;
}
}
shutdownExecutor();
- }
-
-
- /**
- * Deallocate APR memory pools, and close server socket.
- */
- @Override
- public void destroy() throws Exception {
- if (running) {
- stop();
- }
-
+
// Destroy pool if it was initialised
if (serverSockPool != 0) {
Pool.destroy(serverSockPool);
Pool.destroy(rootPool);
rootPool = 0;
}
+ }
+
- initialized = false;
+ /**
+ * Deallocate APR memory pools, and close server socket.
+ */
+ @Override
+ public void destroy() throws Exception {
+ if (running) {
+ stop();
+ }
}
// -------------------- Public methods --------------------
@Override
- public void init()
- throws Exception {
+ public void start() throws Exception {
- if (initialized)
- return;
-
// Initialize thread count defaults for acceptor
if (acceptorThreadCount == 0) {
acceptorThreadCount = 1;
throw be;
}
}
- //if( serverTimeout >= 0 )
- // serverSocket.setSoTimeout( serverTimeout );
-
- initialized = true;
-
- }
-
- @Override
- public void start() throws Exception {
- // Initialize socket if not done before
- if (!initialized) {
- init();
- }
+
if (!running) {
running = true;
paused = false;
unlockAccept();
}
shutdownExecutor();
- }
- /**
- * Deallocate APR memory pools, and close server socket.
- */
- @Override
- public void destroy() throws Exception {
- if (running) {
- stop();
- }
if (serverSocket != null) {
try {
if (serverSocket != null)
}
serverSocket = null;
}
- initialized = false ;
+ }
+
+ /**
+ * Deallocate APR memory pools, and close server socket.
+ */
+ @Override
+ public void destroy() throws Exception {
+ if (running) {
+ stop();
+ }
}
}
+ public KeyManager[] wrap(KeyManager[] managers) {
+ if (managers==null) return null;
+ KeyManager[] result = new KeyManager[managers.length];
+ for (int i=0; i<result.length; i++) {
+ if (managers[i] instanceof X509KeyManager && getKeyAlias()!=null) {
+ result[i] = new NioX509KeyManager((X509KeyManager)managers[i],getKeyAlias());
+ } else {
+ result[i] = managers[i];
+ }
+ }
+ return result;
+ }
+
+
// ----------------------------------------------- Public Lifecycle Methods
/**
- * Initialize the endpoint.
+ * Start the NIO endpoint, creating acceptor, poller threads.
*/
@Override
- public void init()
- throws Exception {
-
- if (initialized)
- return;
+ public void start() throws Exception {
serverSock = ServerSocketChannel.open();
socketProperties.setProperties(serverSock.socket());
if (oomParachute>0) reclaimParachute(true);
selectorPool.open();
- initialized = true;
-
- }
-
- public KeyManager[] wrap(KeyManager[] managers) {
- if (managers==null) return null;
- KeyManager[] result = new KeyManager[managers.length];
- for (int i=0; i<result.length; i++) {
- if (managers[i] instanceof X509KeyManager && getKeyAlias()!=null) {
- result[i] = new NioX509KeyManager((X509KeyManager)managers[i],getKeyAlias());
- } else {
- result[i] = managers[i];
- }
- }
- return result;
- }
-
- /**
- * Start the NIO endpoint, creating acceptor, poller threads.
- */
- @Override
- public void start()
- throws Exception {
- // Initialize socket if not done before
- if (!initialized) {
- init();
- }
if (!running) {
running = true;
paused = false;
* Stop the endpoint. This will cause all processing threads to stop.
*/
@Override
- public void stop() {
+ public void stop() throws Exception {
if (!paused) {
pause();
}
processorCache.clear();
shutdownExecutor();
+ // Close server socket
+ serverSock.socket().close();
+ serverSock.close();
+ serverSock = null;
+ sslContext = null;
+ releaseCaches();
+ selectorPool.close();
}
if (running) {
stop();
}
- // Close server socket
- serverSock.socket().close();
- serverSock.close();
- serverSock = null;
- sslContext = null;
- initialized = false;
- releaseCaches();
- selectorPool.close();
+
if (log.isDebugEnabled()) {
log.debug("Destroy completed for "+new InetSocketAddress(getAddress(),getPort()));
}
--- /dev/null
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.util.net;
+
+import java.io.File;
+import java.net.ServerSocket;
+
+import org.apache.catalina.startup.Tomcat;
+import org.apache.catalina.startup.TomcatBaseTest;
+
+/**
+ * Test case for the Endpoint implementations. The testing framework will ensure
+ * that each implementation is tested.
+ */
+public class TestXxxEndpoint extends TomcatBaseTest {
+
+ public void testStartStop() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+ File appDir = new File(getBuildDirectory(), "webapps/examples");
+ tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
+
+ int port = getPort();
+
+ tomcat.start();
+
+ tomcat.getConnector().stop();
+ // This will throw an exception if the socket is not released
+ ServerSocket socket = new ServerSocket(port);
+ socket.close();
+ tomcat.getConnector().start();
+ }
+}
of the deprecated Embedded class. (markt)
</fix>
<fix>
- Further Lifecycle refactoring for Connectors and associated components.
- (markt)
+ <bug>50360</bug>: Further Lifecycle refactoring for Connectors and
+ associated components. The socket is now bound on
+ <code>Connector.start()</code> rather than
+ <code>Connector.init()</code> and the socket is released on
+ <code>Connector.stop()</code> rather than
+ <code>Connector.destroy()</code>.(markt)
</fix>
<fix>
Correct handling of versioned web applications in deployer. (markt)