private void raiseNoServiceError(LogicalService service, URI uri, InstantiationContext context) { LogicalComponent<?> parent = service.getParent(); String msg = "No services available on component: " + uri; NoServiceOnComponent error = new NoServiceOnComponent(msg, parent); context.addError(error); }
@SuppressWarnings({"unchecked"}) public void generateWireTarget(JavaWireTarget target, LogicalService service) { LogicalComponent<JavaImplementation> component = (LogicalComponent<JavaImplementation>) service.getParent(); URI uri = URI.create(component.getUri().toString() + "#" + service.getUri().getFragment()); target.setUri(uri); // assume only wires to composite scope components can be optimized Component<JavaImplementation> componentDefinition = component.getDefinition(); JavaImplementation implementation = componentDefinition.getImplementation(); InjectingComponentType componentType = implementation.getComponentType(); Scope scope = componentType.getScope(); target.setOptimizable(scope.isSingleton()); }
@SuppressWarnings({"unchecked"}) public PhysicalWireSource generateCallbackSource(LogicalService service) { JavaWireSource source = new JavaWireSource(); JavaServiceContract callbackContract = (JavaServiceContract) service.getDefinition().getServiceContract().getCallbackContract(); LogicalComponent<JavaImplementation> component = (LogicalComponent<JavaImplementation>) service.getParent(); generationHelper.generateCallbackWireSource(source, component, callbackContract); return source; }
/** * Selects and configures bindings for wires sourced from the given component. * * @param component the component * @throws BindingSelectionException if an error occurs selecting a binding */ private void selectBindings(LogicalComponent<?> component) throws BindingSelectionException { for (LogicalReference reference : component.getReferences()) { for (LogicalWire wire : reference.getWires()) { LogicalService targetService = wire.getTarget(); if (targetService != null) { LogicalComponent<?> targetComponent = targetService.getParent(); if ((LOCAL_ZONE.equals(component.getZone()) && LOCAL_ZONE.equals(targetComponent.getZone()))) { // components are local, no need for a binding continue; } else if (!LOCAL_ZONE.equals(component.getZone()) && component.getZone().equals(targetComponent.getZone())) { // components are local, no need for a binding continue; } selectBinding(wire); } } } }
/** * Creates a wire by resolving a Target. * * @param target the target * @param reference the source reference * @param bindingName the binding name or null * @param parent the parent component * @param context the instantiation context * @return the wire or null if it could not be created */ private LogicalWire createWire(Target target, LogicalReference reference, String bindingName, LogicalCompositeComponent parent, InstantiationContext context) { LogicalService service = resolveService(reference, target, parent, context); if (service == null) { return null; } QName deployable = service.getParent().getDeployable(); LogicalWire wire = new LogicalWire(parent, reference, service, deployable, true); String serviceBindingName = target.getBinding(); resolveBindings(reference, bindingName, service, wire, serviceBindingName, context); return wire; }
/** * Creates a wire by resolving a Target. * * @param target the target * @param reference the source reference * @param bindingName the binding name or null * @param parent the parent component * @param context the instantiation context * @return the wire or null if it could not be created */ private LogicalWire createWire(Target target, LogicalReference reference, String bindingName, LogicalCompositeComponent parent, InstantiationContext context) { LogicalService service = resolveService(reference, target, parent, context); if (service == null) { return null; } URI contributionUri = service.getParent().getDefinition().getContributionUri(); LogicalWire wire = new LogicalWire(parent, reference, service, contributionUri); String serviceBindingName = target.getBinding(); resolveBindings(reference, bindingName, service, wire, serviceBindingName, context); return wire; }
private boolean isWireReinjection(LogicalReference logicalReference) { Multiplicity multiplicity = logicalReference.getDefinition().getMultiplicity(); if (multiplicity == Multiplicity.ZERO_N || multiplicity == Multiplicity.ONE_N) { for (LogicalWire wire : logicalReference.getWires()) { LogicalComponent<?> targetComponent = wire.getTarget().getParent(); // check the source and target sides since a target may have been added or removed if (wire.getState() == LogicalState.NEW || wire.getState() == LogicalState.MARKED || targetComponent.getState() == LogicalState.NEW || targetComponent.getState() == LogicalState.MARKED) { return true; } } } return false; }
private boolean isWireReinjection(LogicalReference logicalReference) { Multiplicity multiplicity = logicalReference.getDefinition().getMultiplicity(); if (multiplicity == Multiplicity.ZERO_N || multiplicity == Multiplicity.ONE_N) { for (LogicalWire wire : logicalReference.getWires()) { LogicalComponent<?> targetComponent = wire.getTarget().getParent(); // check the source and target sides since a target may have been added or removed if (wire.getState() == LogicalState.NEW || wire.getState() == LogicalState.MARKED || targetComponent.getState() == LogicalState.NEW || targetComponent.getState() == LogicalState.MARKED) { return true; } } } return false; }
public <T extends Binding> PhysicalWire generateService(LogicalBinding<T> binding, URI callbackUri) { checkService(binding); LogicalService service = (LogicalService) binding.getParent(); LogicalComponent<?> component = service.getParent(); ServiceContract contract = service.getServiceContract(); List<LogicalOperation> operations = service.getOperations(); // generate the metadata used to attach the physical wire to the target component ComponentGenerator targetGenerator = getGenerator(component); PhysicalWireTarget target = targetGenerator.generateTarget(service); URI targetUri = service.getParent().getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); target.setCallbackUri(callbackUri); // generate the metadata used to attach the physical wire to the source transport WireBindingGenerator<T> sourceGenerator = getGenerator(binding); PhysicalWireSource source = sourceGenerator.generateSource(binding, contract, operations); URI sourceUri = service.getParent().getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // generate the metadata for interceptors that are attached to wire invocation chains, e.g. policy implemented by an interceptor Set<PhysicalOperation> physicalOperations = operationGenerator.generateOperations(operations); PhysicalWire physicalWire = new PhysicalWire(source, target, physicalOperations); boolean optimizable = source.isOptimizable() && target.isOptimizable() && checkOptimization(contract, physicalOperations); physicalWire.setOptimizable(optimizable); return physicalWire; }
/** * Validates a target key is present for keyed references. * * @param reference the reference * @param service the service * @param context the logical context */ private void validateKeyedReference(LogicalReference reference, LogicalService service, InstantiationContext context) { if (!reference.getDefinition().isKeyed()) { return; } LogicalComponent<?> parent = service.getParent(); if (parent.getDefinition().getKey() == null && parent.getDefinition().getComponentType().getKey() == null) { KeyNotFound error = new KeyNotFound(reference); context.addError(error); } }
/** * Validates a target key is present for keyed references. * * @param reference the reference * @param service the service * @param context the logical context */ private void validateKeyedReference(LogicalReference reference, LogicalService service, InstantiationContext context) { if (!reference.getDefinition().isKeyed()) { return; } LogicalComponent<?> parent = service.getParent(); if (parent.getDefinition().getKey() == null && parent.getDefinition().getComponentType().getKey() == null) { KeyNotFound error = new KeyNotFound(reference); context.addError(error); } }
/** * Validates a target key is present for keyed references. * * @param reference the reference * @param service the service * @param context the logical context */ private void validateKeyedReference(LogicalReference reference, LogicalService service, InstantiationContext context) { if (!reference.getDefinition().isKeyed()) { return; } LogicalComponent<?> parent = service.getParent(); if (parent.getDefinition().getKey() == null && parent.getDefinition().getComponentType().getKey() == null) { KeyNotFound error = new KeyNotFound(reference); context.addError(error); } }
public <T> T resolve(Class<T> interfaze) throws ResolverException { LogicalWire wire = createWire(interfaze); try { boolean remote = !wire.getSource().getParent().getZone().equals(wire.getTarget().getParent().getZone()); PhysicalWireDefinition pwd; if (remote) { bindingSelector.selectBinding(wire); pwd = wireGenerator.generateBoundReference(wire.getSourceBinding()); pwd.getSource().setUri(wire.getSource().getParent().getUri()); } else { pwd = wireGenerator.generateWire(wire); } NonManagedPhysicalWireSourceDefinition source = (NonManagedPhysicalWireSourceDefinition) pwd.getSource(); URI uri = ContributionResolver.getContribution(interfaze); pwd.getTarget().setClassLoaderId(uri); source.setClassLoaderId(uri); connector.connect(pwd); return interfaze.cast(source.getProxy()); } catch (GenerationException | ContainerException e) { throw new ResolverException(e); } }
public <T extends Binding> PhysicalWire generateServiceCallback(LogicalBinding<T> binding) { checkService(binding); LogicalService service = (LogicalService) binding.getParent(); LogicalComponent<?> component = service.getParent(); ServiceContract contract = service.getServiceContract(); ServiceContract callbackContract = contract.getCallbackContract(); List<LogicalOperation> operations = service.getCallbackOperations(); // generate the metadata used to attach the physical callback wire to the source component ComponentGenerator sourceGenerator = getGenerator(component); PhysicalWireSource source = sourceGenerator.generateCallbackSource(service); URI sourceUri = component.getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // generate the metadata used to attach the physical callback wire to the target transport WireBindingGenerator<T> bindingGenerator = getGenerator(binding); PhysicalWireTarget target = bindingGenerator.generateTarget(binding, callbackContract, operations); target.setCallback(true); URI targetUri = binding.getParent().getParent().getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); // generate the metadata for interceptors that are attached to wire invocation chains, e.g. policy implemented by an interceptor Set<PhysicalOperation> physicalOperations = operationGenerator.generateOperations(operations); return new PhysicalWire(source, target, physicalOperations); }
public <T extends Binding> PhysicalWire generateServiceCallback(LogicalBinding<T> binding) { checkService(binding); LogicalService service = (LogicalService) binding.getParent(); LogicalComponent<?> component = service.getParent(); ServiceContract contract = service.getServiceContract(); ServiceContract callbackContract = contract.getCallbackContract(); List<LogicalOperation> operations = service.getCallbackOperations(); // generate the metadata used to attach the physical callback wire to the source component ComponentGenerator sourceGenerator = getGenerator(component); PhysicalWireSource source = sourceGenerator.generateCallbackSource(service); URI sourceUri = component.getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // generate the metadata used to attach the physical callback wire to the target transport WireBindingGenerator<T> bindingGenerator = getGenerator(binding); PhysicalWireTarget target = bindingGenerator.generateTarget(binding, callbackContract, operations); target.setCallback(true); URI targetUri = binding.getParent().getParent().getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); // generate the metadata for interceptors that are attached to wire invocation chains, e.g. policy implemented by an interceptor Set<PhysicalOperation> physicalOperations = operationGenerator.generateOperations(operations); return new PhysicalWire(source, target, physicalOperations); }
public <T extends Binding> PhysicalWire generateReferenceCallback(LogicalBinding<T> binding) { checkReference(binding); LogicalReference reference = (LogicalReference) binding.getParent(); LogicalComponent<?> component = reference.getParent(); ServiceContract contract = reference.getServiceContract(); ServiceContract callbackContract = contract.getCallbackContract(); LogicalService callbackService = component.getService(callbackContract.getInterfaceName()); List<LogicalOperation> operations = reference.getCallbackOperations(); // generate the metadata used to attach the physical callback wire to the source transport WireBindingGenerator<T> sourceGenerator = getGenerator(binding); PhysicalWireSource source = sourceGenerator.generateSource(binding, callbackContract, operations); URI sourceUri = binding.getParent().getParent().getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // generate the metadata used to attach the physical callback wire to the target component ComponentGenerator targetGenerator = getGenerator(component); PhysicalWireTarget target = targetGenerator.generateTarget(callbackService); URI targetUri = callbackService.getParent().getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); target.setCallback(true); Set<PhysicalOperation> operation = operationGenerator.generateOperations(operations); return new PhysicalWire(source, target, operation); }
public <T extends Binding> PhysicalWire generateReferenceCallback(LogicalBinding<T> binding) { checkReference(binding); LogicalReference reference = (LogicalReference) binding.getParent(); LogicalComponent<?> component = reference.getParent(); ServiceContract contract = reference.getServiceContract(); ServiceContract callbackContract = contract.getCallbackContract(); LogicalService callbackService = component.getService(callbackContract.getInterfaceName()); List<LogicalOperation> operations = reference.getCallbackOperations(); // generate the metadata used to attach the physical callback wire to the source transport WireBindingGenerator<T> sourceGenerator = getGenerator(binding); PhysicalWireSource source = sourceGenerator.generateSource(binding, callbackContract, operations); URI sourceUri = binding.getParent().getParent().getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // generate the metadata used to attach the physical callback wire to the target component ComponentGenerator targetGenerator = getGenerator(component); PhysicalWireTarget target = targetGenerator.generateTarget(callbackService); URI targetUri = callbackService.getParent().getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); target.setCallback(true); Set<PhysicalOperation> operation = operationGenerator.generateOperations(operations); return new PhysicalWire(source, target, operation); }
private PhysicalWire generateLocalWireCallback(LogicalWire wire) { LogicalReference reference = wire.getSource(); LogicalService service = wire.getTarget(); LogicalComponent<?> targetComponent = reference.getParent(); ServiceContract referenceCallbackContract = reference.getServiceContract().getCallbackContract(); LogicalService callbackService = targetComponent.getService(referenceCallbackContract.getInterfaceName()); LogicalComponent sourceComponent = service.getParent(); List<LogicalOperation> targetOperations = callbackService.getOperations(); List<LogicalOperation> sourceOperations = service.getCallbackOperations(); Set<PhysicalOperation> callbackOperations = operationGenerator.generateOperations(targetOperations, sourceOperations, false); // generate the metadata used to attach the physical callback wire to the source component (the component providing the forward service) ComponentGenerator sourceGenerator = getGenerator(sourceComponent); PhysicalWireSource source = sourceGenerator.generateCallbackSource(service); URI sourceUri = sourceComponent.getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // generate the metadata used to attach the physical callback wire to the target component (the client of the forward service) ComponentGenerator targetGenerator = getGenerator(targetComponent); PhysicalWireTarget target = targetGenerator.generateTarget(callbackService); URI targetUri = targetComponent.getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); target.setCallback(true); PhysicalWire physicalWire = new PhysicalWire(source, target, callbackOperations); physicalWire.setOptimizable(false); return physicalWire; }
private PhysicalWire generateLocalWireCallback(LogicalWire wire) { LogicalReference reference = wire.getSource(); LogicalService service = wire.getTarget(); LogicalComponent<?> targetComponent = reference.getParent(); ServiceContract referenceCallbackContract = reference.getServiceContract().getCallbackContract(); LogicalService callbackService = targetComponent.getService(referenceCallbackContract.getInterfaceName()); LogicalComponent sourceComponent = service.getParent(); List<LogicalOperation> targetOperations = callbackService.getOperations(); List<LogicalOperation> sourceOperations = service.getCallbackOperations(); Set<PhysicalOperation> callbackOperations = operationGenerator.generateOperations(targetOperations, sourceOperations, false); // generate the metadata used to attach the physical callback wire to the source component (the component providing the forward service) ComponentGenerator sourceGenerator = getGenerator(sourceComponent); PhysicalWireSource source = sourceGenerator.generateCallbackSource(service); URI sourceUri = sourceComponent.getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // generate the metadata used to attach the physical callback wire to the target component (the client of the forward service) ComponentGenerator targetGenerator = getGenerator(targetComponent); PhysicalWireTarget target = targetGenerator.generateTarget(callbackService); URI targetUri = targetComponent.getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); target.setCallback(true); PhysicalWire physicalWire = new PhysicalWire(source, target, callbackOperations); physicalWire.setOptimizable(false); return physicalWire; }
public <T extends BindingDefinition> PhysicalWireDefinition generateBoundReferenceCallback(LogicalBinding<T> binding) throws GenerationException { checkReference(binding); LogicalReference reference = (LogicalReference) binding.getParent(); LogicalComponent<?> component = reference.getParent(); ServiceContract contract = reference.getServiceContract(); ServiceContract callbackContract = contract.getCallbackContract(); LogicalService callbackService = component.getService(callbackContract.getInterfaceName()); List<LogicalOperation> operations = reference.getCallbackOperations(); // resolve policies PolicyResult policyResult = policyResolver.resolveCallbackPolicies(binding); EffectivePolicy sourcePolicy = policyResult.getSourcePolicy(); EffectivePolicy targetPolicy = policyResult.getTargetPolicy(); // generate the metadata used to attach the physical callback wire to the source transport BindingGenerator<T> sourceGenerator = getGenerator(binding); PhysicalSourceDefinition sourceDefinition = sourceGenerator.generateSource(binding, callbackContract, operations, targetPolicy); sourceDefinition.setClassLoaderId(binding.getParent().getParent().getDefinition().getContributionUri()); // generate the metadata used to attach the physical callback wire to the target component ComponentGenerator targetGenerator = getGenerator(component); PhysicalTargetDefinition targetDefinition = targetGenerator.generateTarget(callbackService, sourcePolicy); targetDefinition.setClassLoaderId(callbackService.getParent().getDefinition().getContributionUri()); targetDefinition.setCallback(true); Set<PhysicalOperationDefinition> operation = operationGenerator.generateOperations(operations, true, policyResult); return new PhysicalWireDefinition(sourceDefinition, targetDefinition, operation); }