|
From: Love, E. <EB...@ic...> - 2005-02-25 16:31:31
|
Here are some of the basics of what I did. Keep in mind that I took out =
alot of code dealing with initializing variables such as those to keep =
track of spawned threads, etc. But, you should be able to take this as =
a start and make it your own. For instance, instead of restarting the =
scheduler, you can just restart JBoss.
1. My main wrapper application is a regular java class that implements =
WrapperListener and Runnable. (Runnable so it can be a thread)
public class Scheduler implements WrapperListener, Runnable
2. One of the methods from WrapperListener is start...which is the main =
entry point to your app. I use that to read any config settings, =
initialize values, etc. and then to call my startListener method
3. startListener is a simple method that looks like:
public void startListener()
{
try {
this.processThread =3D new Thread(this);
this.processThread.start();
} catch (Exception e) {
e.printStackTrace();
}
}
4. As with all thread processing, when you call the start method, the =
thread then executes the run method which could do something like...
public void run()
{
long waitTime =3D=20
while (this.runListener) {
try {
// See if any of the jars have changed requiring a =
bounce
=20
if (haveJarsChanged())
{
restartScheduler();
break;
}
Thread.sleep(waitTime);
} catch (InterruptedException e) {
log.error("Interrupted Exception happened: " + =
e.getMessage());
// Sleep was interrupted...expected.
} catch (Exception e) {
log.error("An exception occurred while running the =
schedule", e);
if (++totalErrors >=3D maxErrors)
{
log.error("Too many errors...stopping the Scheduler =
Application");
statusCode =3D -1;
break;
}
}
}
stopListener();
WrapperManager.stop(statusCode);
}
private boolean haveJarsChanged() throws Exception
{
boolean jarsHaveChanged =3D false;
try {
long size =3D watchedJarMap.size();
HashMap tempMap =3D new HashMap();
File directory =3D new File(jarPath);
String files[] =3D directory.list();
for (int i=3D0;i<files.length;i++) {
String fileName =3D files[i];
tempMap.put(fileName, ""+getLastModified(jarPath + "/" + =
fileName));
}
if (size =3D=3D 0)
{
// This is the first time in so set the baseline
watchedJarMap =3D tempMap;
jarsHaveChanged =3D false;
} else if (size !=3D tempMap.size()) {
// Jars have been added or deleted.
jarsHaveChanged =3D true;
} else {
Iterator iterator =3D watchedJarMap.keySet().iterator();
while (iterator.hasNext())
{
String fileName =3D (String)iterator.next();
String newTime =3D (String)tempMap.get(fileName);
if (newTime =3D=3D null)
{
// The jar no longer exists (have to check =
because the old jar count can still match new jar count)
jarsHaveChanged =3D true;
}
long originalTime =3D =
Long.parseLong((String)watchedJarMap.get(fileName));
if (originalTime !=3D Long.parseLong(newTime))
{
// The timestamp on the jar has changed
jarsHaveChanged =3D true;
}
}
}
} catch (Exception e) {
e.printStackTrace();
this.stopListener();
}
return jarsHaveChanged
}
public void stopListener()
{
log.info("Stopping the RC Scheduler Application");
this.runListener =3D false;
// Stop any active threads
stopThreads();
}
private void restartScheduler()
{
log.info("Restart of the Scheduler was requested.");
stopListener();
// Go ahead and restart the jvm.
WrapperManager.restart();
}
-----Original Message-----
From: wra...@li...
[mailto:wra...@li...]On Behalf Of Subramani,
GnanaShekar (GE Healthcare, non-ge)
Sent: Friday, February 25, 2005 10:38 AM
To: wra...@li...
Subject: RE: [Wrapper-user] On Demand Restarts
Hi,
I am running Jboss on unix. Erik, what you have said, is exactly what I =
need. I am new to the Java Service Wrapper. I went through the list of =
wrapper properties, but nothing seemed to be of use for my purpose. =
Would appreciate if you list the steps you have taken to accomplish =
this.=20
Thanks & Regards,
-GnanaShekar-=20
-----Original Message-----
From: wra...@li...
[mailto:wra...@li...]On Behalf Of Love, Erik
Sent: Friday, February 25, 2005 8:46 AM
To: wra...@li...
Subject: RE: [Wrapper-user] On Demand Restarts
Are you wanting to restart it on a scheduled basis or "on change"? One =
of my wrapper-based apps gets a list of jars from a directory, including =
date/time and filesize information, and when any of those changes (or a =
new one is added), it automatically tells all of the spawned threads =
that it needs to restart, waits for them to restart and then calls the =
wrapper method to restart the jvm. It works very well.
The whole key to mine is that the main wrapper application is just a =
management thread. It sits idle for a pre-determined time (example 2 =
minutes) and then checks to see if it needs to do anything such as =
launch a subprocess through an exec() command or spawn a thread.
-----Original Message-----
From: wra...@li...
[mailto:wra...@li...]On Behalf Of Mattias
Ternert
Sent: Friday, February 25, 2005 4:13 AM
To: wra...@li...
Subject: SV: [Wrapper-user] On Demand Restarts
If you are using windows you can schedule your services to be restarted. =
Check that the services Task Scheduler is started, you can then schedule =
your services to be restarted by opening a dos-window and use the =
commands "at" end "net start "<service name>" "net stop "<service =
name>".
//Mattias
-----Ursprungligt meddelande-----
Fr=E5n: wra...@li...
[mailto:wra...@li...]F=F6r Subramani,
GnanaShekar (GE Healthcare, non-ge)
Skickat: den 24 februari 2005 17:31
Till: wra...@li...
=C4mne: [Wrapper-user] On Demand Restarts
Hi,
I have used integration method1 for JSW(Java Service Wrapper) to be able =
to start JBoss. =20
I want JBoss to be restarted automatically as and when there are changes =
made for its configuration files at ${JBoss_Home}/server/default/conf . =
This is the main purpose, I am using JSW for JBoss. I don't know what =
to do next. Please guide.
Thanks & Regards,
-GnanaShekar-
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id=14396&op=3Dick
_______________________________________________
Wrapper-user mailing list
Wra...@li...
https://lists.sourceforge.net/lists/listinfo/wrapper-user
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id=14396&op=3Dick
_______________________________________________
Wrapper-user mailing list
Wra...@li...
https://lists.sourceforge.net/lists/listinfo/wrapper-user
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id=14396&op=3Dclick
_______________________________________________
Wrapper-user mailing list
Wra...@li...
https://lists.sourceforge.net/lists/listinfo/wrapper-user
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id=14396&op=3Dick
_______________________________________________
Wrapper-user mailing list
Wra...@li...
https://lists.sourceforge.net/lists/listinfo/wrapper-user
|