?? setup.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
{
new Setup();
System.exit(0);
}
// Constructors --------------------------------------------------
public Setup()
throws Exception
{
// Load system properties from resource file
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");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -