?? main.java
字號:
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package masteringrmi.agent.server;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.MalformedURLException;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.ServerException;
import java.rmi.registry.Registry;
import java.util.Properties;
import javax.naming.InitialContext;
import com.dreambean.dynaserver.DynaServer;
/**
* This is the manager of the agent host.
*
* It starts the basic services required by the host,
* and also manage an instance of the host itself.
*
* @author Rickard 謆erg
* @version $Revision:$
*/
public class Main
{
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
public static void main(String[] args)
throws Exception
{
// Load system properties
System.getProperties().load(
Thread.currentThread().
getContextClassLoader().
getResourceAsStream("system.properties"));
// Set policy to use
System.setProperty("java.security.policy", Main.class.getResource("/server.policy").toString());
// Set a security manager
System.setSecurityManager(new SecurityManager());
new Main();
}
// Constructors --------------------------------------------------
public Main()
{
// Start server
try
{
startWebServer();
startNamingServer();
startAgentServer();
System.out.println("Server has been started and registered");
} catch (Exception e)
{
System.out.println("The server could not be started");
e.printStackTrace(System.err);
}
}
// Public --------------------------------------------------------
public void startWebServer()
throws IOException
{
// Start webserver for dynamic class loading
// The webserver can access any class available from the default classloader
// Start webserver for dynamic class loading
DynaServer srv = new DynaServer();
srv.setDebug(true);
srv.addClassLoader(Thread.currentThread().getContextClassLoader());
srv.start();
}
protected void startNamingServer()
throws RemoteException
{
// Create registry if not already running
try
{
java.rmi.registry.LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
} catch (java.rmi.server.ExportException ee)
{
// Registry already exists
} catch (RemoteException e)
{
throw new ServerException("Could not create registry", e);
}
}
public void startAgentServer()
throws Exception
{
// Create remote object
AgentHostImpl server = new AgentHostImpl();
UnicastRemoteObject.exportObject(server);
// Register server with naming service
new InitialContext().bind("agenthost",server);
}
// Y overrides ---------------------------------------------------
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -