1 package org
.argeo
.slc
.ant
.detached
;
3 import java
.util
.Properties
;
6 import org
.apache
.commons
.logging
.Log
;
7 import org
.apache
.commons
.logging
.LogFactory
;
8 import org
.argeo
.slc
.ant
.spring
.MapArg
;
9 import org
.argeo
.slc
.ant
.structure
.SAwareTask
;
10 import org
.argeo
.slc
.core
.SlcException
;
11 import org
.argeo
.slc
.detached
.DetachedAnswer
;
12 import org
.argeo
.slc
.detached
.DetachedClient
;
13 import org
.argeo
.slc
.detached
.DetachedRequest
;
14 import org
.argeo
.slc
.spring
.SpringUtils
;
16 public class SlcDetachedTask
extends SAwareTask
{
17 private final static Log log
= LogFactory
.getLog(SlcDetachedTask
.class);
19 private String client
;
20 private String action
;
22 private MapArg properties
;
25 protected void executeActions(String mode
) {
26 // Find detached client
27 DetachedClient detachedClient
= null;
29 detachedClient
= getBean(client
);
31 detachedClient
= SpringUtils
.loadSingleFromContext(getContext(),
32 DetachedClient
.class);
34 if (detachedClient
== null)
35 throw new SlcException("Could not find any detached client.");
37 // Prepare and send request
38 DetachedRequest request
= new DetachedRequest(UUID
.randomUUID()
40 request
.setRef(action
);
42 if (properties
!= null) {
43 Properties props
= new Properties();
44 props
.putAll(properties
.getMap());
45 request
.setProperties(props
);
49 detachedClient
.sendRequest(request
);
50 DetachedAnswer answer
= detachedClient
.receiveAnswer();
51 if (answer
.getStatus() == DetachedAnswer
.ERROR
)
52 throw new SlcException("Error when executing request "
53 + answer
.getUuid() + ": " + answer
.getLog());
55 log
.info("Admin answer: " + answer
.getLog());
56 } catch (Exception e
) {
57 throw new SlcException("Could not send request.", e
);
61 public void setClient(String driverBean
) {
62 this.client
= driverBean
;
65 public void setAction(String action
) {
69 public MapArg
createProperties() {
70 if (properties
== null)
71 properties
= new MapArg();
73 throw new SlcException("Properties already declared.");