Wadjet-SLP supplies a set of classes for accessing SLP (Service Location Protocol) daemons (slpd ).
The code is based on the OpenSLP implementations which have been brought up to date for Java 1.5 and modified so that JMX rmi URLs do not break the ServiceURL parser.
The locator (User Agent) and advertiser (Service Agent) classes can connect to an SLP daemon (Directory or Service Agent) running on a specified host so that it is not necessary to have slpd running on each host.
Over the base protocol layer, there are a set of helper classes that are designed to remove the pain of using SLP by supplying easy to use functionality to keep a service registered, ensure a service is unique, list available services and create service URLs from corbalocs and IORs.
The following sections describe how to
The most common use of SLP to register your server so that it can can be discovered by other applications on the network, to do this you would use the ISlpRegistrar class which will keep your service registered until it is stopped by regularly renewing the lease with the Directory Agent and deregistering automatically when the service stops:
ISlpRegistrar registrar = SlpRegistrarLocator.getSlpRegistrar();
registrar.setServiceUrl("service:jmx:rmi:///jndi/rmi://:3000/jmxrmi",
"AFS",
"default",
20);
registrar.start();
This will register a jmx:rmi service with the AgentName AFS in the default scope with a lease of 20 seconds.
If you prefer to use a long lease and simply register the service and manually deregister when the service terminates, you can do this:
ISlpRegistrar registrar = SlpRegistrarLocator.getSlpRegistrar();
ServiceURL surl = new ServiceURL("service:jmx:rmi:///jndi/rmi://:3000/jmxrmi",
ServiceURL.LIFETIME_PERMANENT);
registrar.setServiceUrl(surl, "AFS", "default");
if(!registrar.register(false)) {
logger.error("Failed to register the service");
...
}
...
...
registrar.deRegister(surl);
This registers the same url permanently and then deregisters it.
Occasionally a service needs to be unique on a net, this can be checked using the ISlpRegistrar implementation too, so to check if the ServiceName (AgentName) is unique:
ISlpRegistrar registrar = SlpRegistrarLocator.getSlpRegistrar();
ServiceURL surl = new ServiceURL("service:jmx:rmi:///jndi/rmi://:3000/jmxrmi",
ServiceURL.LIFETIME_PERMANENT);
registrar.setServiceUrl(surl, "AFS", "default");
if (!registrar.isServiceNameUniqueInScope()) {
logger.fatal("Service is already running");
System.exit(1);
}
or to check whether the Service URL is unique:
ISlpRegistrar registrar = SlpRegistrarLocator.getSlpRegistrar();
ServiceURL surl = new ServiceURL("service:jmx:rmi:///jndi/rmi://:3000/jmxrmi",
ServiceURL.LIFETIME_PERMANENT);
registrar.setServiceUrl(surl, "AFS", "default");
if (!registrar.isServiceUrlUniqueInScope()) {
logger.fatal("Service is already running");
System.exit(1);
}
UAs (User Agents) need to be able to find the service they want to connect to. To do this you would use the SlpServicesLister class. For example, to get all the services of type service:jmx registered on any scope:
ServiceType st = new ServiceType("service:jmx");
List<String> scopes = Conversions.stringToList(
ServiceLocationManager.getConfiguration().getScopes());
SlpServicesLister lister = new SlpServicesLister(st, scopes, null);
List<ServiceDefiniiton> services = lister.getAvailableServices();
to get a specific server in a specific scope:
ServiceType st = new ServiceType("service:jmx");
List<String> scopes = new ArrayList<String();
scopes.add("default");
SlpServicesLister lister = new SlpServicesLister(st, scopes, "AFS");
List<ServiceDefiniiton> services = lister.getAvailableServices();
corbaloc and ior urls have to be created carefully and writing them by hand can be error prone, to help with this there is a helper that will create a ServiceURL from a corbaloc or ior:
SlpCorbaHelper helper = new SlpCorbaHelper();
String cl = "corbaloc:iiop:merlin:1477/AuditForwarder/Audit/AuditForward";
ServiceURL curl = helper.getServiceUrlFromCorbaloc(cl, 600);
String ior = "IOR:9012834790287518576185973347865928347236590357613056130875061073465";
ServiceURL iurl = helper.getServiceUrlFromIOR(ior, 600);
and extract the corbaloc or ior from a ServiceURL
String cl = helper.getCorbalocFromServiceUrl(curl);
String ior = helper.getIORFromServiceUrl(iurl);
All the above examples will work fine if you have slpd running on the local host, if this not the case, you can configure the protocol layer to connect to a specific slpd instance like this:
ServiceLocationManager.getConfiguration().setSlpdHost("myhost.mydomain.com");
You will need to make this call before using an ILocator, IAdvertiser, ISlpRegistrar or a SlpServicesLister instance.
The protocol layer has tracing switched off by default, and no DAs are defined. If you want to see what is being done in the protocol layer or set default DA addresses, you can initialise the configuration in one of 2 ways, by passing a configuration file to the static init() method of the ServiceLocationManager class or by setting up and passing a Properties object:
Properties slpProps = new Properties();
slpProps.setProperty(SLPConfiguration.TRACE_DATRAFFIC, "true");
slpProps.setProperty(SLPConfiguration.TRACE_REG, "true");
slpProps.setProperty(SLPConfiguration.TRACE_MESSAGE, "true");
ServiceLocationManager.init(slpProps);
NOTE The ServiceLocationManager.init() method MUST be invoked before you make any other calls to the ServiceLocationManager.
The properties you can set shown in the following table
| key | Description | Default |
| net.slp.hostname | The host where the slp daemon runs | localhost |
| net.slp.useScopes | Comma delimited list of scopes available | DEFAULT |
| net.slp.DAAddresses | Comma delimited list of DA addresses | None |
| net.slp.noDADiscovery | Do not search for DA addresses, only valid if code net.slp.DAAddresses/code is set | false |
| net.slp.traceDATraffic | Trace DA traffic | false |
| net.slp.traceMsg | Trace Messages | false |
| net.slp.traceDrop | Trace dropped messages | false |
| net.slp.traceReg | Trace registartion messages | false |
| net.slp.multicastTTL | The multicast TTL (byte) | 255 |
| net.slp.multicastMaximumWait | The multicast maximum wait (millisecs) | 5000 |
| net.slp.multicastTimeouts | List of multicast timeouts (millisecs) | 500,750,1000,1500,2000,3000 |
| net.slp.datagramMaximumWait | Maximum datagram wait (millisecs) | 15000 |
| net.slp.datagramTimeouts | List of datagram timeouts | 3000,3000,3000,3000,3000 |
| net.slp.MTU | The MTU to use | 1400 |
| net.slp.locale | The locale to use | en |
| net.slp.securityEnabled | is security enabled | false |
| net.slp.spi | The security provider name | None |
| net.slp.privateKey.<spi> | Path to the private key file | |
| net.slp.publicKey.<spi> | Path to the public key file |