public void visitMethod(Consumer annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { if (method.getParameterTypes().length > 1) { InvalidConsumerMethod failure = new InvalidConsumerMethod("Consumer method " + method + " has more than one parameter", method, componentType); context.addError(failure); return; } TypeMapping typeMapping = context.getTypeMapping(implClass); List<DataType<?>> types = introspectParameterTypes(method, typeMapping); // TODO handle policies String name = helper.getSiteName(method, annotation.value()); Signature signature = new Signature(method); ConsumerDefinition definition = new ConsumerDefinition(name, types); int sequence = annotation.sequence(); if (sequence < 0) { context.addError(new InvalidConsumerMethod("Sequence number cannot be negative: " + method, method, componentType)); } else { definition.setSequence(sequence); } componentType.add(definition, signature); }
private void createConsumers(ComponentDefinition<?> definition, LogicalComponent<?> component, ComponentType componentType) { for (ConsumerDefinition consumer : componentType.getConsumers().values()) { String name = consumer.getName(); URI consumerUri = component.getUri().resolve('#' + name); LogicalConsumer logicalConsumer = new LogicalConsumer(consumerUri, consumer, component); // producer is configured in the component definition ComponentConsumer componentConsumer = definition.getConsumers().get(name); if (componentConsumer != null) { logicalConsumer.addIntents(componentConsumer.getIntents()); // TODO refactor this: URIs should be resolved to channels by a separate service that also handles promotion for (URI uri : componentConsumer.getSources()) { if (uri.isAbsolute()) { LogicalComponent<?> domain = component.getParent(); while (domain.getParent() != null) { domain = domain.getParent(); } logicalConsumer.addSource(URI.create(domain.getUri().toString() + "/" + uri.getAuthority())); } else { logicalConsumer.addSource(URI.create(component.getParent().getUri().toString() + "/" + uri.toString())); } } } component.addConsumer(logicalConsumer); } }
private PhysicalEventStreamDefinition generateEventStream(LogicalConsumer consumer) { PhysicalEventStreamDefinition definition = new PhysicalEventStreamDefinition("default"); List<DataType<?>> types = consumer.getDefinition().getTypes(); boolean typed = false; boolean takesChannelEvent = false; for (DataType<?> dataType : types) { if (dataType instanceof JavaType) { // for now only support Java contracts if (!Object.class.equals(dataType.getLogical())) { typed = true; if (ChannelEvent.class.isAssignableFrom(dataType.getPhysical())) { takesChannelEvent = true; } } } definition.setChannelEvent(takesChannelEvent); definition.addEventType(dataType.getPhysical().getName()); } if (typed) { TypeEventFilterDefinition typeFilter = new TypeEventFilterDefinition(types); definition.addFilterDefinition(typeFilter); } return definition; }
private PhysicalChannelConnectionDefinition generateConsumerConnection(LogicalConsumer consumer, LogicalChannel channel, PhysicalConnectionTargetDefinition targetDefinition, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { // the channel does not have bindings, which means it is a local channel if (!channel.getZone().equals(consumer.getParent().getZone()) && !channel.isBound()) { String name = channel.getDefinition().getName(); throw new GenerationException("Binding not configured on a channel where the consumer is in a different zone: " + name); } // construct a local connection to the channel PhysicalConnectionSourceDefinition sourceDefinition = new ChannelSourceDefinition(channel.getUri(), ChannelSide.CONSUMER); sourceDefinition.setSequence(consumer.getDefinition().getSequence()); sourceDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }
@SuppressWarnings({"unchecked"}) private PhysicalChannelConnectionDefinition generateConsumerBinding(LogicalConsumer consumer, LogicalChannel channel, ChannelDeliveryType deliveryType, URI classLoaderId, PhysicalEventStreamDefinition eventStream) throws GenerationException { // use the bindings on the channel to create a consumer binding configuration LogicalBinding<?> binding = channel.getBinding(); ConnectionBindingGenerator bindingGenerator = getGenerator(binding); PhysicalConnectionSourceDefinition sourceDefinition = bindingGenerator.generateConnectionSource(consumer, binding, deliveryType); sourceDefinition.setSequence(consumer.getDefinition().getSequence()); sourceDefinition.setClassLoaderId(classLoaderId); ChannelTargetDefinition targetDefinition = new ChannelTargetDefinition(channel.getUri(), ChannelSide.CONSUMER); targetDefinition.setClassLoaderId(classLoaderId); return new PhysicalChannelConnectionDefinition(sourceDefinition, targetDefinition, eventStream); }