Created
December 6, 2013 14:28
-
-
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 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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