⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eboardservant.java

📁 基于java rmi的白板
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -