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

📄 helloworldimpl.java

📁 分别介绍RMI,分布式对象与CORBA,动态接口,CORBA客户端开发的课件,以及相关的例子
💻 JAVA
字号:
/*
 * Copyright 1999 by dreamBean Software,
 * All rights reserved.
 */
package masteringrmi.helloactivate.server;

import java.rmi.Remote;
import java.rmi.MarshalledObject;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.rmi.activation.Activatable;
import java.rmi.activation.ActivationID;
import java.util.Properties;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import masteringrmi.helloactivate.interfaces.HelloWorld;

/**
 *   This is a remote activatable object that implements the remote interface.
 *
 *   It has a special constructor that is invoked when the object is activated.
 *   This constructor will export the object and bind it in JNDI.
 *   
 *   @see HelloWorld
 *   @author Rickard 謆erg (rickard@dreambean.com)
 *   @version $Revision:$
 */
public class HelloWorldImpl
   implements HelloWorld
{
   // Constructors --------------------------------------------------
   public HelloWorldImpl(ActivationID id, MarshalledObject data) 
      throws RemoteException 
   { 
      Remote stub = Activatable.exportObject(this, id, 0);
   
      try
      {
         Properties cfg = new Properties();
         cfg.load(this.getClass().getResourceAsStream("/jndi.properties"));
         new InitialContext(cfg).rebind(HelloWorld.NAME, stub);
      } catch (Exception e)
      {
   	   throw new ServerException("Could not bind server", e);
      }
	   System.out.println("Hello created");
   } 
   
   // Public --------------------------------------------------------

   // HelloWorld implementation -------------------------------------
   /**
    *   Create a greeting.
    *
    * @param   name  a name
    * @return     a name including the name
    */
   public String helloWorld(String name)
   {
      System.out.println("Hello called");
      return "Hello " + name +"!";
   }
}

⌨️ 快捷键说明

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