?? main.java
字號:
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package masteringrmi.chat.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.rmi.registry.LocateRegistry;
import java.util.Properties;
import javax.naming.InitialContext;
import masteringrmi.chat.interfaces.TopicInfo;
import com.dreambean.dynaserver.DynaServer;
/**
* This is the admin class that manages the chat server.
*
* @see TopicServerImpl
* @author Rickard 謆erg (rickard@dreambean.com)
* @version $Revision:$
*/
public class Main
{
// Attributes ----------------------------------------------------
TopicServerImpl server; // To prevent GC
// Static --------------------------------------------------------
public static void main(String[] args)
throws Exception
{
// Load system properties
System.getProperties().load(
Thread.currentThread().
getContextClassLoader().
getResourceAsStream("system.properties"));
new Main();
}
// Constructors --------------------------------------------------
public Main()
{
// Start server
try
{
startWebServer();
startNamingServer();
startTopicServer();
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
DynaServer srv = new DynaServer();
srv.addClassLoader(Thread.currentThread().getContextClassLoader());
srv.start();
}
public void startNamingServer()
throws Exception
{
// Create registry if not already running
try
{
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 startTopicServer()
throws Exception
{
// Create remote object
server = new TopicServerImpl(Integer.getInteger("chat.server.threads", 5).intValue());
// Load configuration
server.setPort(Integer.getInteger("chat.server.port", 0).intValue());
// Export server
UnicastRemoteObject.exportObject(server, server.getPort());
// Create a few topics
server.createTopic(new TopicInfo("Beginner RMI", "Welcome to the RMI beginner forum"));
server.createTopic(new TopicInfo("Advanced Java", "Welcome to the RMI advanced forum"));
server.createTopic(new TopicInfo("Cool tricks in RMI", "Welcome to the forum for cool RMI tricks"));
// Register server with naming service
new InitialContext().bind("topics",server);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -