1
2
3
4
5
6
7
8
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) {
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) {
79 logger.error("System problem in reportStatusChange" + endpoint, t);
80 }
81 }
82 }
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108