This topic is quite large and covered in a separate article here.
There are many ways of performing a lookup (see Service Lookup), for this example, we'll use the ServiceDiscoveryManager:
import net.jini.discovery.*;
import net.jini.lookup.*;
import net.jini.lookup.entry.Name;
import net.jini.core.entry.Entry;
import net.jini.core.lookup.ServiceItem;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.space.JavaSpace;
// Class Definition etc........
/*
We use LookupDiscoveryManager because it gives us a great deal
of power in controlling the LUS'en we will do searches on.
We can for example, disable all searching via multicast and use
just a set of LookupLocators or we can do just multicast lookup
on all groups (or a specific group) or we can do lookup based on
a combination of multicast and LookupLocators.
*/
LookupDiscoveryManager myLDM =
new LookupDiscoveryManager(DiscoveryGroupManagement.ALL_GROUPS,
null, null);
ServiceDiscoveryManager myManager =
new ServiceDiscoveryManager(myLDM, null);
/*
Create the search attributes, in this case, we want to find by name
as well as interface.
*/
Entry[] myAttrs = new Entry[] {new Name("aServiceName")};
ServiceTemplate myTemplate =
new ServiceTemplate(null, new Class[] {JavaSpace.class}, myAttrs);
/*
Search for 5 seconds
*/
try {
ServiceItem myMatch = myManager.lookup(myTemplate, null, 5000);
if (myMatch != null) {
System.out.println("*** Found a match with a blocking lookup ***");
// Do stuff......
}
} catch (InterruptedException anIE) {
System.err.println("!!! Whoops blocking lookup interrupted :( !!!");
}
// Rest of class......
If you're looking for information on how to support proxy verification in your service see "Support for Proxy Verification" in Creating a JINI 2.0 Service.
Proxy verification breaks down into three steps:
ProxyPreparer. The most commonly used instance of ProxyPreparer is net.jini.security.BasicProxyPreparer. BasicProxyPreparer has several constructors, the most complicated of which is:
BasicProxyPreparer(boolean verify, MethodConstraints methodConstraints, Permission[] permissions);Which accepts a flag indicating whether to perform trust verification, a set of constraints to apply to the proxy and a set of permissions which should be granted to the proxy. A typical example of usage would be:
/* Lookup proxy in LUS */ Object server = ....... /* Recover a preparer from our configuration file */ ProxyPreparer preparer = (ProxyPreparer) config.getEntry( "org.dancres.example.Client", "preparer", ProxyPreparer.class, new BasicProxyPreparer()); /* Prepare the server proxy */ Thingy preparedServer = (Thingy) preparer.prepareProxy(server);
BasicProxyPreparer does it's work in the following order:
For more details, see "3.2 Proxy Preparation Using BasicProxyPreparer" in the JINI 2.0 overview.
import net.jini.id.UuidFactory;
import net.jini.id.Uuid;
import net.jini.core.lookup.ServiceID;
......
Uuid myUuid = UuidFactory.generate();
ServiceId myServiceId = new ServiceID(myUuid.getMostSignificantBits(),
myUuid.getLeastSignificantBits());
......
© Copyright 2003 Dan Creswell