Java Code Examples for org.apache.nifi.util.RingBuffer#asList()

The following examples show how to use org.apache.nifi.util.RingBuffer#asList() . 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: TestRingBuffer.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsList() {
    final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10);

    final List<Integer> emptyList = ringBuffer.asList();
    assertTrue(emptyList.isEmpty());

    for (int i = 0; i < 3; i++) {
        ringBuffer.add(i);
    }

    List<Integer> list = ringBuffer.asList();
    assertEquals(3, list.size());
    for (int i = 0; i < 3; i++) {
        assertEquals(Integer.valueOf(i), list.get(i));
    }

    for (int i = 3; i < 10; i++) {
        ringBuffer.add(i);
    }

    list = ringBuffer.asList();
    assertEquals(10, list.size());
    for (int i = 0; i < 10; i++) {
        assertEquals(Integer.valueOf(i), list.get(i));
    }
}
 
Example 2
Source File: LatestEventsPerProcessorQuery.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<List<Long>> evaluate(final Query query) {
    if (query.getMaxResults() > 1000) {
        // If query max results > 1000 then we know we don't have enough results. So just return empty.
        return Optional.empty();
    }

    final List<SearchTerm> terms = query.getSearchTerms();
    if (terms.size() != 1) {
        return Optional.empty();
    }

    final SearchTerm term = terms.get(0);
    if (!COMPONENT_ID_FIELD_NAME.equals(term.getSearchableField().getSearchableFieldName())) {
        return Optional.empty();
    }

    if (query.getEndDate() != null || query.getStartDate() != null) {
        return Optional.empty();
    }

    final RingBuffer<Long> ringBuffer = latestRecords.get(term.getValue());
    if (ringBuffer == null || ringBuffer.getSize() < query.getMaxResults()) {
        return Optional.empty();
    }

    List<Long> eventIds = ringBuffer.asList();
    if (eventIds.size() > query.getMaxResults()) {
        eventIds = eventIds.subList(0, query.getMaxResults());
    }

    return Optional.of(eventIds);
}
 
Example 3
Source File: TestRingBuffer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAsList() {
    final RingBuffer<Integer> ringBuffer = new RingBuffer<>(10);

    final List<Integer> emptyList = ringBuffer.asList();
    assertTrue(emptyList.isEmpty());

    for (int i = 0; i < 3; i++) {
        ringBuffer.add(i);
    }

    List<Integer> list = ringBuffer.asList();
    assertEquals(3, list.size());
    for (int i = 0; i < 3; i++) {
        assertEquals(Integer.valueOf(i), list.get(i));
    }

    for (int i = 3; i < 10; i++) {
        ringBuffer.add(i);
    }

    list = ringBuffer.asList();
    assertEquals(10, list.size());
    for (int i = 0; i < 10; i++) {
        assertEquals(Integer.valueOf(i), list.get(i));
    }
}
 
Example 4
Source File: LatestEventsPerProcessorQuery.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Optional<List<Long>> evaluate(final Query query) {
    if (query.getMaxResults() > 1000) {
        // If query max results > 1000 then we know we don't have enough results. So just return empty.
        return Optional.empty();
    }

    final List<SearchTerm> terms = query.getSearchTerms();
    if (terms.size() != 1) {
        return Optional.empty();
    }

    final SearchTerm term = terms.get(0);
    if (!COMPONENT_ID_FIELD_NAME.equals(term.getSearchableField().getSearchableFieldName())) {
        return Optional.empty();
    }

    if (query.getEndDate() != null || query.getStartDate() != null) {
        return Optional.empty();
    }

    final RingBuffer<Long> ringBuffer = latestRecords.get(term.getValue());
    if (ringBuffer == null || ringBuffer.getSize() < query.getMaxResults()) {
        return Optional.empty();
    }

    List<Long> eventIds = ringBuffer.asList();
    if (eventIds.size() > query.getMaxResults()) {
        eventIds = eventIds.subList(0, query.getMaxResults());
    }

    return Optional.of(eventIds);
}