View Javadoc

1   /*$Id: RemoteProgressListener.java,v 1.5 2004/07/26 12:07:38 nw Exp $
2    * Created on 17-Jun-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  import org.astrogrid.applications.beans.v1.cea.castor.types.LogLevel;
17  import org.astrogrid.common.bean.Castor2Axis;
18  import org.astrogrid.jes.delegate.JesDelegateException;
19  import org.astrogrid.jes.delegate.impl.JobMonitorDelegate;
20  import org.astrogrid.jes.types.v1.cea.axis.JobIdentifierType;
21  
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  
25  import java.net.URI;
26  
27  /*** A Progress Listener  that relays  state changes and other messages from an application back home to a
28   * 'jobMonitor' interface.
29   * @author Noel Winstanley nw@jb.man.ac.uk 17-Jun-2004
30   *
31   */
32  public class RemoteProgressListener extends AbstractProgressListener {
33      /***
34       * Commons Logger for this class
35       */
36      private static final Log logger = LogFactory.getLog(RemoteProgressListener.class);
37  
38      /*** Construct a new RemoteProgressListener
39       * @param endpoint the url endpoint for the service to relay to.
40       * 
41       */
42      public RemoteProgressListener(URI endpoint) {
43          super();
44          delegate = JobMonitorDelegate.buildDelegate(endpoint.toString());
45          this.endpoint = endpoint;
46      }
47      protected final JobMonitorDelegate delegate;
48      protected final URI endpoint;
49  
50      /*** relays a message back to the remote service.
51       * 
52       * any communication failure, logs a warning.
53       */
54      protected void reportMessage(Application app, MessageType message) {
55          try {
56              delegate.monitorJob(new JobIdentifierType( app.getJobStepID()),Castor2Axis.convert(message));
57          }
58          catch (JesDelegateException e) {
59              logger.warn("Could not communicate with remote client" + endpoint,e);
60          } catch (Throwable t) {// need to catch everything - otherwise I'm not sure what happens - think things get lost.
61          logger.error("System problem in reportMessage() " + endpoint, t);
62      }
63      }
64      /***Relays a status change back to the remote service
65       * 
66       * any communication failure, logs  a warning
67       */
68      protected void reportStatusChange(Application app, Status status) {
69          try {
70              MessageType message = app.createTemplateMessage();
71              message.setPhase(status.toExecutionPhase());
72              message.setLevel(LogLevel.INFO);
73              message.setContent("Application enters new phase");
74              delegate.monitorJob(new JobIdentifierType( app.getJobStepID()),Castor2Axis.convert(message));
75          }
76          catch (JesDelegateException e) {
77              logger.warn("Could not communicate with remote client" + endpoint,e);
78          } catch (Throwable t) {// need to catch everything - otherwise I'm not sure what happens - think things get lost.
79          logger.error("System problem in reportStatusChange" + endpoint, t);
80      }       
81      }
82  }
83  
84  
85  /* 
86  $Log: RemoteProgressListener.java,v $
87  Revision 1.5  2004/07/26 12:07:38  nw
88  renamed indirect package to protocol,
89  renamed classes and methods within protocol package
90  javadocs
91  
92  Revision 1.4  2004/07/20 02:03:08  nw
93  added abstract listener classes
94  
95  Revision 1.3  2004/07/02 09:11:13  nw
96  improved logging
97  
98  Revision 1.2  2004/07/01 11:16:22  nw
99  merged in branch
100 nww-itn06-componentization
101 
102 Revision 1.1.2.2  2004/07/01 01:42:47  nw
103 final version, before merge
104 
105 Revision 1.1.2.1  2004/06/17 09:21:23  nw
106 finished all major functionality additions to core
107  
108 */