import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.Serializable;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class RunRouterPattern {
public static void main(String[] arguments) {
System.out.println("Example for the Router pattern");
System.out
.println("This code same will create a series of GUIs, and use");
System.out
.println(" the Router pattern to map message notifications between");
System.out
.println(" them. In this code example, the Router will send messages");
System.out
.println(" between the GUI clients based on the following mapping:");
System.out.println();
System.out.println("/tGUI # 1:/tGUI #2/tGUI #3");
System.out.println("/tGUI # 2:/tGUI #1/tGUI #4");
System.out.println("/tGUI # 3:/tGUI #1/tGUI #4");
System.out.println("/tGUI # 4:/tGUI #1/tGUI #2/tGUI #3/tGUI #4");
System.out.println();
System.out.println("Running the RMI compiler (rmic)");
try {
Process p1 = Runtime.getRuntime().exec("rmic Router");
Process p2 = Runtime.getRuntime().exec("rmic RouterClient");
p1.waitFor();
p2.waitFor();
} catch (IOException exc) {
System.err
.println("Unable to run rmic utility. Exiting application.");
System.exit(1);
} catch (InterruptedException exc) {
System.err
.println("Threading problems encountered while using the rmic utility.");
}
System.out.println("Starting the rmiregistry");
System.out.println();
Process rmiProcess = null;
try {
rmiProcess = Runtime.getRuntime().exec("rmiregistry");
Thread.sleep(15000);
} catch (IOException exc) {
System.err
.println("Unable to start the rmiregistry. Exiting application.");
System.exit(1);
} catch (InterruptedException exc) {
System.err
.println("Threading problems encountered when starting the rmiregistry.");
Java中路由器模式
最新推荐文章于 2024-08-21 02:24:08 发布
这是一个使用Java实现路由器模式的例子,展示了如何通过RMI创建一个路由器对象,并连接多个客户端GUI。每个客户端可以发送消息,路由器根据预定义的路由规则将消息转发到相应的目标客户端。
摘要由CSDN通过智能技术生成