|
From: Leif M. <le...@ta...> - 2005-02-27 04:19:21
|
I added feature request for the Wrapper to monitor a set of files for changes. Now that you mention it, this is something I would like to have as well and it should be fairly easy to implement on a lower level in the Wrapper code. https://sourceforge.net/tracker/index.php?func=detail&aid=1152738&group_id=39428&atid=425190 For now though. The code below is great but it probably more than he needs in that it requires you to implement your own WrapperListener implementation. He could simply start a thread someplace in his own application. The call to WrapperManager.restart() will work anywhere and does not need to be done in association with a custom WrapperListener. A fine detail, but as he is new to the Wrapper I wanted to point it out. Cheers, Leif Love, Erik wrote: >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 = 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 = > while (this.runListener) { > try { > // See if any of the jars have changed requiring a bounce > > 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 >= maxErrors) > { > log.error("Too many errors...stopping the Scheduler Application"); > statusCode = -1; > break; > } > } > } > stopListener(); > WrapperManager.stop(statusCode); > } > > private boolean haveJarsChanged() throws Exception > { > boolean jarsHaveChanged = false; > try { > long size = watchedJarMap.size(); > > HashMap tempMap = new HashMap(); > File directory = new File(jarPath); > String files[] = directory.list(); > for (int i=0;i<files.length;i++) { > String fileName = files[i]; > tempMap.put(fileName, ""+getLastModified(jarPath + "/" + fileName)); > } > > if (size == 0) > { > // This is the first time in so set the baseline > watchedJarMap = tempMap; > jarsHaveChanged = false; > } else if (size != tempMap.size()) { > // Jars have been added or deleted. > jarsHaveChanged = true; > } else { > Iterator iterator = watchedJarMap.keySet().iterator(); > while (iterator.hasNext()) > { > String fileName = (String)iterator.next(); > String newTime = (String)tempMap.get(fileName); > if (newTime == null) > { > // The jar no longer exists (have to check because the old jar count can still match new jar count) > jarsHaveChanged = true; > } > > long originalTime = Long.parseLong((String)watchedJarMap.get(fileName)); > if (originalTime != Long.parseLong(newTime)) > { > // The timestamp on the jar has changed > jarsHaveChanged = true; > } > } > } > } catch (Exception e) { > e.printStackTrace(); > this.stopListener(); > } > return jarsHaveChanged > } > > public void stopListener() > { > log.info("Stopping the RC Scheduler Application"); > this.runListener = 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. > >Thanks & Regards, >-GnanaShekar- > >-----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ån: wra...@li... >[mailto:wra...@li...]För Subramani, >GnanaShekar (GE Healthcare, non-ge) >Skickat: den 24 februari 2005 17:31 >Till: wra...@li... >Ämne: [Wrapper-user] On Demand Restarts > > >Hi, > >I have used integration method1 for JSW(Java Service Wrapper) to be able to start JBoss. >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_id396&op=ick >_______________________________________________ >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_id396&op=ick >_______________________________________________ >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_id396&op=click >_______________________________________________ >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_id396&op=ick >_______________________________________________ >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_id396&op=click >_______________________________________________ >Wrapper-user mailing list >Wra...@li... >https://lists.sourceforge.net/lists/listinfo/wrapper-user > > > |