[infinispan-dev] New API to iterate over current entries in cache

William Burns mudokonman at gmail.com
Wed Apr 30 10:06:49 EDT 2014


Was wondering if anyone had any opinions on the API for this.

These are a few options that Dan and I mulled over:

Note the CloseableIterable inteface mentioned is just an interface
that extends both Closeable and Iterable.

1. The API that is very similar to previously proposed in this list
but slightly changed:

Methods on AdvancedCache

CloseableIterable<CacheEntry<K, V>> entryIterable(KeyValueFilter<?
super K, ? super V> filter);

<C> CloseableIterable<CacheEntry<K, C>> entryIterable(KeyValueFilter<?
super K, ? super V> filter, Converter<? super K, ? super V, C>
converter);

Note the difference here is that it would return an Iterable instead
of Iterator, which would allow for it being used in a for loop.

Example usage would be (types omitted)

for (CacheEntry entry : cache.entryIterable(someFilter, someConverter)) {
// Do something
}


2. An API that returns a new type EntryIterable for example that can
chain methods to provide a filter and converter.

on AdvancedCache

EntryIterable<K, V> entryIterable();

where EntryIterable is defined as:

public interface EntryIterable<K, V> extends
CloseableIterable<CacheEntry<K, V>> {

   public EntryIterable<K, V> filter(KeyValueFilter<? super K, ? super
V> filter);

   public EntryIterable<K, V> converter(Converter<? super K, ? super
V, ? extends V> converter);

   public <C> CloseableIterable<CacheEntry<K, C>>
projection(Converter<? super K, ? super V, C> converter);
}

Note that there are 2 methods that take a Converter, this is to
preserve the typing, since the method would return a different
EntryIterable instance.  However I can also see removing one of the
converter method and just rename projection to converter instead.

This API would allow for providing optional fields more cleanly or not
if all if desired.

Example usage would be (types omitted)

for (CacheEntry entry :
cache.entryIterable().filter(someFilter).converter(someConverter)) {
// Do something
}


3. An API that requires the filter up front in the AdvancedCache
method.  This also brings up the point should we require a filter to
always be provided?  Unfortuantely this doesn't prevent a user from
querying every entry as they can just use a filter that accepts all
key/value pairs.

on AdvancedCache

EntryIterable<K, V> entryIterable(Filter<? super K, ? super V> filter)

where EntryIterable is defined as:

public interface EntryIterable<K, V> extends
CloseableIterable<CacheEntry<K, V>> {

   public <C> CloseableIterable<CacheEntry<K, C>>
converter(Converter<? super K, ? super V, C> converter);
}

The usage would be identical to #2 except the filter is always provided.


Let me know what you guys think or if you have any other suggestions.

 Thanks,

 - Will


More information about the infinispan-dev mailing list