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

📄 aclmessage.java

📁 java实现的P2P多agent中间件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************
 JADE - Java Agent DEvelopment Framework is a framework to develop 
 multi-agent systems in compliance with the FIPA specifications.
 Copyright (C) 2000 CSELT S.p.A. 
 
 GNU Lesser General Public License
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation, 
 version 2.1 of the License. 
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the
 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 Boston, MA  02111-1307, USA.
 *****************************************************************/

package jade.lang.acl;

//#MIDP_EXCLUDE_BEGIN
import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.lang.ClassNotFoundException;
//#MIDP_EXCLUDE_END

import java.util.Date;

import jade.util.leap.Serializable;
import jade.util.leap.ArrayList;
import jade.util.leap.Iterator;
import jade.util.leap.Properties;
import jade.util.leap.EmptyIterator;

import jade.util.leap.EnumIterator;
import java.util.Vector;

import jade.core.AID;
//#CUSTOM_EXCLUDE_BEGIN
import jade.domain.FIPAAgentManagement.Envelope;
//#CUSTOM_EXCLUDE_END


/**
 * The class ACLMessage implements an ACL message compliant to the <b>FIPA 2000</b> "FIPA ACL Message Structure Specification" (fipa000061) specifications.
 * All parameters are couples <em>keyword: value</em>.
 * All keywords are <code>private final String</code>.
 * All values can be set by using the methods <em>set</em> and can be read by using
 * the methods <em>get</em>. 
 * <p> <b>Warning: </b> since JADE 3.1  an exception might be thrown 
 * during the serialization of the ACLMessage parameters (with 
 * exception of the content of the ACLMessage) because of a limitation
 * to 65535 in the total number of bytes needed to represent all the 
 * characters of a String (see also java.io.DataOutput#writeUTF(String)).
 * <p> The methods <code> setByteSequenceContent() </code> and 
 * <code> getByteSequenceContent() </code> allow to send arbitrary
 * sequence of bytes
 * over the content of an ACLMessage.
 * <p> The couple of methods 
 * <code> setContentObject() </code> and 
 * <code> getContentObject() </code> allow to send
 * serialized Java objects over the content of an ACLMessage.
 * These method are not strictly 
 * FIPA compliant so their usage is not encouraged.
 * @author Fabio Bellifemine - CSELT
 * @version $Date: 2006-03-27 12:57:34 +0200 (lun, 27 mar 2006) $ $Revision: 5875 $
 * @see <a href=http://www.fipa.org/specs/fipa00061/XC00061D.html>FIPA Spec</a>
 */
//#MIDP_EXCLUDE_BEGIN 
public class ACLMessage implements Cloneable, Serializable {
//#MIDP_EXCLUDE_END 
/*#MIDP_INCLUDE_BEGIN 
public class ACLMessage implements Serializable {
#MIDP_INCLUDE_END*/ 
	// Explicitly set for compatibility between standard and micro version
	private static final long serialVersionUID=3945353187608998130L;
	
	/** constant identifying the FIPA performative **/
	public static final int ACCEPT_PROPOSAL = 0;
	/** constant identifying the FIPA performative **/
	public static final int AGREE = 1;
	/** constant identifying the FIPA performative **/
	public static final int CANCEL = 2;
	/** constant identifying the FIPA performative **/
	public static final int CFP = 3;
	/** constant identifying the FIPA performative **/
	public static final int CONFIRM = 4;
	/** constant identifying the FIPA performative **/
	public static final int DISCONFIRM = 5;
	/** constant identifying the FIPA performative **/
	public static final int FAILURE = 6;
	/** constant identifying the FIPA performative **/
	public static final int INFORM = 7;
	/** constant identifying the FIPA performative **/
	public static final int INFORM_IF = 8;
	/** constant identifying the FIPA performative **/
	public static final int INFORM_REF = 9;
	/** constant identifying the FIPA performative **/
	public static final int NOT_UNDERSTOOD = 10;
	/** constant identifying the FIPA performative **/
	public static final int PROPOSE = 11;
	/** constant identifying the FIPA performative **/
	public static final int QUERY_IF = 12;
	/** constant identifying the FIPA performative **/
	public static final int QUERY_REF = 13;
	/** constant identifying the FIPA performative **/
	public static final int REFUSE = 14;
	/** constant identifying the FIPA performative **/
	public static final int REJECT_PROPOSAL = 15;
	/** constant identifying the FIPA performative **/
	public static final int REQUEST = 16;
	/** constant identifying the FIPA performative **/
	public static final int REQUEST_WHEN = 17;
	/** constant identifying the FIPA performative **/
	public static final int REQUEST_WHENEVER = 18;
	/** constant identifying the FIPA performative **/
	public static final int SUBSCRIBE = 19;
	/** constant identifying the FIPA performative **/
	public static final int PROXY = 20;
	/** constant identifying the FIPA performative **/
	public static final int PROPAGATE = 21;
	/** constant identifying an unknown performative **/
	public static final int UNKNOWN = -1;
	
	/**
	 @serial
	 */
	private int performative; // keeps the performative type of this object
	/** This array of Strings keeps the names of the performatives **/
	private static final String[] performatives = new String[22];
	static { // initialization of the Vector of performatives
		performatives[ACCEPT_PROPOSAL]="ACCEPT-PROPOSAL";
		performatives[AGREE]="AGREE";
		performatives[CANCEL]="CANCEL";
		performatives[CFP]="CFP";
		performatives[CONFIRM]="CONFIRM";
		performatives[DISCONFIRM]="DISCONFIRM";
		performatives[FAILURE]="FAILURE";
		performatives[INFORM]="INFORM";
		performatives[INFORM_IF]="INFORM-IF";
		performatives[INFORM_REF]="INFORM-REF";
		performatives[NOT_UNDERSTOOD]="NOT-UNDERSTOOD";
		performatives[PROPOSE]="PROPOSE";
		performatives[QUERY_IF]="QUERY-IF";
		performatives[QUERY_REF]="QUERY-REF";
		performatives[REFUSE]="REFUSE";
		performatives[REJECT_PROPOSAL]="REJECT-PROPOSAL";
		performatives[REQUEST]="REQUEST";
		performatives[REQUEST_WHEN]="REQUEST-WHEN";
		performatives[REQUEST_WHENEVER]="REQUEST-WHENEVER";
		performatives[SUBSCRIBE]="SUBSCRIBE";
		performatives[PROXY]="PROXY";
		performatives[PROPAGATE]="PROPAGATE";
	}
	
	/**
	 * User defined parameter key specifying, when set to "true", that if the delivery of a 
	 * message fails, no FAILURE notification has to be sent back to the sender.
	 */
	public static final String IGNORE_FAILURE = "JADE-ignore-failure";
	
	/**
	 * User defined parameter key specifying that the corresponding value must be replaced by the JADE runtime
	 * by an ISO8601 encoded time-stamp at posting time.
	 */
	public static final String POST_TIME_STAMP = "JADE-post-ts";
	
	/**
	 * User defined parameter key specifying that the JADE tracing mechanism should be activated for this message.
	 */
	public static final String TRACE = "JADE-trace";
	
	/**
	 @serial
	 */
	private AID source = null;
	
	/** These constants represent the expected size of the 2 array lists
	 * used by this class **/
	private static final int RECEIVERS_EXPECTED_SIZE = 1;
	private static final int REPLYTO_EXPECTED_SIZE = 1;
	
	//#MIDP_EXCLUDE_BEGIN
	private ArrayList dests = new ArrayList(RECEIVERS_EXPECTED_SIZE);
	private ArrayList reply_to = null; 
	//#MIDP_EXCLUDE_END
	/*#MIDP_INCLUDE_BEGIN
	 private Vector dests = new Vector(RECEIVERS_EXPECTED_SIZE);
	 private Vector reply_to = null; 
	 #MIDP_INCLUDE_END*/
	
	
	
	/**
	 @serial
	 */
	// At a given time or content or byteSequenceContent are != null,
	// it is not allowed that both are != null
	private StringBuffer content = null;
	private byte[] byteSequenceContent = null;
	
	/**
	 @serial
	 */
	private String reply_with = null;
	
	/**
	 @serial
	 */
	private String in_reply_to = null;
	
	/**
	 @serial
	 */
	private String encoding = null;
	
	/**
	 @serial
	 */
	private String language = null;
	
	/**
	 @serial
	 */
	private String ontology = null;
	
	/**
	 @serial
	 */
	private long reply_byInMillisec = 0; 
	
	/**
	 @serial
	 */
	private String protocol = null;
	
	/**
	 @serial
	 */
	private String conversation_id = null;
	
	private Properties userDefProps = null; 
	//#CUSTOM_EXCLUDE_BEGIN
	private Envelope messageEnvelope;
	//#CUSTOM_EXCLUDE_END
	
	/**
	 Returns the list of the communicative acts as an array of <code>String</code>.
	 */
	public static String[] getAllPerformativeNames()
	{
		return performatives;
	}
	
	/**
	 @deprecated Since every ACL Message must have a message type, you
	 should use the new constructor which gets a message type as a
	 parameter.  To avoid problems, now this constructor silently sets
	 the message type to <code>not-understood</code>.
	 @see jade.lang.acl.ACLMessage#ACLMessage(int)
	 */
	public ACLMessage() { // Used by persistence service: do not remove it, but make it private
		performative = NOT_UNDERSTOOD;
	}
	
	
	
	
	/**
	 * This constructor creates an ACL message object with the specified
	 * performative. If the passed integer does not correspond to any of
	 * the known performatives, it silently initializes the message to
	 * <code>not-understood</code>.
	 **/
	public ACLMessage(int perf) {
		performative = perf;
	}
	
	/**
	 Writes the <code>:sender</code> slot. <em><b>Warning:</b> no
	 checks are made to validate the slot value.</em>
	 @param source The new value for the slot.
	 @see jade.lang.acl.ACLMessage#getSender()
	 */
	public void setSender(AID s) {
		source = s; 
	}
	
	/**
	 Adds a value to <code>:receiver</code> slot. <em><b>Warning:</b>
	 no checks are made to validate the slot value.</em>
	 @param r The value to add to the slot value set.
	 */
	public void addReceiver(AID r) {
		if(r != null) {
			//#MIDP_EXCLUDE_BEGIN
			dests.add(r);
			//#MIDP_EXCLUDE_END
			/*#MIDP_INCLUDE_BEGIN
			 dests.addElement(r);
			 #MIDP_INCLUDE_END*/
		}
	}
	
	/**
	 Removes a value from <code>:receiver</code>
	 slot. <em><b>Warning:</b> no checks are made to validate the slot
	 value.</em>
	 @param r The value to remove from the slot value set.
	 @return true if the AID has been found and removed, false otherwise
	 */
	public boolean removeReceiver(AID r) {
		if (r != null) {
			//#MIDP_EXCLUDE_BEGIN
			return dests.remove(r);
			//#MIDP_EXCLUDE_END
			/*#MIDP_INCLUDE_BEGIN
			 return dests.removeElement(r);
			 #MIDP_INCLUDE_END*/
		}
		else {
			return false;
		}
	}
	
	/**
	 Removes all values from <code>:receiver</code>
	 slot. <em><b>Warning:</b> no checks are made to validate the slot
	 value.</em> 
	 */
	public void clearAllReceiver() {
		//#MIDP_EXCLUDE_BEGIN
		dests.clear();
		//#MIDP_EXCLUDE_END
		/*#MIDP_INCLUDE_BEGIN
		 dests.removeAllElements();
		 #MIDP_INCLUDE_END*/
	}
	
	
	
	/**
	 Adds a value to <code>:reply-to</code> slot. <em><b>Warning:</b>
	 no checks are made to validate the slot value.</em>
	 @param dest The value to add to the slot value set.
	 */
	public void addReplyTo(AID dest) {
		if (dest != null) { 
			//#MIDP_EXCLUDE_BEGIN
			reply_to = (reply_to == null ? new ArrayList(REPLYTO_EXPECTED_SIZE) : reply_to);
			reply_to.add(dest);
			//#MIDP_EXCLUDE_END
			/*#MIDP_INCLUDE_BEGIN
			 reply_to = (reply_to == null ? new Vector(REPLYTO_EXPECTED_SIZE) : reply_to);
			 reply_to.addElement(dest);
			 #MIDP_INCLUDE_END*/
		}
	}
	
	/**
	 Removes a value from <code>:reply_to</code>
	 slot. <em><b>Warning:</b> no checks are made to validate the slot
	 value.</em>
	 @param dest The value to remove from the slot value set.
	 @return true if the AID has been found and removed, false otherwise
	 */
	public boolean removeReplyTo(AID dest) {
		if ((dest != null) && (reply_to != null) ) {
			//#MIDP_EXCLUDE_BEGIN
			return reply_to.remove(dest);
			//#MIDP_EXCLUDE_END
			/*#MIDP_INCLUDE_BEGIN
			 return reply_to.removeElement(dest);
			 #MIDP_INCLUDE_END*/ 
		}
		else {
			return false;
		}
	}
	
	/**
	 Removes all values from <code>:reply_to</code>
	 slot. <em><b>Warning:</b> no checks are made to validate the slot
	 value.</em> 
	 */
	public void clearAllReplyTo() {
		if (reply_to != null) {
			//#MIDP_EXCLUDE_BEGIN
			reply_to.clear();

⌨️ 快捷键说明

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