1
2
3
4
5
6
7
8
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240