?? mainjini.java
字號(hào):
/*
* Copyright 1999 by dreamBean Software,
* All rights reserved.
*/
package smartworld.server;
import java.io.IOException;
import java.io.File;
import java.lang.reflect.Proxy;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.server.RemoteObject;
import java.rmi.server.UnicastRemoteObject;
import net.jini.core.entry.Entry;
import net.jini.core.lookup.ServiceTemplate;
import net.jini.core.lookup.ServiceID;
import net.jini.lookup.JoinManager;
import net.jini.lookup.entry.Name;
import net.jini.lookup.ServiceIDListener;
import net.jini.discovery.DiscoveryListener;
import net.jini.discovery.DiscoveryEvent;
import smartworld.interfaces.SmartWorld;
import smartproxy.proxies.DynamicStubHandler;
import smartproxy.proxies.LogProxy;
import smartproxy.proxies.JiniServiceProxy;
import smartproxy.proxies.RetryProxy;
import smartproxy.proxies.PerformanceProxy;
import com.dreambean.dynaserver.DynaServer;
/**
* Main server class. This creates a remote object, and registers it
* with the Jini LUS service.
*
* @see SmartWorldImpl
* @author Rickard 謆erg (rickard@dreambean.com)
* @version $Revision:$
*/
public class MainJini
{
// Attributes ----------------------------------------------------
JoinManager joinManager;
DynaServer webserver;
// Static --------------------------------------------------------
/**
* Run server as stand-alone application.
*
* @param args
* @exception Exception
*/
public static void main(String[] args)
throws Exception
{
System.setSecurityManager(new SecurityManager()
{
public void checkPermission(java.security.Permission p)
{
}
});
System.getProperties().load(
Thread.currentThread().
getContextClassLoader().
getResourceAsStream("system.properties"));
new MainJini();
}
// Public --------------------------------------------------------
/**
* Create a remote object and register it with the RMI-registry.
*
*/
public MainJini()
throws Exception
{
startWebserver();
startService();
}
protected void startService()
throws Exception
{
// Set "java.protocol.handler.pkgs" to "smartproxy"
DynamicStubHandler.init();
// Create remote object
SmartWorld server = (SmartWorld)new SmartWorldImpl();
UnicastRemoteObject.exportObject(server);
// Create smart proxy wrappers
// Log on server
server = (SmartWorld) Proxy.newProxyInstance(SmartWorld.class.getClassLoader(),
new Class[] { SmartWorld.class },
new LogProxy(server));
UnicastRemoteObject.exportObject(server);
// The proxies below are executed on client
// Create service template
Class[] types = new Class[] { SmartWorld.class };
ServiceTemplate template = new ServiceTemplate(null, types, null);
// Jini lookup for reconnect
server = (SmartWorld) Proxy.newProxyInstance(SmartWorld.class.getClassLoader(),
new Class[] { SmartWorld.class },
new JiniServiceProxy(server, template));
// Retry
server = (SmartWorld) Proxy.newProxyInstance(SmartWorld.class.getClassLoader(),
new Class[] { SmartWorld.class },
new RetryProxy(server));
// Performance logging
server = (SmartWorld) Proxy.newProxyInstance(server.getClass().getClassLoader(),
new Class[] { SmartWorld.class },
new PerformanceProxy(server));
// Log on client
server = (SmartWorld) Proxy.newProxyInstance(SmartWorld.class.getClassLoader(),
new Class[] { SmartWorld.class },
new LogProxy(server));
// Register server with Jini Lookup Service
// Create attributes
Entry[] attributes = new Entry[]
{
new Name("SmartWorld service")
};
// Create a JoinManager
// This will register our service with Jini lookup services
ServiceIDListener sil = new ServiceIDListener()
{
public void serviceIDNotify(ServiceID serviceID)
{
System.out.println("Registered with LUS");
}
};
joinManager = new JoinManager(server,
attributes,
(ServiceIDListener)sil,
null,
null);
joinManager.getDiscoveryManager().addDiscoveryListener(new DiscoveryListener()
{
public void discovered(DiscoveryEvent e)
{
System.out.println("Discovered "+e);
}
public void discarded(DiscoveryEvent e)
{
System.out.println("Discarded "+e);
}
});
// Register server with naming service - client will use this to do initial lookup (not really necessary)
Naming.rebind(SmartWorld.NAME, server);
System.out.println("Server has been started");
new java.io.DataInputStream(System.in).readLine();
joinManager.terminate();
System.exit(0);
}
protected void startWebserver()
throws IOException
{
// Create webserver for dynamic class downloading
webserver = new DynaServer();
webserver.setDebug(true);
// Add the classloader for this application
// This will allow any client to download classes/resources that
// are in the classpath for this application
webserver.addClassLoader(Thread.currentThread().getContextClassLoader());
// Start the webserver
webserver.start();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -