Java Code Examples for org.apache.nifi.processor.Relationship#equals()

The following examples show how to use org.apache.nifi.processor.Relationship#equals() . 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: StandardProcessorNode.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * @param relationshipName
 *            name
 * @return the relationship for this nodes processor for the given name or
 *         creates a new relationship for the given name
 */
@Override
public Relationship getRelationship(final String relationshipName) {
    final Relationship specRel = new Relationship.Builder().name(relationshipName).build();
    Relationship returnRel = specRel;

    final Set<Relationship> relationships;
    try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(processor.getClass(), processor.getIdentifier())) {
        relationships = processor.getRelationships();
    }

    for (final Relationship rel : relationships) {
        if (rel.equals(specRel)) {
            returnRel = rel;
            break;
        }
    }
    return returnRel;
}
 
Example 2
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * @param relationshipName
 *            name
 * @return the relationship for this nodes processor for the given name or
 *         creates a new relationship for the given name
 */
@Override
public Relationship getRelationship(final String relationshipName) {
    final Relationship specRel = new Relationship.Builder().name(relationshipName).build();
    Relationship returnRel = specRel;

    final Set<Relationship> relationships;
    final Processor processor = processorRef.get().getProcessor();
    try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(getExtensionManager(), processor.getClass(), processor.getIdentifier())) {
        relationships = processor.getRelationships();
    }

    for (final Relationship rel : relationships) {
        if (rel.equals(specRel)) {
            returnRel = rel;
            break;
        }
    }
    return returnRel;
}
 
Example 3
Source File: MockProcessSession.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that all FlowFiles that were transferred were transferred to the
 * given relationship
 *
 * @param relationship to validate
 */
public void assertAllFlowFilesTransferred(final Relationship relationship) {
    for (final Map.Entry<Relationship, List<MockFlowFile>> entry : transferMap.entrySet()) {
        final Relationship rel = entry.getKey();
        final List<MockFlowFile> flowFiles = entry.getValue();

        if (!rel.equals(relationship) && flowFiles != null && !flowFiles.isEmpty()) {
            Assert.fail("Expected all Transferred FlowFiles to go to " + relationship + " but " + flowFiles.size() + " were routed to " + rel);
        }
    }
}
 
Example 4
Source File: MockProcessSession.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that all FlowFiles that were transferred in the given relationship
 * are compliant with the given validator.
 *
 * @param validator validator to use
 */
public void assertAllFlowFiles(Relationship relationship, FlowFileValidator validator) {
    for (final Map.Entry<Relationship, List<MockFlowFile>> entry : transferMap.entrySet()) {
        final List<MockFlowFile> flowFiles = entry.getValue();
        final Relationship rel = entry.getKey();
        for (MockFlowFile mockFlowFile : flowFiles) {
            if(rel.equals(relationship)) {
                validator.assertFlowFile(mockFlowFile);
            }
        }
    }
}
 
Example 5
Source File: AbstractPort.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void addConnection(final Connection connection) throws IllegalArgumentException {
    writeLock.lock();
    try {
        if (!requireNonNull(connection).getSource().equals(this)) {
            if (connection.getDestination().equals(this)) {
                // don't add the connection twice. This may occur if we have a self-loop because we will be told
                // to add the connection once because we are the source and again because we are the destination.
                if (!incomingConnections.contains(connection)) {
                    incomingConnections.add(connection);
                }

                return;
            } else {
                throw new IllegalArgumentException("Cannot add a connection to a LocalPort for which the LocalPort is neither the Source nor the Destination");
            }
        }

        for (final Relationship relationship : connection.getRelationships()) {
            if (!relationship.equals(PORT_RELATIONSHIP)) {
                throw new IllegalArgumentException("No relationship with name " + relationship + " exists for Local Ports");
            }
        }

        // don't add the connection twice. This may occur if we have a self-loop because we will be told
        // to add the connection once because we are the source and again because we are the destination.
        if (!outgoingConnections.contains(connection)) {
            outgoingConnections.add(connection);
        }
    } finally {
        writeLock.unlock();
    }
}
 
Example 6
Source File: AbstractPort.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Connection> getConnections(final Relationship relationship) {
    readLock.lock();
    try {
        if (relationship.equals(PORT_RELATIONSHIP)) {
            return Collections.unmodifiableSet(outgoingConnections);
        }

        throw new IllegalArgumentException("No relationship with name " + relationship.getName() + " exists for Local Ports");
    } finally {
        readLock.unlock();
    }
}
 
Example 7
Source File: StandardFunnel.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void addConnection(final Connection connection) throws IllegalArgumentException {
    writeLock.lock();
    try {
        if (!requireNonNull(connection).getSource().equals(this) && !connection.getDestination().equals(this)) {
            throw new IllegalArgumentException("Cannot add a connection to a Funnel for which the Funnel is neither the Source nor the Destination");
        }
        if (connection.getSource().equals(this) && connection.getDestination().equals(this)) {
            throw new IllegalArgumentException("Cannot add a connection from a Funnel back to itself");
        }

        if (connection.getDestination().equals(this)) {
            // don't add the connection twice. This may occur if we have a self-loop because we will be told
            // to add the connection once because we are the source and again because we are the destination.
            if (!incomingConnections.contains(connection)) {
                incomingConnections.add(connection);
            }
        }

        if (connection.getSource().equals(this)) {
            // don't add the connection twice. This may occur if we have a self-loop because we will be told
            // to add the connection once because we are the source and again because we are the destination.
            if (!outgoingConnections.contains(connection)) {
                for (final Relationship relationship : connection.getRelationships()) {
                    if (!relationship.equals(Relationship.ANONYMOUS)) {
                        throw new IllegalArgumentException("No relationship with name " + relationship + " exists for Funnels");
                    }
                }

                outgoingConnections.add(connection);
            }
        }
    } finally {
        writeLock.unlock();
    }
}
 
Example 8
Source File: StandardFunnel.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Connection> getConnections(final Relationship relationship) {
    readLock.lock();
    try {
        if (relationship.equals(Relationship.ANONYMOUS)) {
            return Collections.unmodifiableSet(outgoingConnections);
        }

        throw new IllegalArgumentException("No relationship with name " + relationship.getName() + " exists for Funnels");
    } finally {
        readLock.unlock();
    }
}
 
Example 9
Source File: MockProcessSession.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that all FlowFiles that were transferred were transferred to the
 * given relationship
 *
 * @param relationship to validate
 */
public void assertAllFlowFilesTransferred(final Relationship relationship) {
    for (final Map.Entry<Relationship, List<MockFlowFile>> entry : transferMap.entrySet()) {
        final Relationship rel = entry.getKey();
        final List<MockFlowFile> flowFiles = entry.getValue();

        if (!rel.equals(relationship) && flowFiles != null && !flowFiles.isEmpty()) {
            Assert.fail("Expected all Transferred FlowFiles to go to " + relationship + " but " + flowFiles.size() + " were routed to " + rel);
        }
    }
}
 
Example 10
Source File: MockProcessSession.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that all FlowFiles that were transferred in the given relationship
 * are compliant with the given validator.
 *
 * @param validator validator to use
 */
public void assertAllFlowFiles(Relationship relationship, FlowFileValidator validator) {
    for (final Map.Entry<Relationship, List<MockFlowFile>> entry : transferMap.entrySet()) {
        final List<MockFlowFile> flowFiles = entry.getValue();
        final Relationship rel = entry.getKey();
        for (MockFlowFile mockFlowFile : flowFiles) {
            if(rel.equals(relationship)) {
                validator.assertFlowFile(mockFlowFile);
            }
        }
    }
}
 
Example 11
Source File: AbstractPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void addConnection(final Connection connection) throws IllegalArgumentException {
    writeLock.lock();
    try {
        if (!requireNonNull(connection).getSource().equals(this)) {
            if (connection.getDestination().equals(this)) {
                // don't add the connection twice. This may occur if we have a self-loop because we will be told
                // to add the connection once because we are the source and again because we are the destination.
                if (!incomingConnections.contains(connection)) {
                    incomingConnections.add(connection);
                }

                return;
            } else {
                throw new IllegalArgumentException("Cannot add a connection to a LocalPort for which the LocalPort is neither the Source nor the Destination");
            }
        }

        for (final Relationship relationship : connection.getRelationships()) {
            if (!relationship.equals(PORT_RELATIONSHIP)) {
                throw new IllegalArgumentException("No relationship with name " + relationship + " exists for Local Ports");
            }
        }

        // don't add the connection twice. This may occur if we have a self-loop because we will be told
        // to add the connection once because we are the source and again because we are the destination.
        if (!outgoingConnections.contains(connection)) {
            outgoingConnections.add(connection);
        }
    } finally {
        writeLock.unlock();
    }
}
 
Example 12
Source File: AbstractPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Connection> getConnections(final Relationship relationship) {
    readLock.lock();
    try {
        if (relationship.equals(PORT_RELATIONSHIP)) {
            return Collections.unmodifiableSet(outgoingConnections);
        }

        throw new IllegalArgumentException("No relationship with name " + relationship.getName() + " exists for Local Ports");
    } finally {
        readLock.unlock();
    }
}
 
Example 13
Source File: StandardFunnel.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void addConnection(final Connection connection) throws IllegalArgumentException {
    writeLock.lock();
    try {
        if (!requireNonNull(connection).getSource().equals(this) && !connection.getDestination().equals(this)) {
            throw new IllegalArgumentException("Cannot add a connection to a Funnel for which the Funnel is neither the Source nor the Destination");
        }
        if (connection.getSource().equals(this) && connection.getDestination().equals(this)) {
            throw new IllegalArgumentException("Cannot add a connection from a Funnel back to itself");
        }

        if (connection.getDestination().equals(this)) {
            // don't add the connection twice. This may occur if we have a self-loop because we will be told
            // to add the connection once because we are the source and again because we are the destination.
            if (!incomingConnections.contains(connection)) {
                incomingConnections.add(connection);
            }
        }

        if (connection.getSource().equals(this)) {
            // don't add the connection twice. This may occur if we have a self-loop because we will be told
            // to add the connection once because we are the source and again because we are the destination.
            if (!outgoingConnections.contains(connection)) {
                for (final Relationship relationship : connection.getRelationships()) {
                    if (!relationship.equals(Relationship.ANONYMOUS)) {
                        throw new IllegalArgumentException("No relationship with name " + relationship + " exists for Funnels");
                    }
                }

                outgoingConnections.add(connection);
            }
        }
    } finally {
        writeLock.unlock();
    }
}
 
Example 14
Source File: StandardFunnel.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Set<Connection> getConnections(final Relationship relationship) {
    readLock.lock();
    try {
        if (relationship.equals(Relationship.ANONYMOUS)) {
            return Collections.unmodifiableSet(outgoingConnections);
        }

        throw new IllegalArgumentException("No relationship with name " + relationship.getName() + " exists for Funnels");
    } finally {
        readLock.unlock();
    }
}