]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.lib.detached/src/main/java/org/argeo/slc/lib/detached/DetachedAdminTask.java
ec1b1cfad74ac9435b425ad7aeb61ec3db114e7d
[gpl/argeo-slc.git] / runtime / org.argeo.slc.lib.detached / src / main / java / org / argeo / slc / lib / detached / DetachedAdminTask.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.lib.detached;
18
19 import java.util.Properties;
20 import java.util.UUID;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.argeo.slc.SlcException;
25 import org.argeo.slc.detached.DetachedAnswer;
26 import org.argeo.slc.detached.DetachedClient;
27 import org.argeo.slc.detached.DetachedRequest;
28
29 public class DetachedAdminTask implements Runnable {
30 private final static Log log = LogFactory.getLog(DetachedAdminTask.class);
31
32 private String action;
33 private DetachedClient client;
34 private Properties properties;
35
36 public void run() {
37 // Prepare and send request
38 DetachedRequest request = new DetachedRequest(UUID.randomUUID()
39 .toString());
40 request.setRef(action);
41
42 if (properties != null) {
43 request.setProperties(properties);
44 }
45
46 try {
47 client.sendRequest(request);
48 DetachedAnswer answer = client.receiveAnswer();
49 if (answer.getStatus() == DetachedAnswer.ERROR)
50 throw new SlcException("Error when executing request "
51 + answer.getUuid() + ": " + answer.getLog());
52 else
53 log.info("Admin answer: " + answer.getLog());
54 } catch (Exception e) {
55 throw new SlcException("Could not send request.", e);
56 }
57 }
58
59 public void setAction(String action) {
60 this.action = action;
61 }
62
63 public void setClient(DetachedClient detachedClient) {
64 this.client = detachedClient;
65 }
66
67 public void setProperties(Properties properties) {
68 this.properties = properties;
69 }
70
71 }