📄 main.java
字号:
import java.rmi.*;
import java.rmi.server.*;
import java.lang.*;
import java.util.*;
public class Main extends UnicastRemoteObject implements ChatInterface {
private ServerList serverList = new ServerList();
public Main() throws RemoteException {
}
public void join(Notify n, String name) throws RemoteException {
serverList.add(n);
serverList.incCounter();
for (Iterator i = serverList.getCollection().iterator();
i.hasNext();) {
Notify client = (Notify)i.next();
client.joinMessage(name);
}
serverList.decCounter();
}
public void talk(String name, String s)
throws RemoteException {
serverList.incCounter();
for (Iterator i = serverList.getCollection().iterator();
i.hasNext();) {
Notify client = (Notify)i.next();
client.sendMessage(name,s);
}
serverList.decCounter();
}
public synchronized void leave(Notify n, String name) throws RemoteException {
serverList.remove(n);
serverList.incCounter();
for (Iterator i = serverList.getCollection().iterator();
i.hasNext();) {
Notify client = (Notify)i.next();
client.exitMessage(name);
}
serverList.decCounter();
}
public static void main(String[] args) {
try {
Main server = new Main();
Naming.rebind("rmichat", server);
}
catch (java.net.MalformedURLException e) {
System.out.println("Malformed URL for MessageServer name "
+ e.toString());
}
catch (RemoteException e) {
System.out.println("Communication error " + e.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -