当前位置: 首页>>代码示例>>Java>>正文


Java KeyValueIterator.hasNext方法代码示例

本文整理汇总了Java中org.apache.kafka.streams.state.KeyValueIterator.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java KeyValueIterator.hasNext方法的具体用法?Java KeyValueIterator.hasNext怎么用?Java KeyValueIterator.hasNext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.kafka.streams.state.KeyValueIterator的用法示例。


在下文中一共展示了KeyValueIterator.hasNext方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocalMetrics

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
/**
 * Query local state store to extract metrics
 *
 * @return local Metrics
 */
private Metrics getLocalMetrics() {
    HostInfo thisInstance = GlobalAppState.getInstance().getHostPortInfo();
    KafkaStreams ks = GlobalAppState.getInstance().getKafkaStreams();

    String source = thisInstance.host() + ":" + thisInstance.port();
    Metrics localMetrics = new Metrics();

    ReadOnlyKeyValueStore<String, Double> averageStore = ks
            .store(storeName,
                    QueryableStoreTypes.<String, Double>keyValueStore());

    LOGGER.log(Level.INFO, "Entries in store {0}", averageStore.approximateNumEntries());
    KeyValueIterator<String, Double> storeIterator = averageStore.all();

    while (storeIterator.hasNext()) {
        KeyValue<String, Double> kv = storeIterator.next();
        localMetrics.add(source, kv.key, String.valueOf(kv.value));

    }
    LOGGER.log(Level.INFO, "Local store state {0}", localMetrics);
    return localMetrics;
}
 
开发者ID:abhirockzz,项目名称:docker-kafka-streams,代码行数:28,代码来源:MetricsResource.java

示例2: hasNextCondition

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
@Override
public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) {
    return new HasNextCondition() {
        @Override
        public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) {
            while (iterator.hasNext()) {
                final Bytes bytes = iterator.peekNextKey();
                final Bytes keyBytes = WindowStoreUtils.bytesKeyFromBinaryKey(bytes.get());
                final long time = WindowStoreUtils.timestampFromBinaryKey(bytes.get());
                if (keyBytes.compareTo(binaryKeyFrom) >= 0
                    && keyBytes.compareTo(binaryKeyTo) <= 0
                    && time >= from
                    && time <= to) {
                    return true;
                }
                iterator.next();
            }
            return false;
        }
    };
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:22,代码来源:WindowKeySchema.java

示例3: hasNextCondition

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
@Override
public HasNextCondition hasNextCondition(final Bytes binaryKeyFrom, final Bytes binaryKeyTo, final long from, final long to) {
    return new HasNextCondition() {
        @Override
        public boolean hasNext(final KeyValueIterator<Bytes, ?> iterator) {
            while (iterator.hasNext()) {
                final Bytes bytes = iterator.peekNextKey();
                final Windowed<Bytes> windowedKey = SessionKeySerde.fromBytes(bytes);
                if (windowedKey.key().compareTo(binaryKeyFrom) >= 0
                    && windowedKey.key().compareTo(binaryKeyTo) <= 0
                    && windowedKey.window().end() >= from
                    && windowedKey.window().start() <= to) {
                    return true;
                }
                iterator.next();
            }
            return false;
        }
    };
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:21,代码来源:SessionKeySchema.java

示例4: fetch

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
private KeyValueIterator<Windowed<K>, V> fetch(Fetcher<K, V> fetcher) {
    final List<ReadOnlySessionStore<K, V>> stores = storeProvider.stores(storeName, queryableStoreType);
    for (final ReadOnlySessionStore<K, V> store : stores) {
        try {
            final KeyValueIterator<Windowed<K>, V> result = fetcher.fetch(store);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException ise) {
            throw new InvalidStateStoreException("State store  [" + storeName + "] is not available anymore" +
                                                 " and may have been migrated to another instance; " +
                                                 "please re-discover its location from the state metadata.");
        }
    }
    return KeyValueIterators.emptyIterator();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:19,代码来源:CompositeReadOnlySessionStore.java

示例5: verifyStateStore

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
private void verifyStateStore(final KafkaStreams streams, final Set<KeyValue<Long, Long>> expectedStoreContent) {
    ReadOnlyKeyValueStore<Long, Long> store = null;

    final long maxWaitingTime = System.currentTimeMillis() + 300000L;
    while (System.currentTimeMillis() < maxWaitingTime) {
        try {
            store = streams.store(storeName, QueryableStoreTypes.<Long, Long>keyValueStore());
            break;
        } catch (final InvalidStateStoreException okJustRetry) {
            try {
                Thread.sleep(5000L);
            } catch (final Exception ignore) { }
        }
    }

    final KeyValueIterator<Long, Long> it = store.all();
    while (it.hasNext()) {
        assertTrue(expectedStoreContent.remove(it.next()));
    }

    assertTrue(expectedStoreContent.isEmpty());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:23,代码来源:EosIntegrationTest.java

示例6: punctuate

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
@Override
public void punctuate(long timestamp) {
    KeyValueIterator<Long, List<OrderGoods>> iter = this.kvStore.all();

    while (iter.hasNext()) {
        KeyValue<Long, List<OrderGoods>> entry = (KeyValue<Long, List<OrderGoods>>) iter.next();
        context.forward(entry.key, entry.value.toString());
    }

    iter.close();
    context.commit();
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:13,代码来源:GoodOrderProcessor.java

示例7: toList

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
static List<KeyValue<Windowed<String>, Long>> toList(final KeyValueIterator<Windowed<String>, Long> iterator) {
    final List<KeyValue<Windowed<String>, Long>> results = new ArrayList<>();
    while (iterator.hasNext()) {
        results.add(iterator.next());
    }
    return results;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:8,代码来源:RocksDBSessionStoreTest.java

示例8: shouldIterateAllStoredItems

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
@Test
public void shouldIterateAllStoredItems() throws Exception {
    int items = addItemsToCache();
    final KeyValueIterator<String, String> all = store.all();
    final List<String> results = new ArrayList<>();
    while (all.hasNext()) {
        results.add(all.next().key);
    }
    assertEquals(items, results.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:CachingKeyValueStoreTest.java

示例9: shouldIterateOverRange

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
@Test
public void shouldIterateOverRange() throws Exception {
    int items = addItemsToCache();
    final KeyValueIterator<String, String> range = store.range(String.valueOf(0), String.valueOf(items));
    final List<String> results = new ArrayList<>();
    while (range.hasNext()) {
        results.add(range.next().key);
    }
    assertEquals(items, results.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:CachingKeyValueStoreTest.java

示例10: toList

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
private List<KeyValue<Windowed<String>, Long>> toList(final KeyValueIterator<Bytes, byte[]> iterator) {
    final List<KeyValue<Windowed<String>, Long>> results = new ArrayList<>();
    while (iterator.hasNext()) {
        final KeyValue<Bytes, byte[]> next = iterator.next();
        final KeyValue<Windowed<String>, Long> deserialized
                = KeyValue.pair(SessionKeySerde.from(next.key.get(), Serdes.String().deserializer(), "dummy"), Serdes.Long().deserializer().deserialize("", next.value));
        results.add(deserialized);
    }
    return results;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:11,代码来源:RocksDBSegmentedBytesStoreTest.java

示例11: hasNext

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
@Override
public boolean hasNext(final KeyValueIterator iterator) {
    return iterator.hasNext();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:5,代码来源:SegmentIteratorTest.java

示例12: shouldFetchExactKeys

import org.apache.kafka.streams.state.KeyValueIterator; //导入方法依赖的package包/类
@Test
public void shouldFetchExactKeys() throws Exception {
    final RocksDBSegmentedBytesStore bytesStore =
            new RocksDBSegmentedBytesStore("session-store", 0x7a00000000000000L, 2, new SessionKeySchema());

    sessionStore = new RocksDBSessionStore<>(bytesStore,
                                             Serdes.String(),
                                             Serdes.Long());

    sessionStore.init(context, sessionStore);

    sessionStore.put(new Windowed<>("a", new SessionWindow(0, 0)), 1L);
    sessionStore.put(new Windowed<>("aa", new SessionWindow(0, 0)), 2L);
    sessionStore.put(new Windowed<>("a", new SessionWindow(10, 20)), 3L);
    sessionStore.put(new Windowed<>("aa", new SessionWindow(10, 20)), 4L);
    sessionStore.put(new Windowed<>("a", new SessionWindow(0x7a00000000000000L - 2, 0x7a00000000000000L - 1)), 5L);

    KeyValueIterator<Windowed<String>, Long> iterator = sessionStore.findSessions("a", 0, Long.MAX_VALUE);
    List<Long> results = new ArrayList<>();
    while (iterator.hasNext()) {
        results.add(iterator.next().value);
    }

    assertThat(results, equalTo(Arrays.asList(1L, 3L, 5L)));


    iterator = sessionStore.findSessions("aa", 0, Long.MAX_VALUE);
    results = new ArrayList<>();
    while (iterator.hasNext()) {
        results.add(iterator.next().value);
    }

    assertThat(results, equalTo(Arrays.asList(2L, 4L)));


    final KeyValueIterator<Windowed<String>, Long> rangeIterator = sessionStore.findSessions("a", "aa", 0, Long.MAX_VALUE);
    final List<Long> rangeResults = new ArrayList<>();
    while (rangeIterator.hasNext()) {
        rangeResults.add(rangeIterator.next().value);
    }
    assertThat(rangeResults, equalTo(Arrays.asList(1L, 3L, 2L, 4L, 5L)));
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:43,代码来源:RocksDBSessionStoreTest.java


注:本文中的org.apache.kafka.streams.state.KeyValueIterator.hasNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。