[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [gyrex-dev] How to use the INodeState
|
Hi,
Am 21.11.2014 um 11:20 schrieb Jürgen Albert <j.albert@xxxxxxxxxxxxxxxxxx>:
> I stumbled upon the INodeState but I have no idea how to use it properly. Can somebody give me an explanation or even better a short example for this? I found nothing about this in the gyrex code…
I just realized that there are no examples at all. One more thing for our todo list. Anyway, here is the general idea:
The state provider (some node) does:
Map<String, String> properties = …;
properties.put(“service.pid”, “cool.search.service.info”)
properties.put(“url”, “https://thishostname...”)
properties.put(“available.indices”, “books”)
…registerOsgiService (INodeState.class, INodeState.INSTANCE, properties);
The state consumer does:
INodeStateQueryService stateQueryService = getOsgiService(INodeStateQueryService.class);
List<INodeStateInfo> availableInfos = stateQueryService.findByServicePid(“cool.search.service.info”);
while(true) {
INodeStateInfo info = pickRandomServiceForIndexAndRemoveItFromList(availableInfos, “books”);
Map<String, String> properties = info.getDate();
String url = properties.get(“url”);
Object result = doSearch(url, keywords)
if(result != null)
return result;
// re-try
}
pickRandomServiceForIndexAndRemoveItFromList can implement some round robin pattern or whatever. It should fail if the list is empty and/or no service is available.
-Gunnar
--
Gunnar Wagenknecht
gunnar@xxxxxxxxxxxxxxx