📄 registerwithrmicommunityserver.java
字号:
import java.rmi.*;
import java.rmi.registry.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.net.MalformedURLException;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class RegisterWithRMICommunityServer{
/** Main method */
public static void main(String[] args) {
//? System.setSecurityManager(new RMISecurityManager());
try {
CommunityServerInterfaceImpl obj =
new CommunityServerInterfaceImpl();
registerToRegistry("CommunityServerInterfaceImpl", obj, true);
System.out.println("VirtualCommunity server " + obj + " registered");
}
catch (RemoteException ex) {
ex.printStackTrace();
}
catch (MalformedURLException ex) {
ex.printStackTrace();
}
MyPanel1 applet = new MyPanel1();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("VirtualCommunity Sql Operator Server");
frame.getContentPane().add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(700, 500);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2,
(d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
/** Register StudentImpl object with the RMI registry.
* @param name - name identifying the service in the RMI registry
* @param create - create local registry if necessary
* @throw RemoteException if cannot be exported or bound to RMI
* registry
* @throw MalformedURLException if name cannot be used to
* construct a valid URL
* @throw IllegalArgumentException if null passed as name
*/
public static void registerToRegistry(String name, Remote obj,
boolean create) throws RemoteException, MalformedURLException{
if (name == null) throw new IllegalArgumentException(
"registration name can not be null");
try {
Naming.rebind(name, obj);
}
catch (RemoteException ex) {
if (create) {
try{
Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
r.rebind(name, obj);
}
catch(Exception e){System.out.println("Cann\'t rebind! ");}
} else throw ex;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -