System.out.println("codebase: " + System.getProperty("java.rmi.server.codebase"));
String serverAddress = InetAddress.getLocalHost().getHostAddress();
System.setProperty("java.rmi.server.hostname", serverAddress);
SmartCardTaskProcessor stub = (SmartCardTaskProcessor) UnicastRemoteObject.exportObject(engine, 0);
Registry registry = LocateRegistry.getRegistry();
boolean rmiregistryFound=true;
try{
//list bounded name in this registry: if rmiregistry is not running, this will throw an exception
System.out.println("try to get registry list");
String []a=registry.list();
System.out.println(a.length + " names bound in the registry");
for(int i=0;i<a.length;i++)
System.out.println(i+"\t"+a[i]);
}catch(Exception e)
{ //need to start rmiregistry
rmiregistryFound=false;
String rmiRegistryPath=AFileUtilities.appendToPath(System.getProperty("java.home"),"bin");
rmiRegistryPath=AFileUtilities.appendToPath(rmiRegistryPath,"rmiregistry");
ProcessBuilder processBuilder=new ProcessBuilder(rmiRegistryPath);
System.out.println("Start rmiregistry");
rmiRegistryProcess = processBuilder.start();
System.out.println("rmiregistry started");
}
long start=System.currentTimeMillis();
while(false==rmiregistryFound){
System.out.println("waiting for registry");
long now=System.currentTimeMillis();
if(now-start>1000) throw new RuntimeException("rmiregistry is not responsive");
try{
registry = LocateRegistry.getRegistry();
//list bounded name in this registry: if rmiregistry is not running, this will throw an exception
String []a=registry.list();
System.out.println(a.length + " names bound in the registry:");
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
rmiregistryFound=true;
}catch(Exception e)
{ //need to start rmiregistry
System.out.println("registry not found");
Thread.yield();
}
}
registry.rebind(SmartCardTaskProcessor.registryId, stub);
System.out.println("Terminal Manager bound");
System.out.println("wait for task or command");
} catch (Exception ex) {