How can I have a class run on start-up?

2001-09-07 Thread Alex Colic

Hi,

hopefully someone can help me with this. I need some type of a class to
start when the web server starts. This class is going to bind itself to a
port and listen to commands from a VB app. Other classes in other web apps
will register themselves with this class to receive these commands.

My questions are:

1: how can you have a class start when the web server starts? This needs to
work with all web servers.
2: how can you have a class in a web app register itself with the class
listening on the port?

Any suggestions are appreciated.

Regards

Alex Colic




Re: How can I have a class run on start-up?

2001-09-07 Thread Jonathan Eric Miller

I don't know the answer to your question, but, I'm wondering if the
application actually has to run in Tomcat. It sounds like you might want to
just create a standalone application that listens on a port.

Jon

- Original Message -
From: Alex Colic [EMAIL PROTECTED]
To: Tomcat-User [EMAIL PROTECTED]
Sent: Friday, September 07, 2001 8:36 AM
Subject: How can I have a class run on start-up?


 Hi,

 hopefully someone can help me with this. I need some type of a class to
 start when the web server starts. This class is going to bind itself to a
 port and listen to commands from a VB app. Other classes in other web apps
 will register themselves with this class to receive these commands.

 My questions are:

 1: how can you have a class start when the web server starts? This needs
to
 work with all web servers.
 2: how can you have a class in a web app register itself with the class
 listening on the port?

 Any suggestions are appreciated.

 Regards

 Alex Colic





RE: How can I have a class run on start-up?

2001-09-07 Thread Peter Romianowski

you could implement a org.apache.catalina.LifecycleListener and attach it to
the context you are using like this:

Context path=/myapp ...
  ...
  Listener className=com.mycompany.MyAppListener/
  ...
/Context

look into the docs for details.
but this is a tomcat-specific thing (and thus not portable).

anyway there's a second approach that comes in mind (but it is not as
clean as the first one)

you simply could write a servlet where you put all code which should be
executed during webapp-initialization into the init-method.
in web.xml you configure the servlet to load on startup. it goes like this:

  servlet
servlet-namesomename/servlet-name
servlet-classsomeclass/servlet-class
load-on-startupa value greater 0/load-on-startup
  /servlet

then the servlet will be called upon webapp-initialization.

dont know if there's is a better (cleaner and portable) solution, but these
two do the job.

greets,
pero

-Original Message-
From: Jonathan Eric Miller [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 07, 2001 7:15 PM
To: [EMAIL PROTECTED]
Subject: Re: How can I have a class run on start-up?


I don't know the answer to your question, but, I'm wondering if the
application actually has to run in Tomcat. It sounds like you might want to
just create a standalone application that listens on a port.

Jon

- Original Message -
From: Alex Colic [EMAIL PROTECTED]
To: Tomcat-User [EMAIL PROTECTED]
Sent: Friday, September 07, 2001 8:36 AM
Subject: How can I have a class run on start-up?


 Hi,

 hopefully someone can help me with this. I need some type of a class to
 start when the web server starts. This class is going to bind itself to a
 port and listen to commands from a VB app. Other classes in other web apps
 will register themselves with this class to receive these commands.

 My questions are:

 1: how can you have a class start when the web server starts? This needs
to
 work with all web servers.
 2: how can you have a class in a web app register itself with the class
 listening on the port?

 Any suggestions are appreciated.

 Regards

 Alex Colic





Re: How can I have a class run on start-up?

2001-09-07 Thread Alex Colic



Hmm. I don't know about that. For the user that would just be another app he
has to start. I was trying to automate things. I was wondering about
creating a servlet and forcing it to run when Tomcat starts.

What do you thing?

Alex


-
I don't know the answer to your question, but, I'm wondering if the
application actually has to run in Tomcat. It sounds like you might want to
just create a standalone application that listens on a port.

Jon




RE: How can I have a class run on start-up?

2001-09-07 Thread Craig R. McClanahan

For a portable solution to the run my class at startup problem, Servlet
2.3 (and therefore Tomcat 4.0) supports a new API called
javax.servlet.ServletContextListener.  If you register such a listener in
your web.xml file, the container will call the contextInitialized() method
when the web application starts up, and contextDestroyed() when the web
application is shut down.

This is safer than the typical approach (use the init() method of a
load-on-startup servlet), because the servlet specification does *not*
guarantee to keep any particular servlet instance in memory for the life
of the application (although Tomcat actually does so).

Craig


On Fri, 7 Sep 2001, Peter Romianowski wrote:

 Date: Fri, 7 Sep 2001 19:35:32 +0200
 From: Peter Romianowski [EMAIL PROTECTED]
 Reply-To: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: RE: How can I have a class run on start-up?

 you could implement a org.apache.catalina.LifecycleListener and attach it to
 the context you are using like this:

 Context path=/myapp ...
   ...
   Listener className=com.mycompany.MyAppListener/
   ...
 /Context

 look into the docs for details.
 but this is a tomcat-specific thing (and thus not portable).

 anyway there's a second approach that comes in mind (but it is not as
 clean as the first one)

 you simply could write a servlet where you put all code which should be
 executed during webapp-initialization into the init-method.
 in web.xml you configure the servlet to load on startup. it goes like this:

   servlet
 servlet-namesomename/servlet-name
 servlet-classsomeclass/servlet-class
 load-on-startupa value greater 0/load-on-startup
   /servlet

 then the servlet will be called upon webapp-initialization.

 dont know if there's is a better (cleaner and portable) solution, but these
 two do the job.

 greets,
 pero

 -Original Message-
 From: Jonathan Eric Miller [mailto:[EMAIL PROTECTED]]
 Sent: Friday, September 07, 2001 7:15 PM
 To: [EMAIL PROTECTED]
 Subject: Re: How can I have a class run on start-up?


 I don't know the answer to your question, but, I'm wondering if the
 application actually has to run in Tomcat. It sounds like you might want to
 just create a standalone application that listens on a port.

 Jon

 - Original Message -
 From: Alex Colic [EMAIL PROTECTED]
 To: Tomcat-User [EMAIL PROTECTED]
 Sent: Friday, September 07, 2001 8:36 AM
 Subject: How can I have a class run on start-up?


  Hi,
 
  hopefully someone can help me with this. I need some type of a class to
  start when the web server starts. This class is going to bind itself to a
  port and listen to commands from a VB app. Other classes in other web apps
  will register themselves with this class to receive these commands.
 
  My questions are:
 
  1: how can you have a class start when the web server starts? This needs
 to
  work with all web servers.
  2: how can you have a class in a web app register itself with the class
  listening on the port?
 
  Any suggestions are appreciated.
 
  Regards
 
  Alex Colic