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

📄 helloimpl.java

📁 weblogic应用全实例
💻 JAVA
字号:
//这个类包含在包examples.rmi.multihello
package examples.rmi.multihello;
//这个远程调用的方法使用weblogic提供的开发包。
import weblogic.rmi.Naming;
import weblogic.rmi.RemoteException;
//import weblogic.rmi.server.UnicastRemoteObject;

/**
 * 这个远程类实现远程接口Hello,它返回一个'hello'消息用名字标识这个类。
 * 这个main()方法在WebLogic服务器注册10个本类的实例。这个例子中,你应该
 * 在系统管理控制台中把这个类注册成启动类(startupClass)。
 * 这使得在WebLogic服务器启动的时候,调用这个main()方法,这将创建10个实例,
 * 并把它们注册在RMI注册表中。
 * 在这个例子中ClientApp Java程序调用每个远程对象的sayHello()远程方法
 */
//这个类必须实现远程接口
public class HelloImpl implements Hello 
// 在WebLogic RMI不必继承UnicastRemoteObject 
{
  //声明变量
  private String name;
  private int cnt = 0;

  /**
   * 以特定的字符串构建HelloImpl。
   *
   * @参数 s                 String 消息
   */
  public HelloImpl(String s) throws RemoteException {
    name = s;
  }

  /**
   * 返回一个字符串.
   *
   * @返回                  String 消息
   * @异常               weblogic.rmi.RemoteException
   */
  public String sayHello() throws RemoteException {
    return "Hello! From " + name; // + " " + cnt++;
  } 

  /**
   * 在WebLogic服务器上创建和邦定10个HelloImpl对象,每个绑定用唯一的名字
   */
  public static void main(String args[]) {
    
     
    // 创建和安装安全管理并不是必须的
    // System.setSecurityManager(new RMISecurityManager());

    int i = 0;
    try {
      for (i = 0; i < 10; i++) {
      	//创建10个实例
        HelloImpl obj = new HelloImpl("MultiHelloServer" + i);
        //邦定
        Naming.rebind("MultiHelloServer" + i, obj);
        System.out.println("MultiHelloServer" + i + " created.");
      }
      System.out.println("Created and registered " + i + " MultiHelloImpls.");
      
    }
    catch (Exception e) {
      System.out.println("HelloImpl err: " + e.getMessage());
      e.printStackTrace();
    }
  }
}

⌨️ 快捷键说明

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