Java Code Examples for org.apache.nifi.flowfile.FlowFile#getLastQueueDate()

The following examples show how to use org.apache.nifi.flowfile.FlowFile#getLastQueueDate() . 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: WriteAheadRepositoryRecordSerde.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public void serializeEdit(final RepositoryRecord previousRecordState, final RepositoryRecord record, final DataOutputStream out, final boolean forceAttributesWritten) throws IOException {
    if (record.isMarkedForAbort()) {
        logger.warn("Repository Record {} is marked to be aborted; it will be persisted in the FlowFileRepository as a DELETE record", record);
        out.write(ACTION_DELETE);
        out.writeLong(getRecordIdentifier(record));
        serializeContentClaim(record.getCurrentClaim(), record.getCurrentClaimOffset(), out);
        return;
    }

    final UpdateType updateType = getUpdateType(record);

    if (updateType.equals(UpdateType.DELETE)) {
        out.write(ACTION_DELETE);
        out.writeLong(getRecordIdentifier(record));
        serializeContentClaim(record.getCurrentClaim(), record.getCurrentClaimOffset(), out);
        return;
    }

    // If there's a Destination Connection, that's the one that we want to associated with this record.
    // However, on restart, we will restore the FlowFile and set this connection to its "originalConnection".
    // If we then serialize the FlowFile again before it's transferred, it's important to allow this to happen,
    // so we use the originalConnection instead
    FlowFileQueue associatedQueue = record.getDestination();
    if (associatedQueue == null) {
        associatedQueue = record.getOriginalQueue();
    }

    if (updateType.equals(UpdateType.SWAP_OUT)) {
        out.write(ACTION_SWAPPED_OUT);
        out.writeLong(getRecordIdentifier(record));
        out.writeUTF(associatedQueue.getIdentifier());
        out.writeUTF(getLocation(record));
        return;
    }

    final FlowFile flowFile = record.getCurrent();
    final ContentClaim claim = record.getCurrentClaim();

    switch (updateType) {
        case UPDATE:
            out.write(ACTION_UPDATE);
            break;
        case CREATE:
            out.write(ACTION_CREATE);
            break;
        case SWAP_IN:
            out.write(ACTION_SWAPPED_IN);
            break;
        default:
            throw new AssertionError();
    }

    out.writeLong(getRecordIdentifier(record));
    out.writeLong(flowFile.getEntryDate());
    out.writeLong(flowFile.getLineageStartDate());
    out.writeLong(flowFile.getLineageStartIndex());

    final Long queueDate = flowFile.getLastQueueDate();
    out.writeLong(queueDate == null ? System.currentTimeMillis() : queueDate);
    out.writeLong(flowFile.getQueueDateIndex());
    out.writeLong(flowFile.getSize());

    if (associatedQueue == null) {
        logger.warn("{} Repository Record {} has no Connection associated with it; it will be destroyed on restart",
            new Object[] {this, record});
        writeString("", out);
    } else {
        writeString(associatedQueue.getIdentifier(), out);
    }

    serializeContentClaim(claim, record.getCurrentClaimOffset(), out);

    if (forceAttributesWritten || record.isAttributesChanged() || updateType == UpdateType.CREATE || updateType == UpdateType.SWAP_IN) {
        out.write(1);   // indicate attributes changed
        final Map<String, String> attributes = flowFile.getAttributes();
        out.writeInt(attributes.size());
        for (final Map.Entry<String, String> entry : attributes.entrySet()) {
            writeString(entry.getKey(), out);
            writeString(entry.getValue(), out);
        }
    } else {
        out.write(0);   // indicate attributes did not change
    }

    if (updateType == UpdateType.SWAP_IN) {
        out.writeUTF(record.getSwapLocation());
    }
}
 
Example 2
Source File: StandardFlowFileQueue.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private FlowFileSummary summarize(final FlowFile flowFile, final int position) {
    // extract all of the information that we care about into new variables rather than just
    // wrapping the FlowFile object with a FlowFileSummary object. We do this because we want to
    // be able to hold many FlowFileSummary objects in memory and if we just wrap the FlowFile object,
    // we will end up holding the entire FlowFile (including all Attributes) in the Java heap as well,
    // which can be problematic if we expect them to be swapped out.
    final String uuid = flowFile.getAttribute(CoreAttributes.UUID.key());
    final String filename = flowFile.getAttribute(CoreAttributes.FILENAME.key());
    final long size = flowFile.getSize();
    final Long lastQueuedTime = flowFile.getLastQueueDate();
    final long lineageStart = flowFile.getLineageStartDate();
    final boolean penalized = flowFile.isPenalized();

    return new FlowFileSummary() {
        @Override
        public String getUuid() {
            return uuid;
        }

        @Override
        public String getFilename() {
            return filename;
        }

        @Override
        public int getPosition() {
            return position;
        }

        @Override
        public long getSize() {
            return size;
        }

        @Override
        public long getLastQueuedTime() {
            return lastQueuedTime == null ? 0L : lastQueuedTime;
        }

        @Override
        public long getLineageStartDate() {
            return lineageStart;
        }

        @Override
        public boolean isPenalized() {
            return penalized;
        }
    };
}
 
Example 3
Source File: WriteAheadRepositoryRecordSerde.java    From nifi with Apache License 2.0 4 votes vote down vote up
public void serializeEdit(final SerializedRepositoryRecord previousRecordState, final SerializedRepositoryRecord record, final DataOutputStream out, final boolean forceAttributesWritten)
        throws IOException {
    if (record.isMarkedForAbort()) {
        logger.warn("Repository Record {} is marked to be aborted; it will be persisted in the FlowFileRepository as a DELETE record", record);
        out.write(ACTION_DELETE);
        out.writeLong(getRecordIdentifier(record));
        serializeContentClaim(record.getContentClaim(), record.getClaimOffset(), out);
        return;
    }

    final UpdateType updateType = getUpdateType(record);

    if (updateType.equals(UpdateType.DELETE)) {
        out.write(ACTION_DELETE);
        out.writeLong(getRecordIdentifier(record));
        serializeContentClaim(record.getContentClaim(), record.getClaimOffset(), out);
        return;
    }

    // If there's a Destination Connection, that's the one that we want to associated with this record.
    // However, on restart, we will restore the FlowFile and set this connection to its "originalConnection".
    // If we then serialize the FlowFile again before it's transferred, it's important to allow this to happen,
    // so we use the originalConnection instead
    final String associatedQueueId = record.getQueueIdentifier();

    if (updateType.equals(UpdateType.SWAP_OUT)) {
        out.write(ACTION_SWAPPED_OUT);
        out.writeLong(getRecordIdentifier(record));
        out.writeUTF(associatedQueueId);
        out.writeUTF(getLocation(record));
        return;
    }

    final FlowFile flowFile = record.getFlowFileRecord();
    final ContentClaim claim = record.getContentClaim();

    switch (updateType) {
        case UPDATE:
            out.write(ACTION_UPDATE);
            break;
        case CREATE:
            out.write(ACTION_CREATE);
            break;
        case SWAP_IN:
            out.write(ACTION_SWAPPED_IN);
            break;
        default:
            throw new AssertionError();
    }

    out.writeLong(getRecordIdentifier(record));
    out.writeLong(flowFile.getEntryDate());
    out.writeLong(flowFile.getLineageStartDate());
    out.writeLong(flowFile.getLineageStartIndex());

    final Long queueDate = flowFile.getLastQueueDate();
    out.writeLong(queueDate == null ? System.currentTimeMillis() : queueDate);
    out.writeLong(flowFile.getQueueDateIndex());
    out.writeLong(flowFile.getSize());

    if (associatedQueueId == null) {
        logger.warn("{} Repository Record {} has no Connection associated with it; it will be destroyed on restart",
            new Object[] {this, record});
        writeString("", out);
    } else {
        writeString(associatedQueueId, out);
    }

    serializeContentClaim(claim, record.getClaimOffset(), out);

    if (forceAttributesWritten || record.isAttributesChanged() || updateType == UpdateType.CREATE || updateType == UpdateType.SWAP_IN) {
        out.write(1);   // indicate attributes changed
        final Map<String, String> attributes = flowFile.getAttributes();
        out.writeInt(attributes.size());
        for (final Map.Entry<String, String> entry : attributes.entrySet()) {
            writeString(entry.getKey(), out);
            writeString(entry.getValue(), out);
        }
    } else {
        out.write(0);   // indicate attributes did not change
    }

    if (updateType == UpdateType.SWAP_IN) {
        out.writeUTF(record.getSwapLocation());
    }
}