thansk Edward for you notable suggestions.
My problem is that i working on the sample example given at some website
with the necessary batch files to run the code.
My server is not responding after some time. And when i am running the client
program i am getting the fallowing exception
i.e Exception occured in MyClient.main() method:java.lang.NullPointerException
This is that example program
Inteface
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface MyServerInterface extends Remote {
public
String sayHello () throws RemoteException;
}
MyServer Program
import net.jini.lookup.entry.Name;
import net.jini.lookup.ServiceIDListener;
import net.jini.core.lookup.ServiceID;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceItem;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.entry.Entry;
import net.jini.core.lease.Lease;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
public class MyService extends UnicastRemoteObject implements MyServerInterface {
public MyService () throws RemoteException {
super ();
}
public String sayHello () throws RemoteException { // MyServiceInterface
System.out.println ("server: The method sayHello() in MyService was " + "called");
return ("Hello World from MyService!");
}
public static void main (String[] args) {
MyServerInterface myServer;
LookupLocator lookup;
ServiceRegistrar registrar;
ServiceItem serviceItem;
try {
/* Set the security manager to allow the RMI class loader
to go to the codebase for classes that are not available
locally. */
System.setSecurityManager (new RMISecurityManager ());
/* Create the attributes (an array of entry objects) that describe this
server and use it to register this server with the lookup service.
JoinManager finds and registers with the lookup service */
Entry[] attr = new Entry[1];
attr[0] = new Name("HelloWorldServer");
myServer = new MyService ();
serviceItem = new ServiceItem(null, myServer, attr);
lookup = new LookupLocator ("jini://localhost");
registrar = lookup.getRegistrar();
registrar.register(serviceItem, Lease.FOREVER);
System.out.println("Serrvice Ready ...");
} catch (Exception e)
{
System.out.println("server: MyService.main(): Exception " + e);
}
}
}
MyClient program
import net.jini.core.entry.Entry;
import net.jini.core.discovery.LookupLocator;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.lookup.entry.Name;
import java.rmi.RMISecurityManager;
public class MyClient {
public static void main (String[] args) {
Entry[] aeAttributes;
LookupLocator lookup;
ServiceRegistrar registrar;
ServiceTemplate template;
MyServerInterface myServerInterface;
try {
/* Set the security manager to allow the RMI class loader to access
the codebase for classes that are not available locally */
System.setSecurityManager (new RMISecurityManager ());
/* Find the Jini lookup service (reggie) and print its location */
lookup = new LookupLocator ("jini://localhost");
/* Get the lookup service's ServiceRegistrar and perform a search to find
the service that has the name attribute name of "HelloWorldServer".
The lookup service returns an Proxy object to the service */
registrar = lookup.getRegistrar();
aeAttributes = new Entry[1];
aeAttributes[0] = new Name ("HelloWorldServer");
template = new ServiceTemplate (null, null, aeAttributes);
myServerInterface = (MyServerInterface) registrar.lookup (template);
System.out.println ("Calling sayHello()->" + myServerInterface.sayHello () + "<-");
} catch (Exception e) {
System.out.println ("client: MyClient.main() exception: " + e);
}
}
}
Please suggest me where i shall make changes in this code such that the
service object remain availabe for long time, unless some network failure etc.
Also suggest me few site where i am find some reference material and workable examples on jini technology.