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

📄 main.java

📁 《精通RMI:Java与EJB企业级应用开发》书籍的源代码. 本书是讲述RMI技术的经典著作
💻 JAVA
字号:
/*
 * Copyright 1999 by dreamBean Software,
 * All rights reserved.
 */
package masteringrmi.helloworld.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 masteringrmi.helloworld.interfaces.HelloWorld;

/**
 *   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.
 *
 *   @see HelloWorld
 *   @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
   {
      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
         HelloWorld server = (HelloWorld)Naming.lookup("rmi://localhost/"+HelloWorld.NAME);
         
         // Call it
         String result = server.helloWorld("World");
         
         // Print result
         System.out.println(result);
         
      } 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);
      }
   }

   /**
    * @label Uses 
    */
   /*#HelloWorld Uses;*/
}

⌨️ 快捷键说明

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