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

📄 conversationlist.java

📁 java实现的P2P多agent中间件
💻 JAVA
字号:
package jade.lang.acl;

import jade.core.Agent;
import jade.util.leap.Serializable;

import java.util.Vector;

/**
   This class represents a list of conversations that an agent is 
   currently carrying out and allows creating a <code>MessageTemplate</code> 
   that matches only messages that do not belong to any of these 
   conversations. 
 */
public class ConversationList implements Serializable{
	private Vector conversations = new Vector();
	protected Agent myAgent = null;
	protected int cnt = 0;
	
	private MessageTemplate myTemplate = new MessageTemplate(new MessageTemplate.MatchExpression() {
		public boolean match(ACLMessage msg) {
			String convId = msg.getConversationId();
			return (convId == null || (!conversations.contains(convId)));
		}
	} );
	
	/**
	   Construct a ConversationList to be used inside a given agent.
	 */
	public ConversationList(Agent a) {
		myAgent = a;
	}
	
	/**
	   Register a conversation creating a new unique ID.
	 */
	public String registerConversation() {
		String id = createConversationId();
		conversations.addElement(id);
		return id;
	}
	
	/**
	   Register a conversation with a given ID.
	 */
	public void registerConversation(String convId) {
		if (convId != null) {
			conversations.addElement(convId);
		}
	}
	
	/**
	   Deregister a conversation with a given ID.
	 */
	public void deregisterConversation(String convId) {
		if (convId != null) {
			conversations.removeElement(convId);
		}
	}

	/**
	   Deregister all conversations.
	 */
	public void clear() {
		conversations.removeAllElements();
	}
	
	/**
	   Return a template that matches only messages that do not belong to 
	   any of the conversations in this list.
	 */
	public MessageTemplate getMessageTemplate() {
		return myTemplate;
	}
	
	protected String createConversationId() {
		return myAgent.getName()+(cnt++);
	}
}
		

⌨️ 快捷键说明

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