1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.jes.component.production;
12
13 import org.astrogrid.component.descriptor.SimpleComponentDescriptor;
14 import org.astrogrid.config.Config;
15 import org.astrogrid.jes.jobscheduler.dispatcher.ApplicationControllerDispatcher.Endpoints;
16
17 import org.apache.axis.ConfigurationException;
18 import org.apache.axis.MessageContext;
19 import org.apache.axis.description.ServiceDesc;
20
21 import java.net.MalformedURLException;
22 import java.net.URI;
23 import java.net.URISyntaxException;
24 import java.net.URL;
25 import java.util.Iterator;
26
27 /*** Configuration object for {@link org.astrogrid.jes.jobscheduler.dispatcher.ApplicationControllerDispatcher}
28 * <p>
29 * looks in configuration for a key, otherwise guesses job monitor service by examing axis engine configuration.
30 * @todo which doesn't seem to work at the moment - need to fix
31 * @author Noel Winstanley nw@jb.man.ac.uk 07-Mar-2004
32 *
33 */
34 public class EndpointsFromConfig extends SimpleComponentDescriptor implements Endpoints {
35 /*** key to look in config for job monitor endpoint */
36 public static final String MONITOR_ENDPOINT_KEY = "jes.monitor.endpoint.url";
37 /*** key to look in config for results listener endpoint */
38 public static final String RESULTS_ENDPOINT_KEY = "jes.results.endpoint.url";
39
40 /*** absolute fallback endpoint - if no value specified in config, and we can't calculate value by querying axis message endpoint */
41 public static final String MONITOR_DEFAULT_ENDPOINT ="http://localhost:8080/jes/services/JobMonitorService" ;
42 public static final String RESULTS_DEFAULT_ENDPOINT = "http://localhost:8080/jes/services/ResultListener";
43
44 public EndpointsFromConfig(Config conf) throws MalformedURLException, URISyntaxException {
45 URL monitorURL = new URL(MONITOR_DEFAULT_ENDPOINT);
46 URL resultsURL = new URL(RESULTS_DEFAULT_ENDPOINT);
47 try {
48 Iterator i = MessageContext.getCurrentContext().getAxisEngine().getConfig().getDeployedServices();
49
50
51 while (i.hasNext()) {
52 ServiceDesc sDesc = (ServiceDesc)i.next();
53 if (sDesc.getName().equals("JobMonitorService") && sDesc.getEndpointURL() != null) {
54 monitorURL = new URL(sDesc.getEndpointURL());
55 }
56 if (sDesc.getName().equals("ResultsListenerService") && sDesc.getEndpointURL() != null) {
57 resultsURL = new URL(sDesc.getEndpointURL());
58 }
59 }
60 } catch (ConfigurationException e ) {
61
62 } catch (NullPointerException e) {
63
64 }
65
66 URL url = conf.getUrl(MONITOR_ENDPOINT_KEY,monitorURL);
67 finalMonitorEndpoint = new URI(url.toString());
68 url = conf.getUrl(RESULTS_ENDPOINT_KEY,resultsURL);
69 finalResultsEndpoint = new URI(url.toString());
70 name = "ApplicationControllerDispatcher - Monitor Endpoint configuration";
71 description = "Loads job-monitor endpoint (used by callback from application controller) from Config\n" +
72 "key :" + MONITOR_ENDPOINT_KEY+ " current value:" + finalMonitorEndpoint.toString()
73 + "\n key : "+ RESULTS_ENDPOINT_KEY + "current value:" + finalResultsEndpoint.toString();
74 }
75
76 protected final URI finalMonitorEndpoint;
77 protected final URI finalResultsEndpoint;
78
79 public URI monitorEndpoint() {
80 return finalMonitorEndpoint;
81 }
82 /***
83 * @see org.astrogrid.jes.jobscheduler.dispatcher.ApplicationControllerDispatcher.Endpoints#resultListenerEndpoint()
84 */
85 public URI resultListenerEndpoint() {
86 return finalResultsEndpoint;
87 }
88 }
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117