You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Warner Onstine <on...@intalio.com> on 2000/08/11 22:00:06 UTC

custom Catalina startup

Hi all,
I am working on a custom Catalina startup class and had a question.

In the start() method of Catalina.java you have these three actions:
// Start the new server
 if (server instanceof Lifecycle) {
     try {
         ((Lifecycle) server).start();
     } catch (LifecycleException e) {
         System.out.println("Catalina.start: " + e);
  e.printStackTrace(System.out);
     }
 }


 // Wait for the server to be told to shut down
 server.await();

 // Shut down the server
 if (server instanceof Lifecycle) {
     try {
         ((Lifecycle) server).stop();
     } catch (LifecycleException e) {
         System.out.println("Catalina.stop: " + e);
         e.printStackTrace(System.out);
     }
 }

-------------------------------------------

My question is this:  What does the stop((Lifecycle)server).stop method
actually do here?  Having it in the start method doesn't make any sense to
me, so I'm sure I'm missing something.

Thanks,
Warner


Re: custom Catalina startup

Posted by Warner Onstine <on...@intalio.com>.
Thanks Craig, I will take a look at that this weekend.

-warner
----- Original Message -----
From: "Craig R. McClanahan" <Cr...@eng.sun.com>
To: <to...@jakarta.apache.org>
Sent: Friday, August 11, 2000 1:41 PM
Subject: Re: custom Catalina startup


> See below.
>
> Warner Onstine wrote:
>
> > Hi all,
> > I am working on a custom Catalina startup class and had a question.
> >
> > In the start() method of Catalina.java you have these three actions:
> > // Start the new server
> >  if (server instanceof Lifecycle) {
> >      try {
> >          ((Lifecycle) server).start();
> >      } catch (LifecycleException e) {
> >          System.out.println("Catalina.start: " + e);
> >   e.printStackTrace(System.out);
> >      }
> >  }
> >
> >  // Wait for the server to be told to shut down
> >  server.await();
> >
> >  // Shut down the server
> >  if (server instanceof Lifecycle) {
> >      try {
> >          ((Lifecycle) server).stop();
> >      } catch (LifecycleException e) {
> >          System.out.println("Catalina.stop: " + e);
> >          e.printStackTrace(System.out);
> >      }
> >  }
> >
> > -------------------------------------------
> >
> > My question is this:  What does the stop((Lifecycle)server).stop method
> > actually do here?  Having it in the start method doesn't make any sense
to
> > me, so I'm sure I'm missing something.
> >
>
> It is a little bit clumsily coded, but the contents of this start() method
> represents the entire period of time that the server stays running.  So,
when
> you execute
>
>     $CATALINA_HOME/bin/catalina.sh start
>
> what you are really doing is calling the start method you quote above.  It
> configures itself, starts all the components (which, among other things,
> starts a bunch of threads that do all the real work), and waits on the
> server.await() call.
>
> Now, to shut Catalina down, you go execute:
>
>     $CATALINA_HOME/bin/catalina.sh stop
>
> which (in a separate JVM) runs the stop() method of Catalina.java.  This
> method communicates to the control port of the running system, which then
> returns from the await() call; which then stops all the components and
exits
> (shutting down the JVM that was running the server).  In the mean time,
the
> second JVM (the one executing the stop() command) exits as well and you
are
> returned to the command line.
>
> If you are interested in embedding Catalina, an alternative approach to
> consider is to use the org.apache.tomcat.startup.Embedded class (which was
> recently added) that lets you have programmatic control over the creation
and
> start of the various components.  This approach relies on your classes
knowing
> how to configure what they want, instead of the parsing of server.xml that
is
> done in the Catalina class.  There's a simple main() method included in
this
> class that illustrates the kinds of things you can do.
>
> When Catalina is embedded in the J2EE reference implementation, for
example,
> this approach is going to be used.
>
> >
> > Thanks,
> > Warner
> >
>
> Craig
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Re: custom Catalina startup

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
See below.

Warner Onstine wrote:

> Hi all,
> I am working on a custom Catalina startup class and had a question.
>
> In the start() method of Catalina.java you have these three actions:
> // Start the new server
>  if (server instanceof Lifecycle) {
>      try {
>          ((Lifecycle) server).start();
>      } catch (LifecycleException e) {
>          System.out.println("Catalina.start: " + e);
>   e.printStackTrace(System.out);
>      }
>  }
>
>  // Wait for the server to be told to shut down
>  server.await();
>
>  // Shut down the server
>  if (server instanceof Lifecycle) {
>      try {
>          ((Lifecycle) server).stop();
>      } catch (LifecycleException e) {
>          System.out.println("Catalina.stop: " + e);
>          e.printStackTrace(System.out);
>      }
>  }
>
> -------------------------------------------
>
> My question is this:  What does the stop((Lifecycle)server).stop method
> actually do here?  Having it in the start method doesn't make any sense to
> me, so I'm sure I'm missing something.
>

It is a little bit clumsily coded, but the contents of this start() method
represents the entire period of time that the server stays running.  So, when
you execute

    $CATALINA_HOME/bin/catalina.sh start

what you are really doing is calling the start method you quote above.  It
configures itself, starts all the components (which, among other things,
starts a bunch of threads that do all the real work), and waits on the
server.await() call.

Now, to shut Catalina down, you go execute:

    $CATALINA_HOME/bin/catalina.sh stop

which (in a separate JVM) runs the stop() method of Catalina.java.  This
method communicates to the control port of the running system, which then
returns from the await() call; which then stops all the components and exits
(shutting down the JVM that was running the server).  In the mean time, the
second JVM (the one executing the stop() command) exits as well and you are
returned to the command line.

If you are interested in embedding Catalina, an alternative approach to
consider is to use the org.apache.tomcat.startup.Embedded class (which was
recently added) that lets you have programmatic control over the creation and
start of the various components.  This approach relies on your classes knowing
how to configure what they want, instead of the parsing of server.xml that is
done in the Catalina class.  There's a simple main() method included in this
class that illustrates the kinds of things you can do.

When Catalina is embedded in the J2EE reference implementation, for example,
this approach is going to be used.

>
> Thanks,
> Warner
>

Craig