1 package org
.argeo
.slc
.detached
;
3 import org
.osgi
.framework
.BundleContext
;
4 import org
.osgi
.framework
.ServiceReference
;
6 public class DetachedExecutionServerImpl
implements DetachedExecutionServer
{
7 private final DetachedContextImpl detachedContext
;
9 private BundleContext bundleContext
;
10 private DetachedDriver driver
;
12 private boolean active
= false;
14 public void setDriver(DetachedDriver driver
) {
18 public DetachedExecutionServerImpl() {
19 detachedContext
= new DetachedContextImpl();
22 public DetachedStepAnswer
executeStep(DetachedStepRequest request
) {
24 DetachedStep step
= null;
27 ServiceReference
[] refs
= bundleContext
.getAllServiceReferences(
28 StaticRefProvider
.class.getName(), null);
29 for (int i
= 0; i
< refs
.length
; i
++) {
30 StaticRefProvider provider
= (StaticRefProvider
) bundleContext
32 Object obj
= provider
.getStaticRef(request
.getStepRef());
34 step
= (DetachedStep
) obj
;
40 throw new DetachedException("Could not find step with ref "
41 + request
.getStepRef());
43 return step
.execute(detachedContext
, request
);
44 } catch (DetachedException e
) {
46 } catch (Exception e
) {
48 throw new DetachedException(
49 "Unexpected exception while executing request " + request
,
54 public void init(BundleContext bundleContext
) {
55 this.bundleContext
= bundleContext
;
56 Thread driverThread
= new Thread(new Runnable() {
61 DetachedStepRequest request
= driver
.receiveRequest();
63 } catch (Exception e
) {
64 if (e
instanceof RuntimeException
)
65 throw (RuntimeException
) e
;