View Javadoc

1   /*$Id: EndpointsFromConfig.java,v 1.2 2004/07/05 18:34:13 nw Exp $
2    * Created on 07-Mar-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.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          // instead try
50          //Iterator i = AxisServer.getServer(new HashMap()).getConfig().getDeployedServices();
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              // oh well.
62          } catch (NullPointerException e) {
63              // oh well
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  $Log: EndpointsFromConfig.java,v $
93  Revision 1.2  2004/07/05 18:34:13  nw
94  tweaked default value to be sensible
95  
96  Revision 1.1  2004/07/01 21:15:00  nw
97  added results-listener interface to jes
98  
99  Revision 1.6  2004/07/01 11:19:05  nw
100 updated interface with cea - part of cea componentization
101 
102 Revision 1.5  2004/03/17 00:26:09  nw
103 attempt at determining monitor endpoint by querying axis engine
104 
105 Revision 1.4  2004/03/15 23:45:07  nw
106 improved javadoc
107 
108 Revision 1.3  2004/03/15 01:30:06  nw
109 factored component descriptor out into separate package
110 
111 Revision 1.2  2004/03/07 21:04:38  nw
112 merged in nww-itn05-pico - adds picocontainer
113 
114 Revision 1.1.2.1  2004/03/07 20:39:26  nw
115 added implementation of a self-configuring production set of component
116  
117 */