jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ajaqu...@apache.org
Subject svn commit: r907445 - in /incubator/jspwiki/trunk/src/java/org/apache/wiki: ./ content/ plugin/ rss/ search/ ui/admin/beans/ util/
Date Sun, 07 Feb 2010 16:46:58 GMT
Author: ajaquith
Date: Sun Feb  7 16:46:57 2010
New Revision: 907445

URL: http://svn.apache.org/viewvc?rev=907445&view=rev
Log:
Refactored WikiBackgroundThread to operate as listeners for JMX timer events. Because they
are no longer true threads, they don't keep chewing up heap if context shutdown for some reason
isn't normal.

Modified:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/InternalWikiException.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSThread.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WatchDog.java
    incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WikiBackgroundThread.java

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/InternalWikiException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/InternalWikiException.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/InternalWikiException.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/InternalWikiException.java Sun Feb  7
16:46:57 2010
@@ -34,10 +34,21 @@
     /**
      *  Create a new InternalWikiException.
      *
-     *  @param msg The Exception message.
+     *  @param msg the Exception message.
      */
     public InternalWikiException( String msg )
     {
         super( msg );
     }
+
+    /**
+     *  Create a new InternalWikiException.
+     *
+     *  @param msg the Exception message.
+     *  @param t the cause of the Exception
+     */
+    public InternalWikiException( String msg, Throwable t )
+    {
+        super( msg, t );
+    }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/ContentManager.java Sun Feb 
7 16:46:57 2010
@@ -1192,7 +1192,7 @@
         public LockReaper( WikiEngine engine )
         {
             super( engine, 60 );
-            setName("JSPWiki Lock Reaper");
+            setName("Lock Reaper");
         }
 
         public void backgroundTask() throws Exception

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/PageViewPlugin.java Sun Feb  7
16:46:57 2010
@@ -190,7 +190,7 @@
         private boolean m_dirty;
 
         /** The page count storage background thread. */
-        private Thread m_pageCountSaveThread;
+        private WikiBackgroundThread m_pageCountSaveThread;
 
         /** The work directory. */
         private String m_workDir ;
@@ -677,19 +677,6 @@
                 }
             }
         }
-
-        /**
-         * Is the given thread still current?
-         * 
-         * @return boolean <code>true</code> iff the thread is still the current
-         *         background thread.
-         * @param thrd
-         */
-        private synchronized boolean isRunning( Thread thrd )
-        {
-            return m_initialized && thrd == m_pageCountSaveThread;
-        }
-
     }
 
     /**
@@ -783,15 +770,13 @@
          */
         public CounterSaveThread( WikiEngine engine, int interval, PageViewManager pageViewManager
)
         {
-
             super( engine, interval );
-
             if( pageViewManager == null )
             {
                 throw new IllegalArgumentException( "Manager cannot be null" );
             }
-
             m_manager = pageViewManager;
+            setName( "Counter Saver" );
         }
 
         /**
@@ -800,10 +785,7 @@
         public void backgroundTask()
         {
 
-            if( m_manager.isRunning( this ) )
-            {
-                m_manager.storeCounters();
-            }
+            m_manager.storeCounters();
         }
     }
 }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSThread.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSThread.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSThread.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/rss/RSSThread.java Sun Feb  7 16:46:57
2010
@@ -68,7 +68,7 @@
         m_generator = engine.getRSSGenerator();
         m_rssFile = rssFile;
         m_rssInterval = rssInterval;
-        setName("JSPWiki RSS Generator");
+        setName("RSS Generator");
         log.debug( "RSS file will be at "+m_rssFile.getAbsolutePath() );
         log.debug( "RSS refresh interval (seconds): "+m_rssInterval );
     }

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/search/LuceneSearchProvider.java Sun
Feb  7 16:46:57 2010
@@ -685,7 +685,7 @@
      */
     private static final class LuceneUpdater extends WikiBackgroundThread
     {
-        protected static final int INDEX_DELAY    = 5;
+        protected static final int INDEX_DELAY   = 15;
         protected static final int INITIAL_DELAY = 60;
         private final LuceneSearchProvider m_provider;
 
@@ -698,7 +698,7 @@
         {
             super( engine, indexDelay );
             m_provider = provider;
-            setName("JSPWiki Lucene Indexer");
+            setName("Lucene Indexer");
         }
 
         public void startupTask() throws Exception

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java
(original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java
Sun Feb  7 16:46:57 2010
@@ -88,8 +88,7 @@
                 public void startupTask() throws Exception
                 {
                     super.startupTask();
-
-                    setName("Reindexer started");
+                    setName("Reindexer");
                 }
 
                 public void backgroundTask() throws Exception

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WatchDog.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WatchDog.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WatchDog.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WatchDog.java Sun Feb  7 16:46:57
2010
@@ -388,7 +388,7 @@
         public WatchDogThread( WikiEngine engine )
         {
             super(engine, CHECK_INTERVAL);
-            setName("WatchDog for '"+engine.getApplicationName()+"'");
+            setName("WatchDog");
         }
 
         public void startupTask()

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WikiBackgroundThread.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WikiBackgroundThread.java?rev=907445&r1=907444&r2=907445&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WikiBackgroundThread.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/util/WikiBackgroundThread.java Sun Feb
 7 16:46:57 2010
@@ -20,183 +20,402 @@
  */
 package org.apache.wiki.util;
 
+import java.lang.management.ManagementFactory;
+import java.lang.ref.WeakReference;
+import java.util.Date;
+
+import javax.management.*;
+import javax.management.timer.Timer;
+import javax.management.timer.TimerNotification;
+
 import org.apache.wiki.InternalWikiException;
+import org.apache.wiki.Release;
 import org.apache.wiki.WikiEngine;
 import org.apache.wiki.event.WikiEngineEvent;
 import org.apache.wiki.event.WikiEvent;
 import org.apache.wiki.event.WikiEventListener;
+import org.apache.wiki.log.Logger;
+import org.apache.wiki.log.LoggerFactory;
 
 /**
- * Abstract Thread subclass that operates in the background;
- * when it detects the {@link WikiEngineEvent#SHUTDOWN} event,
- * it terminates itself. Subclasses of this method need only
- * implement the method {@link #backgroundTask()}, instead of
- * the normal {@link Thread#run()}, and provide a constructor that
- * passes the WikiEngine and sleep interval. This class is
- * thread-safe.
+ * Abstract background class that responds to JMX timer events for a particular
+ * WikiEngine; when it detects the {@link WikiEngineEvent#SHUTDOWN} event, it
+ * removes itself from the timer's listener list. Subclasses of this method need
+ * only implement the method {@link #backgroundTask()}, and provide a
+ * constructor that passes the WikiEngine and sleep interval to this superclass
+ * constructor. This class is <em>not</em> thread-safe.
  */
-public abstract class WikiBackgroundThread extends Thread implements WikiEventListener
+public abstract class WikiBackgroundThread implements WikiEventListener
 {
-    private volatile boolean m_killMe = false;
-    private final WikiEngine m_engine;
-    private final int m_interval;
-    private static final long POLLING_INTERVAL = 1000L;
+    public static class TimerListener implements NotificationListener
+    {
+        private final int m_timerId;
+
+        private final WikiBackgroundThread m_task;
+
+        TimerListener( WikiBackgroundThread task, int timerId )
+        {
+            m_timerId = timerId;
+            m_task = task;
+        }
+
+        public void handleNotification( Notification notification, Object handback )
+        {
+            if( ((TimerNotification) notification).getNotificationID() == m_timerId )
+            {
+                m_task.doBackgroundTask();
+            }
+        }
+    }
+
+    /**
+     * Registers and starts the wiki-wide JMX timer.
+     * @param engine the WikiEngine
+     */
+    public static final ObjectName registerTimer( WikiEngine engine )
+    {
+        try
+        {
+            ObjectName timer = getTimer( engine );
+            MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+            if( !server.isRegistered( timer ) )
+            {
+                server.createMBean( "javax.management.timer.Timer", timer );
+                server.invoke( timer, "start", new Object[] {}, new String[] {} );
+            }
+            return timer;
+        }
+        catch( JMException e )
+        {
+            e.printStackTrace();
+            throw new InternalWikiException( "Could not register JMX timer: " + e.getMessage(),
e );
+        }
+    }
+
+    /**
+     * Stops and unregisters the wiki-wide JMX timer.
+     * @param engine the WikiEngine
+     */
+    public static final void unregisterTimer( WikiEngine engine )
+    {
+        try
+        {
+            // Stop the timer and unregister it
+            MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+            ObjectName timer = getTimer( engine ); 
+            server.invoke( timer, "stop", new Object[] {}, new String[] {} );
+            server.unregisterMBean( timer );
+        }
+        catch( JMException e )
+        {
+            e.printStackTrace();
+            throw new InternalWikiException( "Could not unregister JMX timer: " + e.getMessage(),
e );
+        }
+    }
+
+    private static ObjectName getTimer( WikiEngine engine ) throws JMException
+    {
+        return new ObjectName( Release.APPNAME + ":wiki=" + engine.getApplicationName() +
",component=timer,name=Timer service" );
+    }
+
+    private final Logger m_log;
+
+    /**
+     * Method signature parameters for
+     * {@link javax.management.timer.Timer#addNotification(String, String, Object, Date,
long)}.
+     */
+    private static final String[] ADD_NOTIFICATION_SIGNATURE = new String[] { String.class.getName(),
String.class.getName(),
+                                                                             Object.class.getName(),
Date.class.getName(), "long" };
+
+    /**
+     * Method signature parameters for
+     * {@link javax.management.timer.Timer#removeNotification(Integer)}.
+     */
+    private static final String[] REMOVE_NOTIFICATION_SIGNATURE = new String[] { Integer.class.getName()
};
     
     /**
-     * Constructs a new instance of this background thread with 
-     * a specified sleep interval, and adds the new instance to the 
-     * wiki engine's event listeners.
+     * Method signature parameters for
+     * {@link javax.management.MBeanServer#unregisterMBean(ObjectName)}.
+     */
+    private static final String[] UNREGISTER_TIMER_SIGNATURE = new String[] { ObjectName.class.getName()
};
+
+    /**
+     * Returns the MBeanServer used to add notifications.
+     * 
+     * @throws JMException if the Timer cannot be retrieved, created or returned
+     */
+    private static MBeanServer getMBeanServer() throws JMException
+    {
+        // Get the platform MBeanServer and ObjectName
+        return ManagementFactory.getPlatformMBeanServer();
+    }
+
+    private final WeakReference<WikiEngine> m_engine;
+
+    private final ObjectName m_timer;
+
+    private TimerListener m_timerListener = null;
+
+    private String m_name;
+
+    private final int m_sleepInterval;
+
+    private int m_notificationId;
+
+    /**
+     * Constructs a new instance of this background thread with a specified
+     * sleep interval, and adds the new instance to the wiki engine's event
+     * listeners. It also lazily adds a {@link Timer} instance to the
+     * MBeanServer if one has not previously been registered. Each WikiEngine
+     * will have one Timer.
+     * 
      * @param engine the wiki engine
-     * @param sleepInterval the interval between invocations of
-     * the thread's {@link Thread#run()} method, in seconds
+     * @param sleepInterval the interval between invocations of the thread's
+     *            {@link Thread#run()} method, in seconds
+     * @throws InternalWikiException if the ObjectName for the timer object
+     *             cannot be created
      */
     public WikiBackgroundThread( WikiEngine engine, int sleepInterval )
     {
         super();
-        m_engine = engine;
-        m_interval = sleepInterval;
+        m_engine = new WeakReference<WikiEngine>( engine );
+        m_name = getClass().getName();
+        m_log = LoggerFactory.getLogger( this.getClass() );
+        m_notificationId = 0;
+        m_sleepInterval = sleepInterval;
+        m_timer = registerTimer( engine );
         engine.addWikiEventListener( this );
-        setDaemon( false );
-        
     }
-    
+
     /**
-     * Listens for {@link org.apache.wiki.event.WikiEngineEvent#SHUTDOWN}
-     * and, if detected, marks the thread for death.
+     * Listens for {@link org.apache.wiki.event.WikiEngineEvent#SHUTDOWN} and,
+     * if detected, removes the task from the JMX timer.
      * 
      * @param event {@inheritDoc}
      * @see org.apache.wiki.event.WikiEventListener#actionPerformed(org.apache.wiki.event.WikiEvent)
      */
     public final void actionPerformed( WikiEvent event )
     {
-        if ( event instanceof WikiEngineEvent )
+        if( event instanceof WikiEngineEvent )
         {
-            if ( ((WikiEngineEvent)event).getType() == WikiEngineEvent.SHUTDOWN )
+            if( ((WikiEngineEvent) event).getType() == WikiEngineEvent.SHUTDOWN )
             {
-                System.out.println( "Detected wiki engine shutdown: killing " + getName()
+ "." );
-                m_killMe = true;
+                shutdown();
             }
         }
     }
-    
+
     /**
-     * Abstract method that performs the actual work for this
-     * background thread; subclasses must implement this method.
+     * Abstract method that performs the actual work for this background thread;
+     * subclasses must implement this method.
      * 
      * @throws Exception Any exception can be thrown
      */
     public abstract void backgroundTask() throws Exception;
-    
+
     /**
-     * Returns the WikiEngine that created this background thread.
-     * @return the wiki engine
+     * Returns the WikiEngine that created this background thread. Note that it
+     * is possible that the garbage collector has already collected the
+     * WikiEngine reference, so callers must check for {@code null} return
+     * values.
+     * 
+     * @return the wiki engine, or {@code null} if no reference
      */
-    public WikiEngine getEngine()
+    public final WikiEngine getEngine()
     {
-        return m_engine;
+        return m_engine.get();
     }
-    
+
     /**
-     *  Requests the shutdown of this background thread.  Note that the shutdown
-     *  is not immediate.
-     *  
-     *  @since 2.4.92
-     *
+     * Returns the name of the background task.
+     * 
+     * @return the name
      */
-    public void shutdown()
+    public final String getName()
     {
-        m_killMe = true;
+        return m_name;
     }
-    
+
     /**
-     * Runs the background thread's {@link #backgroundTask()} method
-     * at the interval specified at construction.
-     * The thread will initially pause for a full sleep interval
-     * before starting, after which it will execute 
-     * {@link #startupTask()}. This method will cleanly 
-     * terminate the thread if it has previously 
-     * been marked as dead, before which it will execute
-     * {@link #shutdownTask()}. If any of the three methods
-     * return an exception, it will be re-thrown as a
-     * {@link org.apache.wiki.InternalWikiException}.
-     * @see java.lang.Thread#run()
-     */
-    public final void run() 
-    {
-        try 
-        {
-            // Perform the initial startup task
-            final String name = getName();
-            System.out.println( "Starting up background thread: " + name + ".");
-            startupTask();
-            
-            // Perform the background task; check every
-            // second for thread death
-            while( !m_killMe )
+     * Sets the name of the background task.
+     * 
+     * @param name the name
+     */
+    public final void setName( String name )
+    {
+        m_name = name;
+    }
+
+    /**
+     * Requests the shutdown of this background thread. Note that the shutdown
+     * is not immediate.
+     * 
+     * @since 2.4.92
+     */
+    public final void shutdown()
+    {
+        m_log.info( "Stopping " + m_name + "." );
+        try
+        {
+            try
             {
-                // Perform the background task
-                // log.debug( "Running background task: " + name + "." );
-                backgroundTask();
-                
-                // Sleep for the interval we're supposed to, but
-                // wake up every POLLING_INTERVAL to see if thread should die
-                boolean interrupted = false;
-                try
-                {
-                    for( int i = 0; i < m_interval; i++ )
-                    {
-                        Thread.sleep( POLLING_INTERVAL );
-                        if( m_killMe )
-                        {
-                            interrupted = true;
-                            System.out.println( "Interrupted background thread: " + name
+ "." );
-                            break;
-                        }
-                    }
-                    if( interrupted )
-                    {
-                        break;
-                    }
-                }
-                catch( Throwable t ) 
+                removeJMXListener();
+                if ( m_engine.get() != null )
                 {
-                    System.err.println( "Background thread error: (stack trace follows)"
);
-                    t.printStackTrace();
+                    shutdownTask();
                 }
             }
-            
-            // Perform the shutdown task
-            shutdownTask();
+            catch( Exception e )
+            {
+                e.printStackTrace();
+                throw new InternalWikiException( "Could not stop " + m_name + "!", e );
+            }
         }
         catch( Throwable t )
         {
-            System.err.println( "Background thread error: (stack trace follows)" );
+            m_log.error( "Background task shutdown error: " + t.getMessage() );
             t.printStackTrace();
             throw new InternalWikiException( t.getMessage() );
         }
     }
-    
+
     /**
-     * Executes a task after shutdown signal was detected.
-     * By default, this method does nothing; override it 
-     * to implement custom functionality.
+     * Executes a task after shutdown signal was detected. By default, this
+     * method does nothing; override it to implement custom functionality.
      * 
      * @throws Exception Any exception can be thrown.
      */
     public void shutdownTask() throws Exception
     {
     }
-    
+
     /**
-     * Executes a task just after the thread's {@link Thread#run()}
-     * method starts, but before the {@link #backgroundTask()}
-     * task executes. By default, this method does nothing; 
-     * override it to implement custom functionality.
+     * Causes this background task to begin execution by calling
+     * {@link #startupTask()}. After the startup task runs,
+     * the background task will be scheduled to start one full
+     * sleep interval later.
+     */
+    public final void start()
+    {
+        // Add a notification timer and start the task
+        m_log.info( "Starting " + getName() + "." );
+        try
+        {
+            if ( m_engine.get() != null )
+            {
+                startupTask();
+                addJMXListener();
+            }
+        }
+        catch( JMException e )
+        {
+            e.printStackTrace();
+            throw new InternalWikiException( "Could not add JMX listener for " + m_name +
"!", e );
+        }
+        catch( Exception e )
+        {
+            e.printStackTrace();
+            throw new InternalWikiException( "Could not start " + m_name + "!", e );
+        }
+    }
+
+    /**
+     * Executes a task just after the thread's {@link Thread#run()} method
+     * starts, but before the {@link #backgroundTask()} task executes. By
+     * default, this method does nothing; override it to implement custom
+     * functionality.
      * 
      * @throws Exception Any exception can be thrown.
      */
     public void startupTask() throws Exception
     {
     }
-    
+
+    /**
+     * Adds a notification and listener to the Timer MBean.
+     * 
+     * @throws JMException if either of these things can't be done for any
+     *             reason
+     */
+    private final void addJMXListener() throws JMException
+    {
+        MBeanServer server = getMBeanServer();
+
+        // Add notification
+        long interval = Timer.ONE_SECOND * m_sleepInterval;
+        Date startTime = new Date( new Date().getTime() + interval );
+        Object[] timerArgs = new Object[] { this.getClass().getName(), "Timed task", null,
startTime, interval };
+        m_notificationId = (Integer) server.invoke( m_timer, "addNotification", timerArgs,
ADD_NOTIFICATION_SIGNATURE );
+
+        // Add the listener
+        m_timerListener = new TimerListener( this, m_notificationId );
+        server.addNotificationListener( m_timer, m_timerListener, null, null );
+
+        // Start the timer
+        server.invoke( m_timer, "start", new Object[] {}, new String[] {} );
+    }
+
+    /*
+     * Removes the notification and listener from the Timer MBean.
+     * @throws JMException if either of these things can't be done for any
+     * reason
+     */
+    private final void removeJMXListener() throws JMException
+    {
+        try
+        {
+            MBeanServer server = getMBeanServer();
+
+            // Remove the listener
+            server.removeNotificationListener( getTimer( m_engine.get() ), m_timerListener
);
+
+            // Remove notification
+            Object[] args = new Object[] { m_notificationId };
+            server.invoke( m_timer, "removeNotification", args, REMOVE_NOTIFICATION_SIGNATURE
);
+        }
+        catch( JMException e )
+        {
+            if( e.getCause() instanceof InstanceNotFoundException )
+            {
+                // Adding the listener failed the first time, so it's ok to eat
+                // this exception
+            }
+            else
+            {
+                throw e;
+            }
+        }
+    }
+
+    /**
+     * Called by {@link TimerListener#handleNotification(Notification, Object)},
+     * this method wraps {@link #backgroundTask()} and checks to see if it runs
+     * correctly. If it throws an Exception of any kind, {@link #shutdown()} is
+     * executed to remove the listener and shut down the task.
+     */
+    protected final void doBackgroundTask()
+    {
+        try
+        {
+            if ( m_engine.get() != null )
+            {
+                m_log.info( "Running " + m_name + "." );
+                backgroundTask();
+            }
+        }
+        catch( Exception e )
+        {
+            e.printStackTrace();
+            try
+            {
+                m_log.error( "Could not run " + m_name + "! Shutting it down." );
+                shutdown();
+            }
+            catch( Exception e2 )
+            {
+                m_log.error( "Could not shut down " + m_name + "!" );
+                e2.printStackTrace();
+            }
+        }
+    }
 }



Mime
View raw message