View Javadoc

1   /*$Id: AbstractProgressListener.java,v 1.2 2004/07/26 12:07:38 nw Exp $
2    * Created on 19-Jul-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.applications.manager.observer;
12  
13  import org.astrogrid.applications.Application;
14  import org.astrogrid.applications.Status;
15  import org.astrogrid.applications.beans.v1.cea.castor.MessageType;
16  
17  import org.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  
20  import java.util.Observable;
21  import java.util.Observer;
22  
23  /*** An abstract base class for things that want to listen to the progress of an application execution.
24   * @author Noel Winstanley nw@jb.man.ac.uk 19-Jul-2004
25   *
26   */
27  public abstract class AbstractProgressListener implements Observer {
28      /***
29       * Commons Logger for this class
30       */
31      private static final Log logger = LogFactory.getLog(AbstractProgressListener.class);
32  
33      /*** Construct a new AbstractProgressListener
34       * 
35       */
36      public AbstractProgressListener() {
37          super();
38      }
39      /***
40       * @see java.util.Observer#update(java.util.Observable, java.lang.Object)
41       */
42      public final void update(Observable o, Object arg) {
43          Application app = (Application)o;
44          if (arg instanceof Status) {
45              reportStatusChange(app,(Status)arg);
46          } else if (arg instanceof MessageType) {
47              reportMessage(app,(MessageType)arg);
48              
49          } else {
50              logger.warn("Unknown object in update notification " + arg.getClass().getName() + " " + arg.toString());
51          }
52      }
53      /*** subclasses to implement this.
54       * called when the listener encounters a message from the application.
55       * @param app the applicaitoni emitting the mesage
56       * @param type the message the application emitted - usually  an informative message
57       */
58      protected abstract void reportMessage(Application app, MessageType type);    
59      /*** subclasses to implement this.
60       * called when the listener encounters a status change to the application
61       * @param app the application who's state has changed.
62       * @param status the new status of the application.
63       */
64      protected abstract void reportStatusChange(Application app, Status status);
65      
66  }
67  
68  
69  /* 
70  $Log: AbstractProgressListener.java,v $
71  Revision 1.2  2004/07/26 12:07:38  nw
72  renamed indirect package to protocol,
73  renamed classes and methods within protocol package
74  javadocs
75  
76  Revision 1.1  2004/07/20 02:03:08  nw
77  added abstract listener classes
78   
79  */