nifi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markap14 <...@git.apache.org>
Subject [GitHub] nifi pull request: NIFI-865 added initial support for AMQP publish...
Date Tue, 02 Feb 2016 17:11:38 GMT
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/200#discussion_r51600077
  
    --- Diff: nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/main/java/org/apache/nifi/amqp/processors/AbstractAMQPProcessor.java
---
    @@ -0,0 +1,204 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.nifi.amqp.processors;
    +
    +import java.io.IOException;
    +import java.lang.reflect.Field;
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +import org.apache.nifi.annotation.lifecycle.OnStopped;
    +import org.apache.nifi.components.PropertyDescriptor;
    +import org.apache.nifi.processor.AbstractProcessor;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processor.ProcessSession;
    +import org.apache.nifi.processor.Processor;
    +import org.apache.nifi.processor.exception.ProcessException;
    +import org.apache.nifi.processor.util.StandardValidators;
    +
    +import com.rabbitmq.client.Connection;
    +import com.rabbitmq.client.ConnectionFactory;
    +
    +/**
    + * Base processor that uses RabbitMQ client API
    + * (https://www.rabbitmq.com/api-guide.html) to rendezvous with AMQP-based
    + * messaging systems version 0.9.1
    + *
    + * @param <T> the type of {@link AMQPWorker}. Please see {@link AMQPPublisher}
    + *            and {@link AMQPConsumer}
    + */
    +abstract class AbstractAMQPProcessor<T extends AMQPWorker> extends AbstractProcessor
{
    +
    +    public static final PropertyDescriptor HOST = new PropertyDescriptor.Builder()
    +            .name("Host Name")
    +            .description("Network address of AMQP broker (e.g., localhost)")
    +            .required(true)
    +            .defaultValue("localhost")
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor PORT = new PropertyDescriptor.Builder()
    +            .name("Port")
    +            .description("Numeric value identifying Port of AMQP broker (e.g., 5671)")
    +            .required(true)
    +            .defaultValue("5672")
    +            .addValidator(StandardValidators.PORT_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor V_HOST = new PropertyDescriptor.Builder()
    +            .name("Virtual Host")
    +            .description("Virtual Host name which segregates AMQP system for enhanced
security.")
    +            .required(false)
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor USER = new PropertyDescriptor.Builder()
    +            .name("User Name")
    +            .description("User Name used for authentication and authorization.")
    +            .required(true)
    +            .defaultValue("guest")
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .build();
    +    public static final PropertyDescriptor PASSWORD = new PropertyDescriptor.Builder()
    +            .name("Password")
    +            .description("Password used for authentication and authorization.")
    +            .required(true)
    +            .defaultValue("guest")
    +            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +            .sensitive(true)
    +            .build();
    +    public static final PropertyDescriptor AMQP_VERSION = new PropertyDescriptor.Builder()
    +            .name("AMQP Version")
    +            .description("AMQP Version. Currently only supports AMQP v0.9.1.")
    +            .required(true)
    +            .allowableValues("0.9.1")
    +            .defaultValue("0.9.1")
    +            .build();
    +
    +    static List<PropertyDescriptor> descriptors = new ArrayList<>();
    +
    +    /*
    +     * Will ensure that list of PropertyDescriptors is build only once, since
    +     * all other lifecycle methods are invoked multiple times
    +     */
    +    static {
    +        Field[] fields = AbstractAMQPProcessor.class.getDeclaredFields();
    +        try {
    +            for (Field field : fields) {
    +                field.setAccessible(true);
    +                if (PropertyDescriptor.class.isAssignableFrom(field.getType())) {
    +                    descriptors.add((PropertyDescriptor) field.get(null));
    +                }
    +            }
    +        } catch (Exception e) {
    +            throw new IllegalStateException("Failed to build PropertyDescriptor list",
e);
    +        }
    +    }
    +
    +    protected volatile Connection amqpConnection;
    +
    +    protected volatile T targetResource;
    +
    +    /**
    +     * Will builds target resource ({@link AMQPPublisher} or
    +     * {@link AMQPConsumer}) upon first invocation and will delegate to the
    +     * implementation of
    +     * {@link #rendezvousWithAmqp(ProcessContext, ProcessSession)} method for
    +     * further processing.
    +     */
    +    @Override
    +    public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException
{
    +        synchronized (this) {
    +            this.buildTargetResource(context);
    +        }
    +        this.rendezvousWithAmqp(context, session);
    +    }
    +
    +    /**
    +     * Will close current AMQP connection.
    +     */
    +    @OnStopped
    +    public void close() {
    +        try {
    +            this.targetResource.close();
    --- End diff --
    
    If the call to createConnection() were to throw an Exception, both targetResource and
amqpConnection could be closed. Should check if these objects are null before calling close()


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message