/** * 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 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; }
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); } } }
@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; }
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);
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; }