Scott Van Wart
Scott Van Wart

Reputation: 53

Infinispan distributed cache and executing tasks on primary key owner

Is it possible to get Infinispan (9.4+) to execute a task on a primary key owner? Like if I give it a cache, a key in that cache, and a Runnable/Callable, can it just execute that task on the owner of that key?

This would be similar to Hazelcast IExecutorService's submitToKeyOwner or executeOnKeyOwner.

Thanks.

Upvotes: 0

Views: 275

Answers (1)

Mudokonman
Mudokonman

Reputation: 901

There are a few ways.

The simplest if the key exists is just to use DistributedStreams

cache.entrySet().stream().filterKeys(Collections.singleton(key)).forEach((cache, k) -> <do stuff>);

If the key doesn't exist you can use the ClusterExecutor

cacheManager.executor().singleNodeSubmission().filterTargets(Collections.singleton(address) .submit(<runnable>);

You can find the target address by invoking

Address address = cache.getAdvancedCache().getDistributionManager() .getCacheTopology().getDistributionInfo(key).primary();

I also suggest you check out this section http://infinispan.org/docs/stable/user_guide/user_guide.html#execute_code_grid

Upvotes: 1

Related Questions