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

📄 worktype.java

📁 一个java的rmi实例
💻 JAVA
字号:
import java.io.*;
import java.net.*;
import java.util.*;

public class WorkType
{
	
		public static final int INITIALIZE = 1;
    	public static final int FIND = 2;
    	public static final int FIND_ALL = 3;
    	public static final int PRINT_ALL = 4;
	public static int nextObjKey = 0;
 	private int ObjKey;
	
		public WorkType() 
	{	ObjKey = nextObjKey;
		nextObjKey++;
     	}
	
	
	 
 
 
 
 
   
 
    	// When the following method is called, marshalled data
    	// should be sent to this remote object, and reconstructed.
    	public void initialise(ZipCodeList newlist)
    	{	String temp = "";
               int RtnType;
        	// Marshall MethodID
        	//temp += INITIALIZE + "\n";
        	RtnType=INITIALIZE;
        	

        	// Marshall Method Args
        	ZipCodeList iter = newlist;
 		int length = 0;
		while(iter != null)
		{	length++;
			iter = iter.next;
		}
		
		temp += "ZipCodeList," ;
		temp += length + ",";
		temp += "String,city,";
		temp += "String,ZipCode,";
		
		iter = newlist;
		
	 	while(iter != null)
		{	temp += iter.city + "," ;
	   		temp += iter.ZipCode + "," ;
	   		iter = iter.next;
		}
        	String reply = ZipCodeServerImpl_stub.send(this,ZipCodeServerImpl_stub .REQUEST,RtnType,temp);
        	return;
	}

    	// Basic function: look up a city name, and return its zipcode.
    	public String find(String request)
    	{	// Search the list.
        	String temp = "";
                 int RtnType;
        	// Marshall MethodID
        //	temp += FIND + "\n";
        RtnType=FIND;

        	// Marshall Method Args
        	temp += request;
		String reply =ZipCodeServerImpl_stub.send(this, ZipCodeServerImpl_stub .REQUEST,RtnType,temp);
        	return reply;
    	}

    	// The following short method should send the marshalled 
    	// whole list to the client site.  The main challenge is coding
    	// the skeleton.
    	public ZipCodeList findAll()
    	{	String temp = "";
                 int RtnType;
        	// Marshall MethodID
        //	temp += FIND_ALL + "\n";
           RtnType=FIND_ALL;
        	String reply =ZipCodeServerImpl_stub.send(this, ZipCodeServerImpl_stub .REQUEST,RtnType, temp);
        	String[] arr = reply.split(","); 

        	String returnType = arr[0];
        	int length = Integer.parseInt(arr[1]);
        	String fieldType1 = arr[2];
        	String fieldName1 = arr[3];
        
        	String fieldType2 = arr[4];
        	String fieldName2 = arr[5];
        
        
        	ZipCodeList prev = new ZipCodeList(arr[6], arr[7], null);
        	ZipCodeList start = prev;
        
        	// Unmarshall Method Args
        	for(int i = 8; i < arr.length; i+=2)
		{	ZipCodeList n = new ZipCodeList(arr[i], arr[i+1], null);
          		prev.next = n;
          		prev = n;
	  	}	
		return start;
   	}

    	// The following method prints at the server site.
    	public void printAll()
    	{	String temp = "";
                 int RtnType;
        	// Marshall MethodID
        //	temp += PRINT_ALL + "\n";
        RtnType=PRINT_ALL;

        	String reply =ZipCodeServerImpl_stub.send(this, ZipCodeServerImpl_stub .REQUEST,RtnType, temp);
        	return;
    	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -