📄 df.java
字号:
/*****************************************************************
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.domain;
//#MIDP_EXCLUDE_FILE
import java.util.Enumeration;
import java.util.Vector;
import java.util.Date;
import jade.util.leap.HashMap;
import jade.util.leap.ArrayList;
import jade.util.leap.List;
import jade.util.leap.Iterator;
import jade.util.leap.Properties;
import jade.util.Logger;
import java.net.InetAddress;
import jade.core.AID;
import jade.core.behaviours.*;
import jade.domain.FIPAAgentManagement.*;
import jade.domain.FIPAAgentManagement.InternalError;
import jade.domain.JADEAgentManagement.*;
import jade.domain.KBManagement.*;
import jade.domain.DFGUIManagement.*;
import jade.domain.DFGUIManagement.GetDescription; // Explicitly imported to avoid conflict with FIPA management ontology
//#PJAVA_EXCLUDE_BEGIN
import jade.domain.introspection.AMSSubscriber;
import jade.domain.introspection.Event;
import jade.domain.introspection.IntrospectionVocabulary;
import jade.domain.introspection.DeadAgent;
//#PJAVA_EXCLUDE_END
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.lang.acl.ISO8601;
import jade.gui.GuiAgent;
import jade.gui.GuiEvent;
import jade.proto.SubscriptionResponder;
import jade.proto.AchieveREInitiator;
import jade.content.*;
import jade.content.lang.*;
import jade.content.lang.sl.*;
import jade.content.onto.basic.*;
/**
<p>
Standard <em>Directory Facilitator</em> agent. This class implements
<em><b>FIPA</b></em> <em>DF</em> agent. <b>JADE</b> applications
typically don't use this class directly, but interact with the DF agent through
<em>ACL</em> message passing. The <code>DFService</code> class provides
a number of static methods that facilitate this task.
More <em>DF</em> agents can be created
by application programmers to divide a platform into many
<em><b>Agent Domains</b></em>.
<p>
A DF agent accepts a number of optional configuration parameters that can be set
either as command line options or within a properties file (to be passed to
the DF as an argument).
</p>
<table border="1" cellspacing="0">
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
<tr>
<td>
<code>jade_domain_df_autocleanup</code>
</td>
<td>
If set to <code>true</code>, indicates that the DF will automatically
clean up registrations as soon as an agent terminates. The default is <code>false</code>
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_maxleasetime</code>
</td>
<td>
Indicates the maximum lease time (in millisecond) that the DF will grant for agent
description registrations (defaults to infinite).
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_maxresult</code>
</td>
<td>
Indicates the maximum number of items found in a search operation that the DF
will return to the requester (defaults to 100).
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_disablevalidation</code>
</td>
<td>
Turns off content validation on incoming/outgoing messages (defaults to false)
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_db-default</code>
</td>
<td>
If set to <code>true</code>, indicates that the DF will store its catalogue into an internal HSQL database,
running within the same VM. (The HSQL jar files have to added to the Java CLASSPATH)
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_db-url</code>
</td>
<td>
Indicates the JDBC URL of the database the DF will store its catalogue into.
This parameter is ignored if <code>jade_domain_df_db-default</code> is set. If neither this parameter nor
<code>jade_domain_df_db-default</code> is specified the DF will keep its catalogue in memory.
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_db-driver</code>
</td>
<td>
Indicates the JDBC driver to be used to access the DF database (defaults to the ODBC-JDBC bridge). This parameter
is ignored if <code>jade_domain_df_db-url</code> is not set or <code>jade_domain_df_db-default</code> is set.
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_db-username</code>,
<code>jade_domain_df_db-password</code>
</td>
<td>
Indicate the username and password to be used to access the DF database (default to null).
These parameters are ignored if <code>jade_domain_df_db-url</code> is not set or
<code>jade_domain_df_db-default</code> is set.
</td>
</tr>
<td>
<code>jade_domain_df_db-cleantables</code>
</td>
<td>
If set to <code>true</code>, indicates that the DF will clean the content of all pre-existing database tables,
used by the DF. This parameter is ignored if the catalogue is not stored in a database.
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_db-abortonerror</code>
</td>
<td>
If set to <code>true</code>, indicates that the DF will immediately terminate in case it cannot
connect to the database. This parameter is ignored if the catalogue is not stored in a database.
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_kb-factory</code>
</td>
<td>
Indicates the name of the factory class that
should be used to create the knowledge base objects for the DF. The class has to be
a sub class of jade.domain.DFKBFactory.
</td>
</tr>
<tr>
<td>
<code>jade_domain_df_poolsize</code>
</td>
<td>
The dimension of the pool of thread dedicated to serving registration, deregistration and search
requests. If <code>0</code> (default) is specified then registration, deregistration and search
requests are served directly by the df agent Thread. This parameter is ignored when using a
volatile (in-memory) knowledge base.
</td>
</tr>
</table>
<p>
For instance the following command line will launch a JADE main container
with a DF that will store its catalogue into a database accessible at
URL jdbc:odbc:dfdb and that will keep agent registrations for 1 hour at most.
<code>
java jade.Boot -gui -jade_domain_df_db-url jdbc:odbc:dfdb -jade_domain_df_maxleasetime 3600000
</code>
<p>
Each DF has a GUI but, by default, it is not visible. The GUI of the
agent platform includes a menu item that allows to show the GUI of the
default DF.
In order to show the GUI, you should simply send the following message
to each DF agent: <code>(request :content (action DFName (SHOWGUI))
:ontology JADE-Agent-Management :protocol fipa-request)</code>
@see DFService
@author Giovanni Rimassa - Universita' di Parma
@author Tiziana Trucco - TILAB S.p.A.
@author Elisabetta Cortese - TILAB S.p.A.
@author Giovanni Caire - TILAB
@author Roland Mungenast - Profactor
@version $Date: 2007-03-30 18:30:14 +0200 (ven, 30 mar 2007) $ $Revision: 5952 $
*/
public class df extends GuiAgent implements DFGUIAdapter {
//#APIDOC_EXCLUDE_BEGIN
// FIXME The size of the cache must be read from the Profile
private final static int SEARCH_ID_CACHE_SIZE = 16;
private jade.util.HashCache searchIdCache = new jade.util.HashCache(SEARCH_ID_CACHE_SIZE);
private int searchIdCnt = 0;
// The DF federated with this DF
private List children = new ArrayList();
// The DF this DF is federated with
private List parents = new ArrayList();
// Maps a parent DF to the description used by this DF to federate with that parent
private HashMap dscDFParentMap = new HashMap();
// Maps an action that is being serviced by a Behaviour to the
// request message that activated the Behaviour and the notification message
// to be sent back (as soon as the Behaviour will complete) to the requester
private HashMap pendingRequests = new HashMap();
// The GUI of this DF
private DFGUIInterface gui;
// Current description of this df
private DFAgentDescription myDescription = null;
private Codec codec = new SLCodec();
//#PJAVA_EXCLUDE_BEGIN
// This is used in case a pool-size != 0 is specified to serve FIPA requests
private ThreadedBehaviourFactory tbf;
private AMSSubscriber amsSubscriber;
//#PJAVA_EXCLUDE_END
// Configuration parameter keys
private static final String AUTOCLEANUP = "jade_domain_df_autocleanup";
private static final String POOLSIZE = "jade_domain_df_poolsize";
private static final String MAX_LEASE_TIME = "jade_domain_df_maxleasetime";
private static final String MAX_RESULTS = "jade_domain_df_maxresult";
private static final String DISABLE_VALIDATION = "jade_domain_df_disablevalidation";
private static final String DB_DRIVER = "jade_domain_df_db-driver";
private static final String DB_URL = "jade_domain_df_db-url";
private static final String DB_USERNAME = "jade_domain_df_db-username";
private static final String DB_PASSWORD = "jade_domain_df_db-password";
private static final String KB_FACTORY = "jade_domain_df_kb-factory";
private static final String DB_DEFAULT = "jade_domain_df_db-default";
private static final String DB_CLEANTABLES = "jade_domain_df_db-cleantables";
private static final String DB_ABORTONERROR = "jade_domain_df_db-abortonerror";
// Limit of searchConstraints.maxresult
// FIPA Agent Management Specification doc num: SC00023J (6.1.4 Search Constraints)
// a negative value of maxresults indicates that the sender agent is willing to receive
// all available results
private static final String DEFAULT_MAX_RESULTS = "100";
/*
* This is the actual value for the limit on the maximum number of results to be
* returned in case of an ulimited search. This value is read from the Profile,
* if no value is set in the Profile, then DEFAULT_MAX_RESULTS is used instead.
*/
private int maxResultLimit = Integer.parseInt(DEFAULT_MAX_RESULTS);
private Date maxLeaseTime = null;
private KB agentDescriptions = null;
private KBSubscriptionManager subManager = null;
private SubscriptionResponder dfSubscriptionResponder;
private Logger logger;
/**
Default constructor. This constructor does nothing; however,
applications can create their own DF agents using regular
platform management commands. Moreover, customized versions of
a Directory Facilitator agent can be built subclassing this
class and exploiting its protected interface.
*/
public df() {
}
/**
This method starts all behaviours needed by <em>DF</em> agent to
perform its role within <em><b>JADE</b></em> agent platform.
*/
protected void setup() {
logger = Logger.getMyLogger(getLocalName());
String sDisableValidation = getProperty(DISABLE_VALIDATION, "false");
//#PJAVA_EXCLUDE_BEGIN
// ---------- Read configuration ----------
// If an argument is specified, it indicates the name of a properties
// file where to read DF configuration from. Otherwise configuration
// properties are read from the Profile.
// Values in a property file override those in the profile if
// both are specified.
String sAutocleanup = getProperty(AUTOCLEANUP, null);
String sPoolsize = getProperty(POOLSIZE, null);
String sMaxLeaseTime = getProperty(MAX_LEASE_TIME, null);
String sMaxResults = getProperty(MAX_RESULTS, DEFAULT_MAX_RESULTS);
String dbUrl = getProperty(DB_URL, null);
String dbDriver = getProperty(DB_DRIVER, null);
String dbUsername = getProperty(DB_USERNAME, null);
String dbPassword = getProperty(DB_PASSWORD, null);
String kbFactClass = getProperty(KB_FACTORY, null);
String sDBDefault = getProperty(DB_DEFAULT, null);
String sCleanTables = getProperty(DB_CLEANTABLES, null);
String sDBAbortOnError = getProperty(DB_ABORTONERROR, null);
Object[] args = this.getArguments();
if(args != null && args.length > 0) {
Properties p = new Properties();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -