eboardservant.java
来自「基于java rmi的白板」· Java 代码 · 共 91 行
JAVA
91 行
package whiteboard;
import java.rmi.*;
import java.util.Vector;
import java.rmi.server.UnicastRemoteObject;
public class eboardServant extends UnicastRemoteObject implements eboard
{
private Vector customerList;
private Vector shapeList;
private int count=0;
public eboardServant() throws RemoteException
{
customerList=new Vector();
shapeList=new Vector();
}
public void add(shape g) throws RemoteException
{
shapeList.add(g);
for(int i=0;i<customerList.size();i++)
{
try{
CallBack cb=((parcel)(customerList.elementAt(i))).callback;
cb.callback(false);
}catch(Exception e)
{
;
}
}
System.out.println("new shape coming");
}
public Vector getall()throws RemoteException
{
return shapeList;
}
public int regist(CallBack callback) throws RemoteException
{
customerList.add(new parcel(callback,count));
System.out.println("new custommer coming");
int temp=count;
count=(count+1)%1000;
return temp;
}
public void deregist(int callbackid) throws RemoteException
{
for(int i=0;i<customerList.size();i++)
{
if(((parcel)(customerList.elementAt(i))).tag==callbackid)
customerList.remove(i);
}
System.out.println("one custommer leave");
}
public void clear() throws RemoteException
{
shapeList.clear();
for(int i=0;i<customerList.size();i++)
{
try{
CallBack cb=((parcel)(customerList.elementAt(i))).callback;
cb.callback(true);
}catch(Exception e)
{
;
}
}
System.out.println("clear");
}
}
class parcel
{
CallBack callback;
int tag;
public parcel(CallBack cback,int t)
{
callback=cback;
tag=t;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?