You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2005/11/24 06:34:20 UTC

svn commit: r348665 - /tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java

Author: costin
Date: Wed Nov 23 21:34:19 2005
New Revision: 348665

URL: http://svn.apache.org/viewcvs?rev=348665&view=rev
Log:
Another experiment - this class uses NIO to get the socket from Xinetd ( I'll also try
with launchd ). This allows starting tomcat on-demand, from xinetd/lauchd. 
Work in progress, I also want to shutdown when idle for too long. 

This is also targeted to embeded/desktop use.

Added:
    tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java

Added: tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java
URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java?rev=348665&view=auto
==============================================================================
--- tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java (added)
+++ tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java Wed Nov 23 21:34:19 2005
@@ -0,0 +1,69 @@
+package org.apache.coyote.standalone;
+
+import java.io.IOException;
+import java.nio.channels.Channel;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Timer;
+import java.util.TimerTask;
+
+
+/** 
+ * Used to run tomcat or coyote on demand or on port 80 ( no JNI code needed, 
+ * just (x)inetd, launchd or other simple C wrappers ). This is intended for 
+ * simple configurations, with a single endpoint. 
+ *  
+ * The target for this mode are people running tomcat on their desktop 
+ * machines, either as personal web server or as interface to some applications,
+ * or as developers. It avoids the need to have tomcat taking memory all the 
+ * time - it starts on demand, when you need it, and stops itself when it's
+ * idle too long.  
+ * 
+ */
+public class MainInetd extends Main {
+    Timer timer=new Timer(true); // daemon thread
+    
+    public MainInetd() {        
+    }
+
+    
+    /**
+     */
+    public void run() {
+        init();
+        SelectorProvider sp=SelectorProvider.provider();
+        
+        // check every 5 minutes
+        timer.scheduleAtFixedRate( new IdleCheck(), 300000, 300000);
+        try {
+            Channel ch=sp.inheritedChannel();
+            if(ch!=null ) {
+                System.err.println("Inherited: " + ch.getClass().getName());
+                ServerSocketChannel ssc=(ServerSocketChannel)ch;
+                proto.getEndpoint().setServerSocket( ssc.socket() );
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        
+        
+        
+        start();
+    }
+    
+    class IdleCheck extends TimerTask {
+
+        public void run() {
+            
+        }
+        
+    }
+
+    // ------------------- Main ---------------------
+    public static void main( String args[]) {
+        MainInetd sa=new MainInetd();
+        sa.run();
+    }
+
+    
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r348665 - /tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java

Posted by Costin Manolache <co...@gmail.com>.
I'm a bit puzzled - can you explain a bit why you think it's a bad idea ???

I hope you realize this is not 'prefork' mode ( i.e. forking a tomcat
on each request ), just wait
for the first connection and pass the server socket descriptor. It's
by far the cleanest method to run tomcat on port 80 - either via
xinetd/launchd, or via another native wrapper ( compare it with
commons-daemon ). And the only clean method I know of loading tomcat
on demand - instead of keeping it running and taking memory all the
time. Tomcat is not used only for big servers, but also for
development and smaller servers - I don't like my memory used by code
that I run only once in a while.

Costin

On 11/24/05, Bill Barker <wb...@wilshire.com> wrote:
>
> <co...@apache.org> wrote in message
> news:20051124053420.22279.qmail@minotaur.apache.org...
> > Author: costin
> > Date: Wed Nov 23 21:34:19 2005
> > New Revision: 348665
> >
> > URL: http://svn.apache.org/viewcvs?rev=348665&view=rev
> > Log:
> > Another experiment - this class uses NIO to get the socket from Xinetd (
> > I'll also try
> > with launchd ). This allows starting tomcat on-demand, from xinetd/lauchd.
> > Work in progress, I also want to shutdown when idle for too long.
> >
> > This is also targeted to embeded/desktop use.
> >
>
> About the most useless waste of svn space I could imagine.  I mean, it's
> like a total reason to close off the sandbox right here.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r348665 - /tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java

Posted by Cédrik LIME <cl...@icare-france.com>.
At 00:35 24/11/2005 -0800, you wrote:

><co...@apache.org> wrote in message
>news:20051124053420.22279.qmail@minotaur.apache.org...
> > Author: costin
> > Date: Wed Nov 23 21:34:19 2005
> > New Revision: 348665
> >
> > URL: http://svn.apache.org/viewcvs?rev=348665&view=rev
> > Log:
> > Another experiment - this class uses NIO to get the socket from Xinetd (
> > I'll also try
> > with launchd ). This allows starting tomcat on-demand, from xinetd/lauchd.
> > Work in progress, I also want to shutdown when idle for too long.
> >
> > This is also targeted to embeded/desktop use.
> >
>
>About the most useless waste of svn space I could imagine.  I mean, it's
>like a total reason to close off the sandbox right here.

Disk space is cheap. Why should we prevent new ideas from being expressed?

Even if this particular test won't make it in 
HEAD, even if *most* of the experiments in the 
sandbox will die, it is always useful to express 
ideas: you never you, it may spark a light in 
someone's head for the next killer feature.

+1 to keeping sandbox!

Besides... I find integrating TC with launchd is 
worth its share of geekpoints! O:-)

         Cédrik 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r348665 - /tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java

Posted by Costin Manolache <co...@gmail.com>.
On 11/24/05, Bill Barker <wb...@wilshire.com> wrote:

> > URL: http://svn.apache.org/viewcvs?rev=348665&view=rev
> > Log:
> > Another experiment - this class uses NIO to get the socket from Xinetd (
> > I'll also try
> > with launchd ). This allows starting tomcat on-demand, from xinetd/lauchd.
> > Work in progress, I also want to shutdown when idle for too long.


> About the most useless waste of svn space I could imagine.  I mean, it's
> like a total reason to close off the sandbox right here.

I can move this to sf, but it is far more usefull than a lot of code in tomcat.

Costin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r348665 - /tomcat/sandbox/java/org/apache/coyote/standalone/MainInetd.java

Posted by Bill Barker <wb...@wilshire.com>.
<co...@apache.org> wrote in message 
news:20051124053420.22279.qmail@minotaur.apache.org...
> Author: costin
> Date: Wed Nov 23 21:34:19 2005
> New Revision: 348665
>
> URL: http://svn.apache.org/viewcvs?rev=348665&view=rev
> Log:
> Another experiment - this class uses NIO to get the socket from Xinetd ( 
> I'll also try
> with launchd ). This allows starting tomcat on-demand, from xinetd/lauchd.
> Work in progress, I also want to shutdown when idle for too long.
>
> This is also targeted to embeded/desktop use.
>

About the most useless waste of svn space I could imagine.  I mean, it's 
like a total reason to close off the sandbox right here.




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org