View Javadoc

1   /*$Id: Service.java,v 1.13 2004/11/22 18:26:54 clq2 Exp $
2    * Created on 27-Jan-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.scripting;
12  
13  import org.astrogrid.applications.delegate.DelegateFactory;
14  import org.astrogrid.datacenter.delegate.DatacenterDelegateFactory;
15  import org.astrogrid.jes.delegate.JesDelegateFactory;
16  import org.astrogrid.registry.client.RegistryDelegateFactory;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  import java.io.IOException;
22  import java.net.URL;
23  
24  import javax.xml.rpc.ServiceException;
25  
26  
27  /***
28   * Data object representing a service 
29   * @deprecated don't think things are going to work out this way any more. stay clear. unstable code.
30   * @author Noel Winstanley nw@jb.man.ac.uk 27-Jan-2004
31   *
32   */ 
33  public class Service {
34      /***
35       * Commons Logger for this class
36       */
37      private static final Log logger = LogFactory.getLog(Service.class);
38      
39  
40     public static final String DATACENTER_SERVICE = "datacenter";
41     public static final String REGISTRY_SERVICE = "registry";
42     public static final String REGISTRYADMIN_SERVICE = "registryadmin";
43     public static final String CEA_SERVICE = "cea";
44     public static final String JOBCONTROL_SERVICE = "jobcontrol";
45     public static final String JOBMONITOR_SERVICE = "jobmonitor";
46     public static final String UNNKOWN_SERVICE = "unknown";
47     
48     
49     protected String endpoint;
50     protected String type;
51     protected String description;
52     
53     /*** instantate a suitable delegate object for this service
54      * 
55      * @return a delegate object, depending on the {@ #type} atttibute of this service:
56      * <ul>
57      * <li>datacenter - return a {@link org.astrogrid.datacenter.delegate.QuerySearcher}
58      * <li>registry - return a {@link org.astrogrid.registry.client.query.RegistryService}
59      * <li>registryadmin - return a {@link org.astrogrid.registry.client.admin.RegistryAdminService}
60      * <li>application - return a {@link org.astrogrid.applications.delegate.CommonExecutionConnectorClient}
61      * <li>jobcontrol - return a {@link org.astrogrid.jes.delegate.JobController}
62      * <li>jobmonitor - return a {@link org.astrogrid.jes.delegate.JobMonitor}
63      * </ul>
64      * @throws ServiceException
65      * @throws IOException
66      */
67     public Object createDelegate() throws  ServiceException, IOException {
68        if (DATACENTER_SERVICE.equals(type)) {
69            logger.info("Creating datacenter delegate");
70           return DatacenterDelegateFactory.makeQuerySearcher(endpoint);
71        } 
72        if (REGISTRY_SERVICE.equals(type)) {
73            logger.info("Creating registry delegate");
74            return RegistryDelegateFactory.createQuery(new URL(endpoint));
75        }
76        if (REGISTRYADMIN_SERVICE.equals(type)) {
77            logger.info("Creating registry admin delegate");
78            return RegistryDelegateFactory.createAdmin(new URL(endpoint));
79        }
80        if(CEA_SERVICE.equals(type)) {
81            logger.info("Creating cea delegate");
82           return DelegateFactory.createDelegate(endpoint);
83        }
84        if (JOBCONTROL_SERVICE.equals(type)) {
85            logger.info("Creating job controller delegate");
86           return JesDelegateFactory.createJobController(endpoint);
87        }
88        if (JOBMONITOR_SERVICE.equals(type)) {
89            logger.info("Creating job monitor delegate");
90           return JesDelegateFactory.createJobMonitor(endpoint);
91        }
92        logger.error("Unknown service type - cannot create delegate for " + this.toString());
93        throw new IllegalStateException("Unknown service type - cannot create for " + this.toString());
94     }
95     
96     /*** Get the dsescription of this service
97      * @return
98      */
99     public String getDescription() {
100       return description;
101    }
102 
103    /*** Access the endpoint of this service
104     * @return
105     */
106    public String getEndpoint() {
107       return endpoint;
108    }
109  
110    /*** Access the type of this service - one of the constants defined in this class 
111     * @return
112     */
113    public String getType() {
114       return type;
115    }
116 
117    /*** Set the description of this service
118     * @param string
119     */
120    public void setDescription(String string) {
121       description = string.trim();
122    }
123 
124    /*** Set the endpoint of this service
125     * @param string
126     */
127    public void setEndpoint(String string) {
128       endpoint = string.trim();
129    }
130 
131    /***Set the type of this service
132     * @param string
133     */
134    public void setType(String string) {
135       type = string.trim().toLowerCase();
136       
137    }
138 
139     /***
140      * Override hashCode.
141      *
142      * @return the Objects hashcode.
143      */
144     public int hashCode() {
145         int hashCode = 1;
146         hashCode = 31 * hashCode + (endpoint == null ? 0 : endpoint.hashCode());
147         hashCode = 31 * hashCode + (type == null ? 0 : type.hashCode());
148         hashCode = 31
149             * hashCode
150             + (description == null ? 0 : description.hashCode());
151         return hashCode;
152     }
153     public String toString() {
154         StringBuffer buffer = new StringBuffer();
155         buffer.append("[Service:");
156         buffer.append(" endpoint: ");
157         buffer.append(endpoint);
158         buffer.append(" type: ");
159         buffer.append(type);
160         buffer.append(" description: ");
161         buffer.append(description);
162         buffer.append("]");
163         return buffer.toString();
164     }
165     /***
166      * Returns <code>true</code> if this <code>Service</code> is the same as the o argument.
167      *
168      * @return <code>true</code> if this <code>Service</code> is the same as the o argument.
169      */
170     public boolean equals(Object o) {
171         if (this == o) {
172             return true;
173         }
174         if (o == null) {
175             return false;
176         }
177         if (o.getClass() != getClass()) {
178             return false;
179         }
180         Service castedObj = (Service) o;
181         return ((this.endpoint == null
182             ? castedObj.endpoint == null
183             : this.endpoint.equals(castedObj.endpoint))
184             && (this.type == null ? castedObj.type == null : this.type
185                 .equals(castedObj.type)) && (this.description == null
186             ? castedObj.description == null
187             : this.description.equals(castedObj.description)));
188     }
189 }
190 
191 /* 
192 $Log: Service.java,v $
193 Revision 1.13  2004/11/22 18:26:54  clq2
194 scripting-nww-715
195 
196 Revision 1.12.68.1  2004/11/22 15:54:51  nw
197 deprecated existing scripting interface (which includes service lists).
198 produced new scripting interface, with more helpler objects.
199 
200 Revision 1.12  2004/08/09 11:28:17  nw
201 improvied behaviour when no service list is found.
202 tidied imports.
203 
204 Revision 1.11  2004/08/09 09:10:38  nw
205 updated list of service types (renamed applications to cea)
206 improved toString()
207 added logging
208 
209 Revision 1.10  2004/07/01 11:36:25  nw
210 fixed for removal of myspace delegate
211 
212 Revision 1.9  2004/05/07 15:33:50  pah
213 added egistryAdmin as a service type
214 
215 Revision 1.8  2004/04/15 11:22:47  nw
216 added support for registry delegate.
217 
218 Revision 1.7  2004/03/16 13:57:41  nw
219 added in registry delegate
220 
221 Revision 1.6  2004/03/14 23:11:32  nw
222 commented out code that used methods that have dissapeared from datacenter and applications delegate jars
223 
224 Revision 1.5  2004/03/05 16:27:28  nw
225 updated to new jes delegates
226 
227 Revision 1.4  2004/02/27 00:51:01  nw
228 updated to use new jes delegates
229 
230 Revision 1.3  2004/02/01 00:38:24  nw
231 added two other kinds of job delegate
232 
233 Revision 1.2  2004/01/29 10:41:40  nw
234 extended scripting model with helper functions,
235 imporove javadoc
236 
237 Revision 1.1  2004/01/28 17:19:58  nw
238 first check in of scripting project
239  
240 */