本文整理汇总了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;
}
示例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;
}
};
}
示例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;
}
};
}
示例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();
}
示例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());
}
示例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();
}
示例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;
}
示例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());
}
示例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());
}
示例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();
}
示例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)));
}