mailboxtry11.java

来自「一个agent 工具包,可以开发移动设备应用,考虑了安全措施」· Java 代码 · 共 61 行

JAVA
61
字号
import SOMA.agent.*;
import SOMA.naming.*;

import java.util.*;

public class MailboxTry11 extends Agent {
	
	private PlaceID home;
	private AgentID parent;
	private int destinationIndex;
	private String manipulation = "";
	
	public void putArgument(Object obj) {
		
		Vector temp = (Vector) obj;
		home = (PlaceID) temp.get(0);
		parent = (AgentID) temp.get(1);
		destinationIndex = ((Integer) temp.get(2)).intValue();
		
	}
	
	public void run() {
		
		try {
			go((PlaceID) agentSystem.sharedObjects.get(destinationIndex), "buildString");
		} catch (CantGoException cge) {
			cge.printStackTrace();
		}
		
	}
	
	public void buildString() {
		
		Vector places = new Vector(Arrays.asList(agentSystem.getPlaces()));
		places.remove(agentSystem.getPlaceID());
		for (int index = places.size() - 1; index >= 0; index--) {
			PlaceID place = (PlaceID) places.get(index);
			manipulation += " " + place.toString();
		}
		
		try {
			go(home, "atHome");
		} catch (CantGoException cge) {
			cge.printStackTrace();
		}
	
	}
	
	public void atHome() {
		
		// Substitute the old object (a PlaceID) with the String previously built
		agentSystem.sharedObjects.remove(destinationIndex);
		agentSystem.sharedObjects.put(destinationIndex, manipulation);
		// the agent has done, and notifies it to its parent
		Message mex = new Message("lurker_agent_done", getID(), parent);
		agentSystem.sendMessage(mex);
	
	}
	
} // end MailboxTry11

⌨️ 快捷键说明

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