Ejemplo n.º 1
0
  @Override
  public void addConnection(final Connection connection) {
    Objects.requireNonNull(connection, "connection cannot be null");

    if (!connection.getSource().equals(this) && !connection.getDestination().equals(this)) {
      throw new IllegalStateException(
          "Cannot a connection to a ProcessorNode for which the ProcessorNode is neither the Source nor the Destination");
    }

    writeLock.lock();
    try {
      List<Connection> updatedIncoming = null;
      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.
        final List<Connection> incomingConnections = incomingConnectionsRef.get();
        updatedIncoming = new ArrayList<>(incomingConnections);
        if (!updatedIncoming.contains(connection)) {
          updatedIncoming.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 (!destinations.containsKey(connection)) {
          for (final Relationship relationship : connection.getRelationships()) {
            final Relationship rel = getRelationship(relationship.getName());
            Set<Connection> set = connections.get(rel);
            if (set == null) {
              set = new HashSet<>();
              connections.put(rel, set);
            }

            set.add(connection);

            destinations.put(connection, connection.getDestination());
          }

          final Set<Relationship> autoTerminated = this.undefinedRelationshipsToTerminate.get();
          if (autoTerminated != null) {
            autoTerminated.removeAll(connection.getRelationships());
            this.undefinedRelationshipsToTerminate.set(autoTerminated);
          }
        }
      }

      if (updatedIncoming != null) {
        incomingConnectionsRef.set(Collections.unmodifiableList(updatedIncoming));
      }
    } finally {
      writeLock.unlock();
    }
  }
Ejemplo n.º 2
0
  @Override
  public void verifyCanDelete(final boolean ignoreConnections) {
    readLock.lock();
    try {
      if (isRunning()) {
        throw new IllegalStateException(this + " is running");
      }

      if (!ignoreConnections) {
        for (final Set<Connection> connectionSet : connections.values()) {
          for (final Connection connection : connectionSet) {
            connection.verifyCanDelete();
          }
        }

        for (final Connection connection : incomingConnectionsRef.get()) {
          if (connection.getSource().equals(this)) {
            connection.verifyCanDelete();
          } else {
            throw new IllegalStateException(this + " is the destination of another component");
          }
        }
      }
    } finally {
      readLock.unlock();
    }
  }
Ejemplo n.º 3
0
  List<Connection> getIncomingNonLoopConnections() {
    final List<Connection> connections = getIncomingConnections();
    final List<Connection> nonLoopConnections = new ArrayList<>(connections.size());
    for (final Connection connection : connections) {
      if (!connection.getSource().equals(this)) {
        nonLoopConnections.add(connection);
      }
    }

    return nonLoopConnections;
  }
  private void addConnection(final Element parentElement, final Connection connection) {
    final Document doc = parentElement.getOwnerDocument();
    final Element element = doc.createElement("connection");
    parentElement.appendChild(element);
    addTextElement(element, "id", connection.getIdentifier());
    addTextElement(element, "name", connection.getName());

    final Element bendPointsElement = doc.createElement("bendPoints");
    element.appendChild(bendPointsElement);
    for (final Position bendPoint : connection.getBendPoints()) {
      addPosition(bendPointsElement, bendPoint, "bendPoint");
    }

    addTextElement(element, "labelIndex", connection.getLabelIndex());
    addTextElement(element, "zIndex", connection.getZIndex());

    final String sourceId = connection.getSource().getIdentifier();
    final ConnectableType sourceType = connection.getSource().getConnectableType();
    final String sourceGroupId;
    if (sourceType == ConnectableType.REMOTE_OUTPUT_PORT) {
      sourceGroupId =
          ((RemoteGroupPort) connection.getSource()).getRemoteProcessGroup().getIdentifier();
    } else {
      sourceGroupId = connection.getSource().getProcessGroup().getIdentifier();
    }

    final ConnectableType destinationType = connection.getDestination().getConnectableType();
    final String destinationId = connection.getDestination().getIdentifier();
    final String destinationGroupId;
    if (destinationType == ConnectableType.REMOTE_INPUT_PORT) {
      destinationGroupId =
          ((RemoteGroupPort) connection.getDestination()).getRemoteProcessGroup().getIdentifier();
    } else {
      destinationGroupId = connection.getDestination().getProcessGroup().getIdentifier();
    }

    addTextElement(element, "sourceId", sourceId);
    addTextElement(element, "sourceGroupId", sourceGroupId);
    addTextElement(element, "sourceType", sourceType.toString());

    addTextElement(element, "destinationId", destinationId);
    addTextElement(element, "destinationGroupId", destinationGroupId);
    addTextElement(element, "destinationType", destinationType.toString());

    for (final Relationship relationship : connection.getRelationships()) {
      addTextElement(element, "relationship", relationship.getName());
    }

    addTextElement(
        element,
        "maxWorkQueueSize",
        connection.getFlowFileQueue().getBackPressureObjectThreshold());
    addTextElement(
        element,
        "maxWorkQueueDataSize",
        connection.getFlowFileQueue().getBackPressureDataSizeThreshold());

    addTextElement(
        element, "flowFileExpiration", connection.getFlowFileQueue().getFlowFileExpiration());
    for (final FlowFilePrioritizer comparator : connection.getFlowFileQueue().getPriorities()) {
      final String className = comparator.getClass().getCanonicalName();
      addTextElement(element, "queuePrioritizerClass", className);
    }

    parentElement.appendChild(element);
  }