this.scheduler = scheduler;
this.workContext = workContext;
}
public void connect(SCAObject source) {
CompositeComponent parent = source.getParent();
if (source instanceof AtomicComponent) {
AtomicComponent sourceComponent = (AtomicComponent) source;
// connect outbound wires for component references to their targets
for (List<OutboundWire> referenceWires : sourceComponent.getOutboundWires().values()) {
for (OutboundWire outboundWire : referenceWires) {
if (outboundWire instanceof OutboundAutowire) {
continue;
}
try {
SCAObject target;
if (sourceComponent.isSystem()) {
target = parent.getSystemChild(outboundWire.getTargetName().getPartName());
} else {
target = parent.getChild(outboundWire.getTargetName().getPartName());
}
connect(sourceComponent, outboundWire, target);
} catch (BuilderConfigException e) {
e.addContextName(source.getName());
e.addContextName(parent.getName());
throw e;
}
}
}
// connect inbound wires
for (InboundWire inboundWire : sourceComponent.getInboundWires().values()) {
for (InboundInvocationChain chain : inboundWire.getInvocationChains().values()) {
Operation<?> operation = chain.getOperation();
String serviceName = inboundWire.getServiceName();
TargetInvoker invoker = sourceComponent.createTargetInvoker(serviceName, operation);
chain.setTargetInvoker(invoker);
chain.prepare();
}
}
} else if (source instanceof Reference) {
Reference reference = (Reference) source;
InboundWire inboundWire = reference.getInboundWire();
Map<Operation<?>, InboundInvocationChain> inboundChains = inboundWire.getInvocationChains();
for (InboundInvocationChain chain : inboundChains.values()) {
//TODO handle async
// add target invoker on inbound side
ServiceContract contract = inboundWire.getServiceContract();
Operation operation = chain.getOperation();
TargetInvoker invoker = reference.createTargetInvoker(contract, operation);
chain.setTargetInvoker(invoker);
chain.prepare();
}
OutboundWire outboundWire = reference.getOutboundWire();
// connect the reference's inbound and outbound wires
connect(inboundWire, outboundWire, true);
if (reference instanceof CompositeReference) {
// For a composite reference only, since its outbound wire comes
// from its parent composite,
// the corresponding target would not lie in its parent but
// rather in its parent's parent
parent = parent.getParent();
assert parent != null : "Parent of parent was null";
SCAObject target = parent.getChild(outboundWire.getTargetName().getPartName());
connect((Component)parent, outboundWire, target);
}
} else if (source instanceof Service) {
Service service = (Service) source;
InboundWire inboundWire = service.getInboundWire();
OutboundWire outboundWire = service.getOutboundWire();
// For a composite reference only, since its outbound wire comes from its parent composite,
// the corresponding target would not lie in its parent but rather in its parent's parent
if (source instanceof CompositeReference) {
parent = parent.getParent();
assert parent != null : "Parent of parent was null";
}
SCAObject target;
if (service.isSystem()) {
target = parent.getSystemChild(outboundWire.getTargetName().getPartName());
} else {
target = parent.getChild(outboundWire.getTargetName().getPartName());
}
// connect the outbound service wire to the target
connect(service, outboundWire, target);
// NB: this connect must be done after the outbound service chain is connected to its target above
if (!(source instanceof CompositeService)) {