]> 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
590758976b454bbfa71c102ccd79bb05a6f8fcc4
[gpl/argeo-slc.git] / runtime / org.argeo.slc.lib.detached / src / main / java / org / argeo / slc / lib / detached / DetachedAdminTask.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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 package org.argeo.slc.lib.detached;
17
18 import java.util.Properties;
19 import java.util.UUID;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.argeo.slc.SlcException;
24 import org.argeo.slc.detached.DetachedAnswer;
25 import org.argeo.slc.detached.DetachedClient;
26 import org.argeo.slc.detached.DetachedRequest;
27
28 public class DetachedAdminTask implements Runnable {
29 private final static Log log = LogFactory.getLog(DetachedAdminTask.class);
30
31 private String action;
32 private DetachedClient client;
33 private Properties properties;
34
35 public void run() {
36 // Prepare and send request
37 DetachedRequest request = new DetachedRequest(UUID.randomUUID()
38 .toString());
39 request.setRef(action);
40
41 if (properties != null) {
42 request.setProperties(properties);
43 }
44
45 try {
46 client.sendRequest(request);
47 DetachedAnswer answer = client.receiveAnswer();
48 if (answer.getStatus() == DetachedAnswer.ERROR)
49 throw new SlcException("Error when executing request "
50 + answer.getUuid() + ": " + answer.getLog());
51 else
52 log.info("Admin answer: " + answer.getLog());
53 } catch (Exception e) {
54 throw new SlcException("Could not send request.", e);
55 }
56 }
57
58 public void setAction(String action) {
59 this.action = action;
60 }
61
62 public void setClient(DetachedClient detachedClient) {
63 this.client = detachedClient;
64 }
65
66 public void setProperties(Properties properties) {
67 this.properties = properties;
68 }
69
70 }