Search in sources :

Example 1 with ReadOnlyWindowStore

use of org.apache.kafka.streams.state.ReadOnlyWindowStore in project apache-kafka-on-k8s by banzaicloud.

the class CompositeReadOnlyWindowStore method fetch.

@Override
public WindowStoreIterator<V> fetch(final K key, final long timeFrom, final long timeTo) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType);
    for (final ReadOnlyWindowStore<K, V> windowStore : stores) {
        try {
            final WindowStoreIterator<V> result = windowStore.fetch(key, timeFrom, timeTo);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException e) {
            throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata.");
        }
    }
    return KeyValueIterators.emptyWindowStoreIterator();
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyWindowStore(org.apache.kafka.streams.state.ReadOnlyWindowStore)

Example 2 with ReadOnlyWindowStore

use of org.apache.kafka.streams.state.ReadOnlyWindowStore in project kafka by apache.

the class CompositeReadOnlyWindowStore method backwardFetch.

@Override
public WindowStoreIterator<V> backwardFetch(final K key, final Instant timeFrom, final Instant timeTo) throws IllegalArgumentException {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType);
    for (final ReadOnlyWindowStore<K, V> windowStore : stores) {
        try {
            final WindowStoreIterator<V> result = windowStore.backwardFetch(key, timeFrom, timeTo);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException e) {
            throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata.");
        }
    }
    return KeyValueIterators.emptyWindowStoreIterator();
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyWindowStore(org.apache.kafka.streams.state.ReadOnlyWindowStore)

Example 3 with ReadOnlyWindowStore

use of org.apache.kafka.streams.state.ReadOnlyWindowStore in project kafka by apache.

the class CompositeReadOnlyWindowStore method fetch.

@Override
public WindowStoreIterator<V> fetch(final K key, final Instant timeFrom, final Instant timeTo) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType);
    for (final ReadOnlyWindowStore<K, V> windowStore : stores) {
        try {
            final WindowStoreIterator<V> result = windowStore.fetch(key, timeFrom, timeTo);
            if (!result.hasNext()) {
                result.close();
            } else {
                return result;
            }
        } catch (final InvalidStateStoreException e) {
            throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata.");
        }
    }
    return KeyValueIterators.emptyWindowStoreIterator();
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyWindowStore(org.apache.kafka.streams.state.ReadOnlyWindowStore)

Example 4 with ReadOnlyWindowStore

use of org.apache.kafka.streams.state.ReadOnlyWindowStore in project kafka by apache.

the class CompositeReadOnlyWindowStore method fetch.

@Override
public V fetch(final K key, final long time) {
    Objects.requireNonNull(key, "key can't be null");
    final List<ReadOnlyWindowStore<K, V>> stores = provider.stores(storeName, windowStoreType);
    for (final ReadOnlyWindowStore<K, V> windowStore : stores) {
        try {
            final V result = windowStore.fetch(key, time);
            if (result != null) {
                return result;
            }
        } catch (final InvalidStateStoreException e) {
            throw new InvalidStateStoreException("State store is not available anymore and may have been migrated to another instance; " + "please re-discover its location from the state metadata.");
        }
    }
    return null;
}
Also used : InvalidStateStoreException(org.apache.kafka.streams.errors.InvalidStateStoreException) ReadOnlyWindowStore(org.apache.kafka.streams.state.ReadOnlyWindowStore)

Aggregations

InvalidStateStoreException (org.apache.kafka.streams.errors.InvalidStateStoreException)4 ReadOnlyWindowStore (org.apache.kafka.streams.state.ReadOnlyWindowStore)4