avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/scheduler TriggerFailureListener.java TimeScheduler.java
Date Sat, 05 Oct 2002 00:49:09 GMT
hammant     2002/10/04 17:49:08

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/scheduler
                        DefaultTimeScheduler.java
               src/java/org/apache/avalon/cornerstone/services/scheduler
                        TimeScheduler.java
  Added:       src/java/org/apache/avalon/cornerstone/services/scheduler
                        TriggerFailureListener.java
  Log:
  Add callback from failed triggered events.  OutOfMemoryError FWIW should not just journal
to log as a warning and then carry on.
  
  Revision  Changes    Path
  1.24      +44 -2     jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/scheduler/DefaultTimeScheduler.java
  
  Index: DefaultTimeScheduler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/scheduler/DefaultTimeScheduler.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- DefaultTimeScheduler.java	18 Aug 2002 02:54:42 -0000	1.23
  +++ DefaultTimeScheduler.java	5 Oct 2002 00:49:08 -0000	1.24
  @@ -9,9 +9,12 @@
   
   import java.util.Hashtable;
   import java.util.NoSuchElementException;
  +import java.util.ArrayList;
  +
   import org.apache.avalon.cornerstone.services.scheduler.Target;
   import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
   import org.apache.avalon.cornerstone.services.scheduler.TimeTrigger;
  +import org.apache.avalon.cornerstone.services.scheduler.TriggerFailureListener;
   import org.apache.avalon.cornerstone.services.threads.ThreadManager;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.activity.Startable;
  @@ -28,6 +31,7 @@
    *
    * @author <a href="mailto:peter at apache.org">Peter Donald</a>
    * @author <a href="mailto:ram.chidambaram@telus.com">Ram Chidambaram</a>
  + * @author Paul Hammant
    */
   public class DefaultTimeScheduler
       extends AbstractLogEnabled
  @@ -38,6 +42,7 @@
           new SynchronizedPriorityQueue( new BinaryHeap() );
       private ThreadManager m_threadManager;
       private boolean m_running;
  +    private ArrayList m_triggerFailureListeners = new ArrayList();
   
       /**
        * @phoenix:dependency name="org.apache.avalon.cornerstone.services.threads.ThreadManager"
  @@ -233,10 +238,18 @@
           {
               entry.getTarget().targetTriggered( entry.getName() );
           }
  -        catch( final Throwable t )
  +        catch( final Error e)
           {
               final String message = "Error occured executing trigger " + entry.getName();
  -            getLogger().warn( message, t );
  +            getLogger().error( message, e );
  +            notifyFailedTriggers(e);
  +
  +        }
  +        catch( final Exception e )
  +        {
  +            final String message = "Exception occured executing trigger " + entry.getName();
  +            getLogger().warn( message, e );
  +            notifyFailedTriggers(e);
           }
       }
   
  @@ -351,5 +364,34 @@
   
           return entry;
       }
  +
  +    /**
  +     * Add a trigger failure listener
  +     * @param listener The listener
  +     */
  +    public void addTriggerFailureListener(TriggerFailureListener listener)
  +    {
  +        m_triggerFailureListeners.add(listener);
  +    }
  +
  +    /**
  +     * Remove a trigger failure listener
  +     * @param listener The listener
  +     */
  +    public void removeTriggerFailureListener(TriggerFailureListener listener)
  +    {
  +        m_triggerFailureListeners.remove(listener);
  +    }
  +
  +    private void notifyFailedTriggers(Throwable t) {
  +        for (int i = 0; i < m_triggerFailureListeners.size(); i++)
  +        {
  +            TriggerFailureListener triggerFailureListener = (TriggerFailureListener) m_triggerFailureListeners.get(i);
  +            triggerFailureListener.triggerFailure(t);
  +        }
  +
  +    }
  +
  +
   }
   
  
  
  
  1.9       +13 -0     jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/scheduler/TimeScheduler.java
  
  Index: TimeScheduler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/scheduler/TimeScheduler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TimeScheduler.java	5 Aug 2002 14:12:14 -0000	1.8
  +++ TimeScheduler.java	5 Oct 2002 00:49:08 -0000	1.9
  @@ -45,4 +45,17 @@
        */
       void resetTrigger( String name )
           throws NoSuchElementException;
  +
  +    /**
  +     * Add a trigger failure listener
  +     * @param listener the listener
  +     */
  +    void addTriggerFailureListener(TriggerFailureListener listener);
  +
  +    /**
  +     * Remove a trigger failure listener
  +     * @param listener the listener
  +     */
  +    void removeTriggerFailureListener(TriggerFailureListener listener);
  +
   }
  
  
  
  1.1                  jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/scheduler/TriggerFailureListener.java
  
  Index: TriggerFailureListener.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.cornerstone.services.scheduler;
  
  /**
   * A callback mechanism for failures on triggering of targets.
   *
   * @author Paul Hammant
   */
  public interface TriggerFailureListener
  {
      void triggerFailure(Throwable throwable);
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message