public void attach(ZeroMQWireSource source, PhysicalWireTarget target, Wire wire) { URI uri = source.getCallbackUri() != null ? source.getCallbackUri() : target.getUri(); ClassLoader loader = target.getClassLoader(); List<InvocationChain> chains = ZeroMQAttacherHelper.sortChains(wire); ZeroMQMetadata metadata = source.getMetadata(); broker.connectToReceiver(uri, chains, metadata, loader); }
private void processReference(Wire wire, JavaWireSource source, PhysicalWireTarget target, JavaComponent component, Injectable injectable, Class<?> type) { String callbackUri = null; URI uri = target.getCallbackUri(); if (uri != null) { callbackUri = uri.toString(); } Supplier<?> supplier = proxyService.createSupplier(type, wire, callbackUri); if (source.isKeyed() || source.isOrdered()) { Object key = getKey(source, target); int order = source.getOrder(); InjectionAttributes attributes = new InjectionAttributes(key, order); component.setSupplier(injectable, supplier, attributes); } else { component.setSupplier(injectable, supplier); } }
public <T> T resolve(Class<T> interfaze) throws Fabric3Exception { LogicalWire logicalWire = createWire(interfaze); PhysicalWire physicalWire = wireGenerator.generateWire(logicalWire); NonManagedWireSource source = (NonManagedWireSource) physicalWire.getSource(); URI uri = ContributionResolver.getContribution(interfaze); ClassLoader classLoader = classLoaderRegistry.getClassLoader(uri); physicalWire.getTarget().setClassLoader(classLoader); source.setClassLoader(classLoader); connector.connect(physicalWire); return interfaze.cast(source.getProxy()); }
public void detach(ZeroMQWireSource source, PhysicalWireTarget target) { URI uri = source.getCallbackUri() != null ? source.getCallbackUri() : target.getUri(); broker.releaseReceiver(uri); }
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; }
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); }
private void addJAXBInterceptor(JmsWireSource source, PhysicalWireTarget target, PhysicalOperation op, InvocationChain chain) { ClassLoader sourceClassLoader = source.getClassLoader(); ClassLoader targetClassLoader = target.getClassLoader(); List<DataType> jaxTypes = DataTypeHelper.createTypes(op); Interceptor jaxbInterceptor = interceptorFactory.createInterceptor(op, DataTypeHelper.JAXB_TYPES, jaxTypes, targetClassLoader, sourceClassLoader); chain.addInterceptor(jaxbInterceptor); }
public <T extends ResourceReference> PhysicalWire generateResource(LogicalResourceReference<T> logicalReference) { T reference = logicalReference.getDefinition(); LogicalComponent<?> component = logicalReference.getParent(); // Generates the wire source metadata ComponentGenerator sourceGenerator = getGenerator(component); @SuppressWarnings("unchecked") PhysicalWireSource source = sourceGenerator.generateResourceSource(logicalReference); URI sourceUri = component.getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // Generates the wire target metadata ResourceReferenceGenerator<T> targetGenerator = getGenerator(reference); PhysicalWireTarget target = targetGenerator.generateWireTarget(logicalReference); URI targetUri = logicalReference.getParent().getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); boolean optimizable = target.isOptimizable(); // Create the wire from the component to the resource List<LogicalOperation> sourceOperations = logicalReference.getOperations(); Set<PhysicalOperation> operations = operationGenerator.generateOperations(sourceOperations); PhysicalWire physicalWire = new PhysicalWire(source, target, operations); physicalWire.setOptimizable(optimizable); return physicalWire; }
target.setCallbackUri(callbackUri); target.setClassLoader(targetLoader);
URI targetUri = target.getUri(); throw new Fabric3Exception("No matching method found when wiring " + sourceUri + " to " + targetUri); } catch (NoSuchMethodException e) { URI sourceUri = source.getUri(); URI targetUri = target.getUri(); throw new Fabric3Exception("No matching method found when wiring " + sourceUri + " to " + targetUri, e);
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; }
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); }
/** * Returns a key for a map-style reference or null if there is no key associated with the reference. * * @param source the source metadata * @param target the target metadata * @return the key * @throws Fabric3Exception if there is an error instantiating the key */ @SuppressWarnings("unchecked") protected Object getKey(PojoWireSource source, PhysicalWireTarget target) throws Fabric3Exception { if (!source.isKeyed()) { return null; } String key = source.getKey(); // The target classloader must be used since the key class may not be visible to the source classloader, for example, when subclasses are used as keys ClassLoader targetClassLoader = target.getClassLoader(); Class<?> keyType = ClassLoading.loadClass(targetClassLoader, source.getKeyClassName()); if (String.class.equals(keyType)) { // short-circuit the transformation and return the string return key; } else if (Enum.class.isAssignableFrom(keyType)) { // enum, instantiate it directly Class<Enum> enumClass = (Class<Enum>) keyType; return Enum.valueOf(enumClass, key); } JavaType targetType = new JavaType(keyType); return createKey(targetType, key, targetClassLoader); }
public <T extends ResourceReference> PhysicalWire generateResource(LogicalResourceReference<T> logicalReference) { T reference = logicalReference.getDefinition(); LogicalComponent<?> component = logicalReference.getParent(); // Generates the wire source metadata ComponentGenerator sourceGenerator = getGenerator(component); @SuppressWarnings("unchecked") PhysicalWireSource source = sourceGenerator.generateResourceSource(logicalReference); URI sourceUri = component.getDefinition().getContributionUri(); source.setClassLoader(classLoaderRegistry.getClassLoader(sourceUri)); // Generates the wire target metadata ResourceReferenceGenerator<T> targetGenerator = getGenerator(reference); PhysicalWireTarget target = targetGenerator.generateWireTarget(logicalReference); URI targetUri = logicalReference.getParent().getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); boolean optimizable = target.isOptimizable(); // Create the wire from the component to the resource List<LogicalOperation> sourceOperations = logicalReference.getOperations(); Set<PhysicalOperation> operations = operationGenerator.generateOperations(sourceOperations); PhysicalWire physicalWire = new PhysicalWire(source, target, operations); physicalWire.setOptimizable(optimizable); return physicalWire; }
target.setCallbackUri(callbackUri); target.setClassLoader(targetLoader);
URI targetUri = target.getUri(); throw new Fabric3Exception("No matching method found when wiring " + sourceUri + " to " + targetUri); } catch (NoSuchMethodException e) { URI sourceUri = source.getUri(); URI targetUri = target.getUri(); throw new Fabric3Exception("No matching method found when wiring " + sourceUri + " to " + targetUri, e);
PhysicalWireTarget target = targetGenerator.generateTarget(service); URI targetUri = targetComponent.getDefinition().getContributionUri(); target.setClassLoader(classLoaderRegistry.getClassLoader(targetUri)); ServiceContract serviceContract = service.getServiceContract(); ServiceContract callbackContract = serviceContract.getCallbackContract(); target.setCallbackUri(callbackUri); boolean optimizable = source.isOptimizable() && target.isOptimizable() && checkOptimization(referenceContract, operations); physicalWire.setOptimizable(optimizable); return physicalWire;
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); }
/** * Returns a key for a map-style reference or null if there is no key associated with the reference. * * @param source the source metadata * @param target the target metadata * @return the key * @throws Fabric3Exception if there is an error instantiating the key */ @SuppressWarnings("unchecked") protected Object getKey(PojoWireSource source, PhysicalWireTarget target) throws Fabric3Exception { if (!source.isKeyed()) { return null; } String key = source.getKey(); // The target classloader must be used since the key class may not be visible to the source classloader, for example, when subclasses are used as keys ClassLoader targetClassLoader = target.getClassLoader(); Class<?> keyType = ClassLoading.loadClass(targetClassLoader, source.getKeyClassName()); if (String.class.equals(keyType)) { // short-circuit the transformation and return the string return key; } else if (Enum.class.isAssignableFrom(keyType)) { // enum, instantiate it directly Class<Enum> enumClass = (Class<Enum>) keyType; return Enum.valueOf(enumClass, key); } JavaType targetType = new JavaType(keyType); return createKey(targetType, key, targetClassLoader); }
public <T> T resolve(Class<T> interfaze) throws Fabric3Exception { LogicalWire logicalWire = createWire(interfaze); PhysicalWire physicalWire = wireGenerator.generateWire(logicalWire); NonManagedWireSource source = (NonManagedWireSource) physicalWire.getSource(); URI uri = ContributionResolver.getContribution(interfaze); ClassLoader classLoader = classLoaderRegistry.getClassLoader(uri); physicalWire.getTarget().setClassLoader(classLoader); source.setClassLoader(classLoader); connector.connect(physicalWire); return interfaze.cast(source.getProxy()); }