⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 《精通RMI:Java与EJB企业级应用开发》书籍的源代码. 本书是讲述RMI技术的经典著作
💻 JAVA
字号:
/*
 * Copyright 1999 by dreamBean Software,
 * All rights reserved.
 */
package smartworld.client;

import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Properties;

import smartworld.interfaces.SmartWorld;

/**
 *   This test application client locates a server object, and invokes it.
 *
 *   This demonstrates a barebones client which is about as simple as it gets, RMI-wise at least.
 *
 *   @author Rickard 謆erg (rickard@dreambean.com)
 *   @version $Revision:$
 */
public class Main
   implements Runnable
{
   // Static --------------------------------------------------------

   /**
    *   Start the client as a stand-alone application.
    *
    * @param   args  
    * @exception   Exception  
    */
   public static void main(String[] args)
      throws Exception
   {
      System.setSecurityManager(new SecurityManager()
      {
         public void checkPermission(java.security.Permission p)
         {
            
         }
      });
      
      new Main().run();
   }
   
   // Public --------------------------------------------------------

   // Runnable implementation ---------------------------------------

   /**
    *   Run the client. Lookup the server from a RMI-registry, call it, and print the result.
    *
    */
   public void run()
   {
      try
      {
         // Locate remote object
         SmartWorld server = (SmartWorld)Naming.lookup(SmartWorld.NAME);
/*         
         // Call it
         String result = server.helloWorld("World");
         
         // Print result
         System.out.println(result);
         
         // Say hi
         server.sayHi("World", true);
         
         // Test arrays
         server.testArrays(new int[1][2]);
*/         
         // Test reconnect
         while (true)
         {
            try
            {
               System.out.println(server.helloWorld("World"));
            } catch (RemoteException e)
            {
               System.out.println("Server not available:"+e.getMessage());
            }
            
            Thread.sleep(1000);
         }
         
      } catch (NotBoundException e)
      {
         System.out.println("The server could not be found");
         e.printStackTrace(System.err);
      } catch (MalformedURLException e)
      {
         System.out.println("The server name was incorrect");
         e.printStackTrace(System.err);
      } catch (Exception e)
      {
         System.out.println("The object could not be created");
         e.printStackTrace(System.err);
      }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -