private Service<ComponentType> createServiceDefinition(Class<?> serviceInterface, InjectingComponentType componentType, IntrospectionContext context) { ServiceContract contract = contractProcessor.introspect(serviceInterface, context, componentType); return new Service<>(contract.getInterfaceName(), contract); } }
/** * Default constructor * * @param uri the service uri * @param definition the service definition * @param parent the service parent component */ @SuppressWarnings("unchecked") public LogicalService(URI uri, Service<ComponentType> definition, LogicalComponent<?> parent) { super(uri, definition != null ? definition.getServiceContract() : null, parent); this.definition = definition; }
private void createServices(Component<?> component, LogicalComponent<?> logicalComponent, ComponentType componentType) { for (Service<ComponentType> service : componentType.getServices().values()) { String name = service.getName(); URI serviceUri = logicalComponent.getUri().resolve('#' + name); LogicalService logicalService = new LogicalService(serviceUri, service, logicalComponent); for (Binding binding : service.getBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addBinding(logicalBinding); } for (Binding binding : service.getCallbackBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addCallbackBinding(logicalBinding); } // service is configured in the component definition Service<Component> componentService = component.getServices().get(name); if (componentService != null) { for (Binding binding : componentService.getBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addBinding(logicalBinding); } for (Binding binding : componentService.getCallbackBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addCallbackBinding(logicalBinding); } } logicalComponent.addService(logicalService); } }
/** * Adds a binding configuration to a service provided by the component. * * @param serviceName the service name * @param bindingDefinition the binding definition * @return the builder */ public T binding(String serviceName, Binding bindingDefinition) { checkState(); Component<?> definition = getComponent(); Service<Component> service = definition.getServices().get(serviceName); if (service == null) { service = new Service<>(serviceName); definition.add(service); } service.addBinding(bindingDefinition); return builder(); }
String name = serviceInterface.getName(); for (Service<ComponentType> service : componentType.getServices().values()) { String interfaceName = service.getServiceContract().getQualifiedInterfaceName(); if (interfaceName.equals(name)) { boundService = service; boundService.addBinding(binding); ServiceContract contract = boundService.getServiceContract(); if (contract.getCallbackContract() != null) { Binding callbackBinding = processServiceCallback(annotation, boundService, componentType, implClass, context); if (callbackBinding != null) { boundService.addCallbackBinding(callbackBinding);
private <S extends LogicalComponent<?>> URI generateCallbackUri(S source, ServiceContract contract, String referenceName) { LogicalService candidate = null; for (LogicalService entry : source.getServices()) { MatchResult result = matcher.isAssignableFrom(contract, entry.getServiceContract(), false); if (result.isAssignable()) { candidate = entry; break; } } if (candidate == null) { String name = contract.getInterfaceName(); URI uri = source.getUri(); throw new Fabric3Exception("Callback service not found: " + name + " on component: " + uri + " originating from reference :" + referenceName); } return URI.create(source.getUri().toString() + "#" + candidate.getDefinition().getName()); }
private void createServices(Component<?> component, LogicalComponent<?> logicalComponent, ComponentType componentType) { for (Service<ComponentType> service : componentType.getServices().values()) { String name = service.getName(); URI serviceUri = logicalComponent.getUri().resolve('#' + name); LogicalService logicalService = new LogicalService(serviceUri, service, logicalComponent); for (Binding binding : service.getBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addBinding(logicalBinding); } for (Binding binding : service.getCallbackBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addCallbackBinding(logicalBinding); } // service is configured in the component definition Service<Component> componentService = component.getServices().get(name); if (componentService != null) { for (Binding binding : componentService.getBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addBinding(logicalBinding); } for (Binding binding : componentService.getCallbackBindings()) { LogicalBinding<Binding> logicalBinding = new LogicalBinding<>(binding, logicalService); logicalService.addCallbackBinding(logicalBinding); } } logicalComponent.addService(logicalService); } }
private <S extends LogicalComponent<?>> URI generateCallbackUri(S source, ServiceContract contract, String referenceName) { LogicalService candidate = null; for (LogicalService entry : source.getServices()) { MatchResult result = matcher.isAssignableFrom(contract, entry.getServiceContract(), false); if (result.isAssignable()) { candidate = entry; break; } } if (candidate == null) { String name = contract.getInterfaceName(); URI uri = source.getUri(); throw new Fabric3Exception("Callback service not found: " + name + " on component: " + uri + " originating from reference :" + referenceName); } return URI.create(source.getUri().toString() + "#" + candidate.getDefinition().getName()); }
@SuppressWarnings({"unchecked"}) private Service createDefinition(Class<?> service, String name, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { ServiceContract serviceContract = contractProcessor.introspect(service, implClass, context, componentType); Service definition = new Service(name, serviceContract); if (policyIntrospector != null) { policyIntrospector.introspectPolicyOnOperations(serviceContract, implClass, context); } return definition; } }
private Set<Signature> getOperations(Collection<Service<ComponentType>> services) { Set<Signature> operations = new HashSet<>(); for (Service<ComponentType> definition : services) { List<? extends Operation> ops = definition.getServiceContract().getOperations(); for (Operation operation : ops) { String name = operation.getName(); List<? extends DataType> inputTypes = operation.getInputTypes(); List<String> paramTypes = new ArrayList<>(inputTypes.size()); for (DataType inputType : inputTypes) { paramTypes.add(inputType.getType().getName()); } operations.add(new Signature(name, paramTypes)); } } return operations; }
if (service.getServiceContract().getQualifiedInterfaceName().equals(contract.getQualifiedInterfaceName())) { try { serviceUri = new URI(component.getUri() + "#" + service.getDefinition().getName()); } catch (URISyntaxException e) { throw new Fabric3Exception(e);
private void addService(Class<?> interfaze, Component<?> definition) throws ValidationDeploymentException { URI uri = ContributionResolver.getContribution(); DefaultIntrospectionContext context = new DefaultIntrospectionContext(uri, getClass().getClassLoader()); JavaServiceContract contract = contractProcessor.introspect(interfaze, context); Service<ComponentType> service = new Service<>(interfaze.getSimpleName(), contract); definition.getComponentType().add(service); checkErrors(context); }
public void applyHeuristics(InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { // if any services have been defined, just introspect policy if (!componentType.getServices().isEmpty()) { for (Service<ComponentType> definition : componentType.getServices().values()) { JavaServiceContract contract = (JavaServiceContract) definition.getServiceContract(); policyIntrospector.introspectPolicyOnOperations(contract, implClass, context); } return; } Set<Class<?>> interfaces = helper.getImplementedInterfaces(implClass); if (interfaces.isEmpty()) { // no interfaces, use implementation Service<ComponentType> service = createServiceDefinition(implClass, implClass, componentType, context); componentType.add(service); } else { // class implements all interfaces that are not management interfaces or in the Java package for (Class<?> interfaze : interfaces) { Package pkg = interfaze.getPackage(); if (interfaze.isAnnotationPresent(Management.class) || pkg == null || pkg.getName().startsWith("java")) { continue; } Service<ComponentType> service = createServiceDefinition(interfaze, implClass, componentType, context); componentType.add(service); } } }
private void addServiceDefinitions(Object instance, InjectingComponentType componentType, IntrospectionContext context) { Class<?> implClass = instance.getClass(); Class[] interfaces = implClass.getInterfaces(); Class<?> serviceInterface; if (interfaces.length == 0) { serviceInterface = implClass; } else if (interfaces.length == 1) { serviceInterface = interfaces[0]; } else { MultipleInterfacesSupported failure = new MultipleInterfacesSupported(implClass, componentType); context.addError(failure); return; } String serviceName = serviceInterface.getSimpleName(); ServiceContract contract = contractProcessor.introspect(serviceInterface, context); Service<ComponentType> service = new Service<>(serviceName, contract); componentType.add(service); } }
@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; }
@SuppressWarnings({"unchecked"}) private Service<ComponentType> createServiceDefinition(Class<?> serviceInterface, Class<?> implClass, ComponentType componentType, IntrospectionContext context) { ServiceContract contract = contractProcessor.introspect(serviceInterface, context, componentType); Service<ComponentType> definition = new Service<>(contract.getInterfaceName(), contract); policyIntrospector.introspectPolicyOnOperations(contract, implClass, context); return definition; }
protected Binding processService(ZeroMQ annotation, Service<ComponentType> boundService, InjectingComponentType componentType, Class<?> implClass, IntrospectionContext context) { if(!isActiveForEnvironment(annotation.environments())) { return null; } Class<?> serviceInterface = ((JavaServiceContract) boundService.getServiceContract()).getInterfaceClass(); ZeroMQMetadata metadata = new ZeroMQMetadata(); String bindingName = "ZMQ" + serviceInterface.getSimpleName(); ZeroMQBinding binding = new ZeroMQBinding(bindingName, metadata); int port = annotation.port(); if (port > 0) { SocketAddressDefinition address = new SocketAddressDefinition("localhost", port); metadata.setSocketAddresses(Collections.singletonList(address)); } else { parseAddresses(annotation, metadata, implClass, context); } processMetadata(annotation, metadata); return binding; }
public void visitType(Remotable annotation, Class<?> type, InjectingComponentType componentType, IntrospectionContext context) { ServiceContract serviceContract = contractProcessor.introspect(type, context, componentType); Service definition = new Service(serviceContract.getInterfaceName(), serviceContract); componentType.add(definition); } }