1 37 38 package net.sourceforge.cruisecontrol.distributed.util; 39 40 import java.rmi.RemoteException ; 41 42 import net.jini.core.lookup.ServiceItem; 43 import net.jini.core.lookup.ServiceMatches; 44 import net.jini.core.lookup.ServiceRegistrar; 45 import net.jini.core.lookup.ServiceTemplate; 46 47 import org.apache.log4j.Logger; 48 49 55 public final class JiniLookUpUtility { 56 57 private static final Logger LOG = Logger.getLogger(JiniLookUpUtility.class); 58 59 private MulticastDiscovery discovery = new MulticastDiscovery(null); 60 61 private JiniLookUpUtility() { 62 String waitMessage = "Waiting 5 seconds for registrars to report in..."; 63 System.out.println(waitMessage); 64 LOG.info(waitMessage); 65 try { 66 try { 67 Thread.sleep(5000); 68 } catch (InterruptedException e1) { 69 } 70 ServiceRegistrar[] registrars = discovery.getRegistrars(); 71 for (int x = 0; x < registrars.length; x++) { 72 ServiceRegistrar registrar = registrars[x]; 73 String registrarInfo = "Registrar: " + registrar.getServiceID(); 74 System.out.println(); 75 System.out.println(registrarInfo); 76 LOG.debug(registrarInfo); 77 ServiceTemplate template = new ServiceTemplate(null, null, null); 78 ServiceMatches matches = registrar.lookup(template, Integer.MAX_VALUE); 79 ServiceItem[] items = matches.items; 80 for (int i = 0; i < items.length; i++) { 81 String serviceInfo = " Service: " + items[i].service; 82 System.out.println(serviceInfo); 83 LOG.debug(serviceInfo); 84 } 85 } 86 } catch (RemoteException e) { 87 String message = "Search failed due to an unexpected error"; 88 LOG.error(message, e); 89 System.err.println(waitMessage + " - " + e.getMessage()); 90 throw new RuntimeException (message, e); 91 } 92 } 93 94 public static void main(String [] args) { 95 new JiniLookUpUtility(); 96 } 97 } 98 | Popular Tags |