Author: costin Date: Sat Jun 21 19:38:22 2008 New Revision: 670299 URL: http://svn.apache.org/viewvc?rev=670299&view=rev Log: Fixed the inetd mode ( convenient for port 80, load on demand )
Added: tomcat/sandbox/tomcat-lite/build.properties.default Removed: tomcat/sandbox/tomcat-lite/bin/Tomcat6Sandbox.launch Modified: tomcat/sandbox/tomcat-lite/bin/tomcatInetd.sh tomcat/sandbox/tomcat-lite/build.xml tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/net/SelectorThreadNio.java tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/TomcatLite.java tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/test/CoyoteTestHelper.java Modified: tomcat/sandbox/tomcat-lite/bin/tomcatInetd.sh URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/bin/tomcatInetd.sh?rev=670299&r1=670298&r2=670299&view=diff ============================================================================== --- tomcat/sandbox/tomcat-lite/bin/tomcatInetd.sh (original) +++ tomcat/sandbox/tomcat-lite/bin/tomcatInetd.sh Sat Jun 21 19:38:22 2008 @@ -1,8 +1,11 @@ #!/bin/sh -. $HOME/.bashrc +# Example - you need to set JAVA_HOME, BASE -$BASE=`pwd`/../.. -export CLASSPATH=$BASE/sandbox/classes:$BASE/connectors/bin -cd $BASE/sandbox -exec sudo -u costin java org.apache.coyote.standalone.MainInetd >/tmp/tc.log 2>&1 +JAVA_HOME=/local/opt/jdk1.6.0 + +BIN=`dirname $0` +BASE=$BIN/.. + +cd $BASE +$JAVA_HOME/bin/java -jar $BASE/output/tomcat-lite.jar --async --port 0 >>tcout.log 2>>tcerr.log Added: tomcat/sandbox/tomcat-lite/build.properties.default URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/build.properties.default?rev=670299&view=auto ============================================================================== --- tomcat/sandbox/tomcat-lite/build.properties.default (added) +++ tomcat/sandbox/tomcat-lite/build.properties.default Sat Jun 21 19:38:22 2008 @@ -0,0 +1,5 @@ +watchdog.src=../../watchdog +tc6.src=../../tomcat6 +#Alternative: +#tc6.home=../../tomcat6/output/build + Modified: tomcat/sandbox/tomcat-lite/build.xml URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/build.xml?rev=670299&r1=670298&r2=670299&view=diff ============================================================================== --- tomcat/sandbox/tomcat-lite/build.xml (original) +++ tomcat/sandbox/tomcat-lite/build.xml Sat Jun 21 19:38:22 2008 @@ -13,7 +13,7 @@ <property name="source.vm" value="1.6"/> <property name="compile.optimize" value="true"/> - <property name="compile.debug" value="false" /> + <property name="compile.debug" value="true" /> <property name="compile.deprecation" value="false" /> <property name="compile.source" value="1.6" /> @@ -38,7 +38,7 @@ includeJavaRuntime="false" deprecation="false" classpathref="runtime-deps" - debug="false" > + debug="${compile.debug}" > <src path="java" /> <include name ="org/apache/tomcat/servlets/addon/**" /> <include name ="org/apache/tomcat/servlets/util/**" /> @@ -50,7 +50,7 @@ classpathref="runtime-deps" includeJavaRuntime="false" deprecation="false" - debug="false" > + debug="${compile.debug}" > <src path="tomcat-coyote" /> <include name ="**" /> </javac> @@ -65,7 +65,7 @@ includeJavaRuntime="false" classpathref="runtime-deps" deprecation="false" - debug="false" > + debug="${compile.debug}" > <src path="java" /> <include name ="org/apache/tomcat/servlets/config/**" /> <include name ="org/apache/tomcat/servlets/file/**" /> @@ -81,7 +81,7 @@ target="${target.vm}" includeJavaRuntime="false" deprecation="false" - debug="false" > + debug="${compile.debug}" > <src path="coyote-nio" /> <include name ="**" /> </javac> @@ -98,7 +98,7 @@ classpathref="runtime-deps" includeJavaRuntime="false" deprecation="false" - debug="false" > + debug="${compile.debug}" > <src path="coyote-apr" /> <include name ="**" /> </javac> @@ -114,7 +114,7 @@ classpathref="runtime-deps" includeJavaRuntime="false" deprecation="false" - debug="false" > + debug="${compile.debug}" > <src path="coyote-extensions" /> <include name ="**" /> </javac> @@ -125,7 +125,7 @@ classpathref="runtime-deps" includeJavaRuntime="false" deprecation="false" - debug="false" > + debug="${compile.debug}" > <src path="java" /> <include name ="org/apache/tomcat/lite/**" /> </javac> @@ -141,7 +141,7 @@ classpathref="runtime-deps" includeJavaRuntime="false" deprecation="false" - debug="false" > + debug="${compile.debug}" > <src path="webapps/addons-jasper/WEB-INF/src" /> <include name ="org/apache/tomcat/**" /> <classpath> Modified: tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java?rev=670299&r1=670298&r2=670299&view=diff ============================================================================== --- tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java (original) +++ tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/coyote/adapters/CoyoteServer.java Sat Jun 21 19:38:22 2008 @@ -15,6 +15,7 @@ */ package org.apache.coyote.adapters; +import java.io.IOException; import java.lang.management.ManagementFactory; import org.apache.coyote.Adapter; @@ -96,8 +97,12 @@ /** */ public void run() { - init(); - start(); + try { + init(); + start(); + } catch(IOException ex) { + ex.printStackTrace(); + } } public void setDaemon(boolean b) { @@ -173,7 +178,7 @@ } } - public void start() { + public void start() throws IOException { try { if (started) { return; @@ -200,6 +205,7 @@ started = true; } catch (Throwable e) { e.printStackTrace(); + throw new IOException(e); } } Modified: tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/net/SelectorThreadNio.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/net/SelectorThreadNio.java?rev=670299&r1=670298&r2=670299&view=diff ============================================================================== --- tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/net/SelectorThreadNio.java (original) +++ tomcat/sandbox/tomcat-lite/coyote-extensions/org/apache/tomcat/util/net/SelectorThreadNio.java Sat Jun 21 19:38:22 2008 @@ -644,6 +644,27 @@ } } + /** + * Example config: + * + * www stream tcp wait USER PATH_TO_tomcatInetd.sh + * + * For a different port, you need to add it to /etc/services. + * + * 'wait' is critical - the common use of inetd is 'nowait' for + * tcp services, which doesn't make sense for java ( too slow startup + * time ). It may make sense in future with something like android VM. + * + * In 'wait' mode, inetd will pass the acceptor socket to java - so + * you can listen on port 80 and run as regular user with no special + * code and magic. + * If tomcat dies, inetd will get back the acceptor and on next connection + * restart tomcat. + * + * This also works with xinetd. It might work with Apple launchd. + * + * TODO: detect inactivity for N minutes, exist - to free resources. + */ @Override public void inetdAcceptor(SelectorCallback cstate) throws IOException { SelectorProvider sp=SelectorProvider.provider(); @@ -653,13 +674,19 @@ log.info("Inherited: " + ch.getClass().getName()); // blocking mode ServerSocketChannel ssc=(ServerSocketChannel)ch; + ssc.configureBlocking(false); + SelectorData selectorData = new SelectorData(this); selectorData.channelData = ssc; + selectorData.callback = cstate; synchronized (connectAcceptInterest) { connectAcceptInterest.add(selectorData); } selector.wakeup(); + } else { + log.severe("No inet socket "); + throw new IOException("Invalid inheritedChannel"); } } @@ -857,7 +884,6 @@ while (ci.hasNext()) { SelectorData selectorData = ci.next(); - SelectionKey sk = (SelectionKey) selectorData.selKey; // Find host, port - initiate connection try { @@ -891,8 +917,9 @@ log.info("Pending connect added: " + selectorData.callback); } } - } catch (IOException e) { - e.printStackTrace(); + } catch (Throwable e) { + log.log(Level.SEVERE, "error registering connect/accept", + e); } } connectAcceptInterest.clear(); Modified: tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/TomcatLite.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/TomcatLite.java?rev=670299&r1=670298&r2=670299&view=diff ============================================================================== --- tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/TomcatLite.java (original) +++ tomcat/sandbox/tomcat-lite/java/org/apache/tomcat/lite/TomcatLite.java Sat Jun 21 19:38:22 2008 @@ -57,7 +57,6 @@ private String serverDirName; private File workDir; - private int port = 8080; // all contexts - hostMapper knows about hostnames and how they are mapped. // this shouldn't be needed if we want to delegate ctx management @@ -90,6 +89,10 @@ return contexts; } + public CoyoteServer getConnectors() { + return coyote; + } + public URLClassLoader getContextParentLoader() { if (contextParentLoader == null) { @@ -132,7 +135,6 @@ } public void startConnector() { - coyote.setPort(port); coyote.addAdapter("/", this); try { coyote.init(); @@ -432,11 +434,7 @@ public void setServerDir(String dir) { this.serverDirName = dir; } - - public void setPort(int port) { - this.port = port; - } - + public File getWork() { if (workDir == null) { File rootDirFile = new File(serverDirName); Modified: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java?rev=670299&r1=670298&r2=670299&view=diff ============================================================================== --- tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java (original) +++ tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/lite/TomcatLiteTest.java Sat Jun 21 19:38:22 2008 @@ -32,7 +32,7 @@ void initServer() throws Exception { TomcatLiteTest.initServlets(lite); - lite.setPort(8804); + lite.getConnectors().setPort(8804); // At this point we can add contexts and inject requests, if we want to // do it over HTTP need to start the connector as well. lite.startConnector(); Modified: tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/test/CoyoteTestHelper.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/test/CoyoteTestHelper.java?rev=670299&r1=670298&r2=670299&view=diff ============================================================================== --- tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/test/CoyoteTestHelper.java (original) +++ tomcat/sandbox/tomcat-lite/test/org/apache/tomcat/test/CoyoteTestHelper.java Sat Jun 21 19:38:22 2008 @@ -106,12 +106,17 @@ * * @param port * @return + * @throws IOException * @throws ServletException */ - public static CoyoteServer getTestServer(int port) { + public static CoyoteServer getTestServer(int port) { CoyoteServer server = getCachedServer(port); if (!server.getStarted()) { - server.start(); + try { + server.start(); + } catch (IOException e) { + e.printStackTrace(); + } } return server; } @@ -133,7 +138,7 @@ return server; } - public static CoyoteServer getProxyServer(int port) { + public static CoyoteServer getProxyServer(int port) throws IOException { CoyoteServer server = servers.get(port); if (server == null) { server = new CoyoteServer(port, new ProxyAdapter()); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]