Reputation: 365
I am using Infinispan 7.2.5 cluster in the distribution mode to cache large amount of data where I cannot cache in a single machine. Average cache entry size is around 1Mb.
I have a REST application which gets a cache entry from the Infinispan cluster and filter it and send small parts of the cache entry (few Kbs) as response. Since retrieving 1Mb of data from Infinispan cluster is effecting the REST application performance, I am looking for a way to filter out the cache entry within the corresponding Infinispan node itself to reduce the network latency.
If I can get the IP address of the node where the cache entry resides, I can have another REST application on each Infinispan server to process the cache entry and return the required response.
I have tried with the HotRod Java client, but couldn't find the way to get the IP address.
Thank you in advance! :)
Upvotes: 0
Views: 424
Reputation: 5888
Locating the key within the cluster is not complicated, you can use
Address address = cache.getAdvancedCache()
.getDistributionManager().getPrimaryLocation(key)
The dirty stuff happens afterwards; you have to cast that to JGroupsAddress
and call getJGroupsAddress()
. However, as JGroups is quite generic, this does need to have IP assigned either; if you're lucky it's an instance of IpAddress
and you can call getIpAddress()
on it.
Better approach is to use distributed executors with the filter as task, and let Infinispan do the routing for you - see also DistributedExecutorService.submit(Callable<T> task, K... input);
:
Execution environment will chose an arbitrary node N hosting some or all of the keys specified as
input
.
Upvotes: 2