helloworldimpl.java

来自「最新的关于精通rmi这本书的源码」· Java 代码 · 共 66 行

JAVA
66
字号
/*
 * 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 + =
减小字号Ctrl + -
显示快捷键?