/** * Returns the event type * * @return the event type */ public JavaType getType() { return (JavaType) super.getType(); } }
private void createConsumers(Component<?> definition, LogicalComponent<?> logicalComponent, ComponentType componentType) { for (Consumer<ComponentType> consumer : componentType.getConsumers().values()) { String name = consumer.getName(); URI consumerUri = logicalComponent.getUri().resolve('#' + name); LogicalConsumer logicalConsumer = new LogicalConsumer(consumerUri, consumer, logicalComponent); // producer is configured in the logicalComponent definition Consumer<Component> componentConsumer = definition.getConsumers().get(name); if (componentConsumer != null) { for (URI uri : componentConsumer.getSources()) { addSource(logicalConsumer, uri, logicalComponent); } } else { for (URI uri : consumer.getSources()) { addSource(logicalConsumer, uri, logicalComponent); } } logicalConsumer.setServiceContract(consumer.getServiceContract()); logicalComponent.addConsumer(logicalConsumer); } }
@SuppressWarnings("unchecked") private void processAnnotations(Object instance, Component<?> definition, IntrospectionContext context) { InjectingComponentType componentType = (InjectingComponentType) definition.getComponentType(); Class<?> implClass = instance.getClass(); // handle consumer annotations AnnotationProcessor consumerProcessor = annotationProcessors.get(org.fabric3.api.annotation.Consumer.class); for (Method method : implClass.getDeclaredMethods()) { org.fabric3.api.annotation.Consumer consumer = method.getAnnotation(org.fabric3.api.annotation.Consumer.class); if (consumer == null) { continue; } TypeMapping mapping = context.getTypeMapping(implClass); if (mapping == null) { mapping = new TypeMapping(); context.addTypeMapping(implClass, mapping); } helper.resolveTypeParameters(implClass, mapping); consumerProcessor.visitMethod(consumer, method, implClass, componentType, context); } // add automatic configuration for consumer annotations for (Consumer<ComponentType> consumer : componentType.getConsumers().values()) { String name = consumer.getName(); Consumer<Component> componentConsumer = new Consumer<>(name); componentConsumer.setSources(Collections.singletonList(URI.create(name))); definition.add(componentConsumer); } }
public void visitConstructorParameter(org.fabric3.api.annotation.Consumer annotation, java.lang.reflect.Constructor<?> constructor, int index, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { String name = helper.getSiteName(constructor, index, annotation.value()); TypeMapping typeMapping = context.getTypeMapping(implClass); Class<?> genericType = constructor.getParameterTypes()[index]; Type logicalParamType = typeMapping.getActualType(genericType); DataType dataType = createDataType(genericType, logicalParamType, typeMapping); ServiceContract contract = null; if (contractProcessor != null) { Class<?> baseType = helper.getBaseType(genericType, typeMapping); contract = contractProcessor.introspect(baseType, implClass, context, componentType); } ConstructorInjectionSite injectionSite = new ConstructorInjectionSite(constructor, index); Consumer<ComponentType> consumer = new Consumer<>(name, dataType, contract); if (annotation.group().length() > 0){ consumer.setGroup(annotation.group()); } processSources(annotation, consumer, constructor, constructor.getDeclaringClass(), context); componentType.add(consumer, injectionSite, constructor); }
Consumer<ComponentType> consumer = new Consumer<>(name, type, contract); consumer.setGroup(annotation.group()); context.addError(new InvalidConsumerMethod("Sequence number cannot be negative: " + method, method, componentType)); } else { consumer.setSequence(sequence);
private <T> LogicalConsumer createConsumer(Class<T> type, URI channelUri) { JavaServiceContract contract = introspector.introspect(type); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(Object.class, domain, root); DataType dataType = new JavaType(type); Consumer consumer = new Consumer("consumer", dataType, true); int pos = counter.getAndIncrement(); LogicalConsumer logicalConsumer = new LogicalConsumer(URI.create(root + "/F3Synthetic#consumer" + pos), consumer, logicalComponent); logicalConsumer.setServiceContract(contract); logicalConsumer.addSource(channelUri); return logicalConsumer; }
/** * Add a consumer and its associated accessible object. * * @param consumer the consumer to add * @param object the consumer method, field or ctor */ public void add(Consumer<ComponentType> consumer, InjectionSite injectionSite, AccessibleObject object) { super.add(consumer); Injectable injectable = new Injectable(InjectableType.CONSUMER, consumer.getName()); addInjectionSite(injectionSite, injectable); injectionSiteMapping.put(consumer, injectionSite); consumerSignatures.put(consumer.getName(), object); }
private PhysicalChannelConnection generateLocalConnection(LogicalConsumer consumer, LogicalChannel channel, PhysicalConnectionTarget target, ClassLoader classLoader) { // the channel does not have bindings, which means it is a local channel // construct a local connection to the channel URI uri = channel.getUri(); PhysicalConnectionSource source = new ChannelSource(uri, ChannelSide.CONSUMER); source.setSequence(consumer.getDefinition().getSequence()); source.setClassLoader(classLoader); Class<?> type = getType(consumer); boolean bound = channel.isBound(); return new PhysicalChannelConnection(uri, consumer.getUri(), source, target, type, bound); }
@SuppressWarnings({"unchecked"}) public void generateConnectionTarget(JavaConnectionTarget target, LogicalConsumer consumer) { // Create an injectable for the consumer. Note in cases where the consumer is a method that is connected via an event stream and is used to receive // events rather than act as a setter for a direct connection, the injector will never be activated. Injectable injectable = new Injectable(InjectableType.CONSUMER, consumer.getUri().getFragment()); target.setInjectable(injectable); LogicalComponent<? extends JavaImplementation> component = (LogicalComponent<? extends JavaImplementation>) consumer.getParent(); URI uri = component.getUri(); target.setUri(uri); ServiceContract serviceContract = consumer.getDefinition().getServiceContract(); Class<?> interfaze = serviceContract.getInterfaceClass(); target.setServiceInterface(interfaze); InjectingComponentType type = component.getDefinition().getImplementation().getComponentType(); AccessibleObject object = type.getConsumerSite(consumer.getUri().getFragment()); if (object == null) { // programming error throw new Fabric3Exception("Consumer not found on: " + consumer.getUri()); } target.setConsumerSite(object); }
private void createConsumers(Component<?> definition, LogicalComponent<?> logicalComponent, ComponentType componentType) { for (Consumer<ComponentType> consumer : componentType.getConsumers().values()) { String name = consumer.getName(); URI consumerUri = logicalComponent.getUri().resolve('#' + name); LogicalConsumer logicalConsumer = new LogicalConsumer(consumerUri, consumer, logicalComponent); // producer is configured in the logicalComponent definition Consumer<Component> componentConsumer = definition.getConsumers().get(name); if (componentConsumer != null) { for (URI uri : componentConsumer.getSources()) { addSource(logicalConsumer, uri, logicalComponent); } } else { for (URI uri : consumer.getSources()) { addSource(logicalConsumer, uri, logicalComponent); } } logicalConsumer.setServiceContract(consumer.getServiceContract()); logicalComponent.addConsumer(logicalConsumer); } }
public void visitField(org.fabric3.api.annotation.Consumer annotation, Field field, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { TypeMapping typeMapping = context.getTypeMapping(implClass); Class<?> genericType = field.getType(); Type logicalParamType = typeMapping.getActualType(genericType); DataType dataType = createDataType(genericType, logicalParamType, typeMapping); String name = helper.getSiteName(field, annotation.value()); ServiceContract contract = null; if (contractProcessor != null) { Class<?> baseType = helper.getBaseType(genericType, typeMapping); contract = contractProcessor.introspect(baseType, implClass, context, componentType); } Consumer<ComponentType> consumer = new Consumer<>(name, dataType, contract); if (annotation.group().length() > 0){ consumer.setGroup(annotation.group()); } Class<?> clazz = field.getDeclaringClass(); processSources(annotation, consumer, field, clazz, context); FieldInjectionSite injectionSite = new FieldInjectionSite(field); componentType.add(consumer, injectionSite, field); }
private <T> LogicalConsumer createConsumer(Class<T> type, URI channelUri) { JavaServiceContract contract = introspector.introspect(type); LogicalCompositeComponent domain = lcm.getDomainComposite(); String root = domain.getUri().toString(); LogicalComponent<NonManagedImplementation> logicalComponent = createComponent(Object.class, domain, root); DataType dataType = new JavaType(type); Consumer consumer = new Consumer("consumer", dataType, true); int pos = counter.getAndIncrement(); LogicalConsumer logicalConsumer = new LogicalConsumer(URI.create(root + "/F3Synthetic#consumer" + pos), consumer, logicalComponent); logicalConsumer.setServiceContract(contract); logicalConsumer.addSource(channelUri); return logicalConsumer; }
private PhysicalChannelConnection generateLocalConnection(LogicalConsumer consumer, LogicalChannel channel, PhysicalConnectionTarget target, ClassLoader classLoader) { // the channel does not have bindings, which means it is a local channel // construct a local connection to the channel URI uri = channel.getUri(); PhysicalConnectionSource source = new ChannelSource(uri, ChannelSide.CONSUMER); source.setSequence(consumer.getDefinition().getSequence()); source.setClassLoader(classLoader); Class<?> type = getType(consumer); boolean bound = channel.isBound(); return new PhysicalChannelConnection(uri, consumer.getUri(), source, target, type, bound); }
/** * Returns the event type * * @return the event type */ public JavaType getType() { return (JavaType) super.getType(); } }
@SuppressWarnings({"unchecked"}) private PhysicalChannelConnection generateBoundConnection(LogicalConsumer consumer, LogicalChannel channel, DeliveryType deliveryType, ClassLoader classLoader) { // use the bindings on the channel to create a consumer binding configuration LogicalBinding<?> binding = channel.getBinding(); ConnectionBindingGenerator bindingGenerator = getGenerator(binding); PhysicalConnectionSource source = bindingGenerator.generateConnectionSource(consumer, binding, deliveryType); source.setSequence(consumer.getDefinition().getSequence()); source.setClassLoader(classLoader); URI uri = channel.getUri(); ChannelTarget target = new ChannelTarget(uri, ChannelSide.CONSUMER); target.setClassLoader(classLoader); Class<?> type = getType(consumer); return new PhysicalChannelConnection(uri, consumer.getUri(), source, target, type, true); }
private Class<?> getType(LogicalConsumer consumer) { Consumer<?> consumerDefinition = consumer.getDefinition(); return consumerDefinition.getType().getType(); }
@SuppressWarnings({"unchecked"}) private PhysicalChannelConnection generateBoundConnection(LogicalConsumer consumer, LogicalChannel channel, DeliveryType deliveryType, ClassLoader classLoader) { // use the bindings on the channel to create a consumer binding configuration LogicalBinding<?> binding = channel.getBinding(); ConnectionBindingGenerator bindingGenerator = getGenerator(binding); PhysicalConnectionSource source = bindingGenerator.generateConnectionSource(consumer, binding, deliveryType); source.setSequence(consumer.getDefinition().getSequence()); source.setClassLoader(classLoader); URI uri = channel.getUri(); ChannelTarget target = new ChannelTarget(uri, ChannelSide.CONSUMER); target.setClassLoader(classLoader); Class<?> type = getType(consumer); return new PhysicalChannelConnection(uri, consumer.getUri(), source, target, type, true); }
private Class<?> getType(LogicalConsumer consumer) { Consumer<?> consumerDefinition = consumer.getDefinition(); return consumerDefinition.getType().getType(); }