[jboss-user] [Remoting] - Re: rmi registry

tom.elrod@jboss.com do-not-reply at jboss.com
Tue Aug 8 13:34:04 EDT 2006


Server code:

  | public class RMIRegistryTestServer
  | {
  |    private Connector connector = null;
  |    private String locatorUri = "rmi://localhost:4555";
  | 
  |    public void setUp() throws Exception
  |    {
  |       connector = new Connector(locatorUri);
  |       connector.create();
  |       connector.start();
  |    }
  |    
  |    public void tearDown()
  |    {
  |       if(connector != null)
  |       {
  |          connector.stop();
  |          connector.destroy();
  |       }
  |    }
  | 
  |    public static void main(String[] args)
  |    {
  |       RMIRegistryTestServer server = new RMIRegistryTestServer();
  |       try
  |       {
  |          server.setUp();
  | 
  |          Thread.sleep(6000000);
  | 
  |          server.tearDown();
  |       }
  |       catch (Exception e)
  |       {
  |          e.printStackTrace();
  |       }
  |    }
  | 
  | }
  | 
  |   | 
  |   | Client code:
  |   | 
  |   | 
  |   |   | public class RMIRegistryTestClient
  |   |   | {
  |   |   |    public void testRegistry() throws Exception
  |   |   |    {
  |   |   |       Registry registry = LocateRegistry.getRegistry("localhost", 3455);
  |   |   |       if (registry != null)
  |   |   |       {
  |   |   |          String[] entries = registry.list();
  |   |   |          if (entries != null)
  |   |   |          {
  |   |   |             for (int x = 0; x < entries.length; x++)
  |   |   |             {
  |   |   |                System.out.println("entry " + x + ": " + entries[x]);
  |   |   |             }
  |   |   |          }
  |   |   |          else
  |   |   |          {
  |   |   |             System.out.println("Failed to get entries.");
  |   |   |          }
  |   |   |       }
  |   |   |       else
  |   |   |       {
  |   |   |          System.out.println("Failed to get regsitry.");
  |   |   |       }
  |   |   | 
  |   |   |       String[] listing = Naming.list("//localhost:3455");
  |   |   |       if(listing != null)
  |   |   |       {
  |   |   |          for(int x = 0; x < listing.length; x++)
  |   |   |          {
  |   |   |             System.out.println("listing " + x + ": " + listing[x]);
  |   |   |          }
  |   |   |       }
  |   |   |       else
  |   |   |       {
  |   |   |          System.out.println("Failed to get listing.");
  |   |   |       }
  |   |   |    }
  |   |   | 
  |   |   |    public static void main(String[] args)
  |   |   |    {
  |   |   |       RMIRegistryTestClient client = new RMIRegistryTestClient();
  |   |   |       try
  |   |   |       {
  |   |   |          client.testRegistry();
  |   |   |       }
  |   |   |       catch (Exception e)
  |   |   |       {
  |   |   |          e.printStackTrace();
  |   |   |       }
  |   |   |    }
  |   |   | }
  |   |   | 
  |   | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3963871#3963871

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3963871



More information about the jboss-user mailing list