2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org
.argeo
.slc
.lib
.detached
;
19 import java
.util
.Properties
;
20 import java
.util
.UUID
;
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
;
29 public class DetachedAdminTask
implements Runnable
{
30 private final static Log log
= LogFactory
.getLog(DetachedAdminTask
.class);
32 private String action
;
33 private DetachedClient client
;
34 private Properties properties
;
37 // Prepare and send request
38 DetachedRequest request
= new DetachedRequest(UUID
.randomUUID()
40 request
.setRef(action
);
42 if (properties
!= null) {
43 request
.setProperties(properties
);
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());
53 log
.info("Admin answer: " + answer
.getLog());
54 } catch (Exception e
) {
55 throw new SlcException("Could not send request.", e
);
59 public void setAction(String action
) {
63 public void setClient(DetachedClient detachedClient
) {
64 this.client
= detachedClient
;
67 public void setProperties(Properties properties
) {
68 this.properties
= properties
;