org.eclipse.microprofile.reactive.messaging.spi.Connector Java Examples

The following examples show how to use org.eclipse.microprofile.reactive.messaging.spi.Connector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurationDocWriter.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
public void generateIncomingDocumentation(Connector connector, List<ConnectorAttribute> commonAttributes,
        List<ConnectorAttribute> incomingAttributes)
        throws IOException {
    FileObject resource = environment.getFiler()
            .createResource(StandardLocation.CLASS_OUTPUT, "",
                    "META-INF/connector/" + connector.value() + "-incoming.adoc");
    resource.delete();
    try (PrintWriter out = new PrintWriter(resource.openWriter())) {
        out.println(".Incoming Attributes of the '" + connector.value() + "' connector");
        writeTableBegin(out);
        commonAttributes.forEach(att -> {
            if (!att.hiddenFromDocumentation()) {
                generateLine(att, out);
            }
        });
        incomingAttributes.forEach(att -> {
            if (!att.hiddenFromDocumentation()) {
                generateLine(att, out);
            }
        });
        out.println("|===");
    }
}
 
Example #2
Source File: ConfigurationDocWriter.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
public void generateOutgoingDocumentation(Connector connector, List<ConnectorAttribute> commonAttributes,
        List<ConnectorAttribute> incomingAttributes)
        throws IOException {
    FileObject resource = environment.getFiler()
            .createResource(StandardLocation.CLASS_OUTPUT, "",
                    "META-INF/connector/" + connector.value() + "-outgoing.adoc");
    resource.delete();

    // merge and sort the attributes
    List<ConnectorAttribute> list = new ArrayList<>(commonAttributes);
    list.addAll(incomingAttributes);
    list.sort(Comparator.comparing(ConnectorAttribute::name));

    try (PrintWriter out = new PrintWriter(resource.openWriter())) {
        out.println(".Outgoing Attributes of the '" + connector.value() + "' connector");
        writeTableBegin(out);
        list.forEach(att -> {
            if (!att.hiddenFromDocumentation()) {
                generateLine(att, out);
            }
        });
        out.println("|===");
    }
}
 
Example #3
Source File: ConfigurationClassWriter.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
public void generateAllClasses(Connector connector, String className, List<ConnectorAttribute> common,
        List<ConnectorAttribute> incoming, List<ConnectorAttribute> outgoing)
        throws IOException {
    CommonConfigurationClassWriter.generate(environment, connector, className, common);

    String packageName = getPackage(className);
    String incomingConfigClassName = getConfigClassName(className, "IncomingConfiguration");
    String outgoingConfigClassName = getConfigClassName(className, "OutgoingConfiguration");
    String parentClassName = getConfigClassName(className, "CommonConfiguration");
    String incomingConfigSimpleClassName = getSimpleClassName(incomingConfigClassName);
    String outgoingConfigSimpleClassName = getSimpleClassName(outgoingConfigClassName);
    String parentConfigSimpleClassName = getSimpleClassName(parentClassName);

    ClassWriter.log(
            "Generating incoming configuration for connector `%s`: %s", connector.value(), incomingConfigClassName);
    generate(incoming, packageName, incomingConfigClassName, incomingConfigSimpleClassName, parentConfigSimpleClassName,
            "incoming", connector.value());

    ClassWriter.log(
            "Generating outgoing configuration for connector `%s`: %s", connector.value(), outgoingConfigClassName);
    generate(outgoing, packageName, outgoingConfigClassName, outgoingConfigSimpleClassName, parentConfigSimpleClassName,
            "outgoing", connector.value());
}
 
Example #4
Source File: PubSubTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private PubSubConnector getConnector() {
    return container.select(PubSubConnector.class, new Connector() {
        @Override
        public Class<? extends Annotation> annotationType() {
            return Connector.class;
        }

        @Override
        public String value() {
            return PubSubConnector.CONNECTOR_NAME;
        }
    }).get();
}
 
Example #5
Source File: CommonConfigurationClassWriter.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
public static void generate(ProcessingEnvironment environment, Connector connector, String className,
        List<ConnectorAttribute> attributes) throws IOException {
    CommonConfigurationClassWriter writer = new CommonConfigurationClassWriter(environment);
    String packageName = ClassWriter.getPackage(className);
    String configClassName = ClassWriter.getConfigClassName(className, "CommonConfiguration");
    String simpleClassName = ClassWriter.getSimpleClassName(configClassName);
    ClassWriter.log(
            "Generating common configuration for connector `%s`: %s", connector.value(), configClassName);
    writer.generate(attributes, packageName, configClassName, simpleClassName, connector.value());
}
 
Example #6
Source File: ConnectorAttributeProcessor.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private Connector getConnector(Element annotatedElement) {
    Connector connector = annotatedElement.getAnnotation(Connector.class);
    if (connector == null) {
        throw new IllegalStateException(
                "Expecting the usage of `@ConnectorAttribute` on a class annotated with @Connector");
    }
    return connector;
}
 
Example #7
Source File: SmallRyeReactiveMessagingProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@BuildStep
AdditionalBeanBuildItem beans() {
    // We add the connector and channel qualifiers to make them part of the index.
    return new AdditionalBeanBuildItem(SmallRyeReactiveMessagingLifecycle.class, Connector.class,
            Channel.class, io.smallrye.reactive.messaging.annotations.Channel.class,
            QuarkusWorkerPoolRegistry.class);
}
 
Example #8
Source File: ConnectorAttributeProcessor.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Override
public boolean process(Set<? extends TypeElement> annotations,
        RoundEnvironment roundEnv) {

    if (invoked) {
        return true;
    }
    invoked = true;

    Set<? extends Element> annotated = roundEnv.getElementsAnnotatedWith(ConnectorAttributes.class);
    Set<? extends Element> others = roundEnv.getElementsAnnotatedWith(ConnectorAttribute.class);
    Set<Element> all = new LinkedHashSet<>();
    all.addAll(annotated);
    all.addAll(others);

    for (Element annotatedElement : all) {
        String className = annotatedElement.toString();
        Connector connector = getConnector(annotatedElement);
        ConnectorAttributes annotation = annotatedElement.getAnnotation(ConnectorAttributes.class);
        ConnectorAttribute[] attributes;
        if (annotation == null) {
            attributes = new ConnectorAttribute[] { annotatedElement.getAnnotation(ConnectorAttribute.class) };
        } else {
            attributes = annotation.value();
        }

        List<ConnectorAttribute> incomingAttributes = new ArrayList<>();
        List<ConnectorAttribute> outgoingAttributes = new ArrayList<>();
        List<ConnectorAttribute> commonAttributes = new ArrayList<>();

        for (ConnectorAttribute attribute : attributes) {
            addAttributeToList(commonAttributes, attribute, ConnectorAttribute.Direction.INCOMING_AND_OUTGOING);
            addAttributeToList(incomingAttributes, attribute, ConnectorAttribute.Direction.INCOMING);
            addAttributeToList(outgoingAttributes, attribute, ConnectorAttribute.Direction.OUTGOING);
        }

        validate(commonAttributes);
        validate(incomingAttributes);
        validate(outgoingAttributes);

        ConfigurationClassWriter classWriter = new ConfigurationClassWriter(processingEnv);
        ConfigurationDocWriter docWriter = new ConfigurationDocWriter(processingEnv);

        try {
            classWriter.generateAllClasses(connector, className, commonAttributes, incomingAttributes, outgoingAttributes);
            docWriter.generateIncomingDocumentation(connector, commonAttributes, incomingAttributes);
            docWriter.generateOutgoingDocumentation(connector, commonAttributes, outgoingAttributes);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    return true;
}