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

📄 setup.java

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

import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.MarshalledObject;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.rmi.AlreadyBoundException;
import java.rmi.activation.ActivationGroupDesc;
import java.rmi.activation.ActivationGroupID;
import java.rmi.activation.ActivationGroup;
import java.rmi.activation.ActivationDesc;
import java.rmi.activation.Activatable;
import java.util.Properties;

import javax.naming.InitialContext;

import masteringrmi.helloactivate.interfaces.HelloWorld;

/**
 *   This application should be run once, and will register the activatable
 *   object with the RMI daemon.
 *   
 *   @see HelloWorldImpl
 *   @author Rickard 謆erg (rickard@dreambean.com)
 *   @version $Revision:$
 */
public class Setup
{
   // Attributes ----------------------------------------------------

   // Static --------------------------------------------------------
   public static void main(String[] args)
      throws Exception
   {
try{
		new Setup();
}
catch(Exception ee){}
      
      System.exit(0);
   }
   
   // Constructors --------------------------------------------------
	public Setup()
		throws Exception
	{
		// Load system properties from resource file
        try{
	   System.getProperties().load(
	      Thread.currentThread().
	      getContextClassLoader().
	      getResourceAsStream("system.properties"));

		
		System.setProperty("java.security.policy", getClass().getResource("/server.policy").toString());
      
      // Create activation group description
		Properties cfg = null;
		ActivationGroupDesc.CommandEnvironment ace = null;
		ActivationGroupDesc helloGroup = new ActivationGroupDesc(cfg, ace);
		
		// Register group with activation system
		ActivationGroupID agi = ActivationGroup.getSystem().registerGroup(helloGroup);

      // Create the group
      // This is necessary since the activation description created below will 
      // use this group
		ActivationGroup.createGroup(agi, helloGroup, 0);
		System.out.println("Activation group created");		
		
      // Create activatable object description
      // Use the same codebase as this class
		String location = System.getProperty("java.rmi.server.codebase"); 
		MarshalledObject data = null;
		ActivationDesc desc = new ActivationDesc("masteringrmi.helloactivate.server.HelloWorldImpl", 
															   location, data, true);
		
      // Register object with activation system
		HelloWorld hello = (HelloWorld)Activatable.register(desc);
		System.out.println("Registered server with activation system");		
		
      // Register objects stub with naming service
		new InitialContext().rebind(HelloWorld.NAME, hello);
		System.out.println("Server has been bound");
	}
catch(Exception e){
System.out.println(e);
}
}
}

⌨️ 快捷键说明

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