Skip to content

Instantly share code, notes, and snippets.

@deckerego
Created December 6, 2013 14:28
Show Gist options
  • Save deckerego/7825600 to your computer and use it in GitHub Desktop.
Save deckerego/7825600 to your computer and use it in GitHub Desktop.
Looking Up a Jini Service Entry, with thanks to Shay at the GigaSpaces forums ( http://forum.openspaces.org/thread.jspa?messageID=10328 )
LookupCache getLookupCache(String host, Class template) {
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
LookupLocator primaryRegistrar = new LookupLocator(host);
LookupDiscoveryManager discoveryManager =
new LookupDiscoveryManager(null, new LookupLocator[] {primaryRegistrar}, null);
ServiceDiscoveryManager serviceDiscoveryManager =
new ServiceDiscoveryManager(discoveryManager, new LeaseRenewalManager());
ServiceTemplate serviceTemplate = new ServiceTemplate(null, new Class[] {template}, null);
return serviceDiscoveryManager.createLookupCache(serviceTemplate, null, this);
}
Object getServiceEntry(String name) {
final Name serviceName = new Name(name);
ServiceItem serviceItem = lookupCache.lookup(new ServiceItemFilter() {
@Override
public boolean check(ServiceItem serviceItem) {
for(Entry attribute : serviceItem.attributeSets)
return serviceName.equals(attribute);
return false;
}
});
return serviceItem.service;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment