📄 df.java
字号:
// Do it
DFDeregister(dfd);
}
/**
Serve the Modify action of the FIPA management ontology.
Package scoped since it is called by DFFipaAgentManagementBehaviour.
*/
void modifyAction(Modify m, AID requester) throws FIPAException {
DFAgentDescription dfd = (DFAgentDescription) m.getDescription();
// Check mandatory slots
DFService.checkIsValid(dfd, true);
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester.getName()+" requesting action Modify for "+dfd.getName());
// Do it
DFModify(dfd);
}
/**
Serve the Search action of the FIPA management ontology.
Package scoped since it is called by DFFipaAgentManagementBehaviour.
@return the List of descriptions matching the template specified
in the Search action. If no description is found an empty List
is returned. In case a recursive search is required it returns
null to indicate that the result is not yet available.
*/
List searchAction(Search s, AID requester) throws FIPAException {
DFAgentDescription dfd = (DFAgentDescription) s.getDescription();
SearchConstraints constraints = s.getConstraints();
List result = null;
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester.getName()+" requesting action Search");
// Avoid loops in searching on federated DFs
checkSearchId(constraints.getSearchId());
int maxResult = getActualMaxResults(constraints);
// Search locally
result = DFSearch(dfd, maxResult);
// Note that if the local search produced more results than
// required, we don't even consider the recursive search
// regardless of the maxDepth parameter.
if(result.size() < maxResult) {
// Check if the search has to be propagated
Long maxDepth = constraints.getMaxDepth();
if ( (children.size() > 0) && (maxDepth != null) && (maxDepth.intValue() > 0) ) {
// Start a recursive search.
performRecursiveSearch(result, dfd, constraints, s);
// The final result will be available at a later time.
return null;
}
}
return result;
}
/**
Serve a Search action of the FIPA management ontology requested
using an iterated-fipa-request protocol.
Package scoped since it is called by DFIteratedSearchManagementBehaviour.
@return an iterator over the DFAgentDescription matching the specified
search template.
*/
KBIterator iteratedSearchAction(Search s, AID requester) throws FIPAException {
DFAgentDescription dfd = (DFAgentDescription) s.getDescription();
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester.getName()+" requesting action Iterated-Search");
return DFIteratedSearch(dfd);
}
////////////////////////////////////////////////////////////////
// Methods serving the actions of the JADE Management ontology
////////////////////////////////////////////////////////////////
/**
Serve the ShowGui action of the JADE management ontology.
Package scoped since it is called by DFJadeAgentManagementBehaviour.
@exception FailureException If the GUI is already visible or some
error occurs creating the GUI.
*/
void showGuiAction(ShowGui sg, AID requester) throws FailureException {
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester.getName()+" requesting action ShowGui");
if (!showGui()){
throw new FailureException("Gui_is_being_shown_already");
}
}
//////////////////////////////////////////////////////////
// Methods serving the actions of the DF-Applet ontology
//////////////////////////////////////////////////////////
/**
Serve the GetParents action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
List getParentsAction(GetParents action, AID requester) {
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action GetParents.");
return parents;
}
/**
Serve the GetDescription action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
List getDescriptionAction(GetDescription action, AID requester) {
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action GetDescription.");
// FIXME: This embeds the description into a list since the Applet still expects a List
List tmp = new ArrayList();
tmp.add(getDescriptionOfThisDF());
return tmp;
}
/**
Serve the GetDescriptionUsed action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
List getDescriptionUsedAction(GetDescriptionUsed action, AID requester) {
AID parent = action.getParentDF();
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action GetDescriptionUsed to federate with "+parent.getName());
// FIXME: This embeds the description into a list since the Applet still expects a List
List tmp = new ArrayList();
tmp.add(getDescriptionOfThisDF(parent));
return tmp;
}
/**
Serve the Federate action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
void federateAction(final Federate action, AID requester) {
AID remoteDF = action.getDf();
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action Federate with DF "+remoteDF.getName());
Register r = new Register();
DFAgentDescription tmp = action.getDescription();
final DFAgentDescription dfd = (tmp != null ? tmp : getDescriptionOfThisDF());
r.setDescription(dfd);
Behaviour b = new RemoteDFRequester(remoteDF, r) {
public int onEnd() {
Object result = getResult();
if (!(result instanceof InternalError)) {
addParent(getRemoteDF(), dfd);
}
sendPendingNotification(action, result);
return 0;
}
};
addBehaviour(b);
}
/**
Serve the RegisterWith action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
void registerWithAction(final RegisterWith action, AID requester){
AID remoteDF = action.getDf();
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action RegisterWith on DF "+remoteDF.getName());
Register r = new Register();
final DFAgentDescription dfd = action.getDescription();
r.setDescription(dfd);
Behaviour b = new RemoteDFRequester(remoteDF, r) {
public int onEnd() {
Object result = getResult();
if (!(result instanceof InternalError)) {
if(dfd.getName().equals(myAgent.getAID())) {
// The registered agent is the DF itself --> This is a federation
addParent(getRemoteDF(), dfd);
}
}
sendPendingNotification(action, result);
return 0;
}
};
addBehaviour(b);
}
/**
Serve the DeregisterFrom action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
void deregisterFromAction(final DeregisterFrom action, AID requester){
AID remoteDF = action.getDf();
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action DeregisterFrom on DF "+remoteDF.getName());
Deregister d = new Deregister();
final DFAgentDescription dfd = action.getDescription();
d.setDescription(dfd);
Behaviour b = new RemoteDFRequester(remoteDF, d) {
public int onEnd() {
Object result = getResult();
if (!(result instanceof InternalError)) {
if(dfd.getName().equals(myAgent.getAID())) {
// The deregistered agent is the DF itself --> Remove a federation
removeParent(getRemoteDF());
}
}
sendPendingNotification(action, result);
return 0;
}
};
addBehaviour(b);
}
/**
Serve the ModifyOn action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
void modifyOnAction(final ModifyOn action, AID requester){
AID remoteDF = action.getDf();
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action ModifyOn on DF "+remoteDF.getName());
Modify m = new Modify();
m.setDescription(action.getDescription());
Behaviour b = new RemoteDFRequester(remoteDF, m) {
public int onEnd() {
sendPendingNotification(action, getResult());
return 0;
}
};
addBehaviour(b);
}
/**
Serve the SearchOn action of the DF-Applet ontology
Package scoped since it is called by DFAppletManagementBehaviour.
*/
void searchOnAction(final SearchOn action, AID requester){
AID remoteDF = action.getDf();
if(logger.isLoggable(Logger.CONFIG))
logger.log(Logger.CONFIG,"Agent "+requester+" requesting action SearchOn on DF "+remoteDF.getName());
Search s = new Search();
s.setDescription(action.getDescription());
s.setConstraints(action.getConstraints());
Behaviour b = new RemoteDFRequester(remoteDF, s) {
public int onEnd() {
sendPendingNotification(action, getResult());
return 0;
}
};
addBehaviour(b);
}
//#APIDOC_EXCLUDE_BEGIN
///////////////////////////////////////////////////////////
// GUI Management: DFGUIAdapter interface implementation
///////////////////////////////////////////////////////////
protected void onGuiEvent(GuiEvent ev) {
try
{
switch(ev.getType()) {
case DFGUIAdapter.EXIT: {
gui.disposeAsync();
gui = null;
doDelete();
break;
}
case DFGUIAdapter.CLOSEGUI: {
gui.disposeAsync();
gui = null;
break;
}
case DFGUIAdapter.REGISTER: {
AID df = (AID) ev.getParameter(0);
final DFAgentDescription dfd = (DFAgentDescription) ev.getParameter(1);
DFService.checkIsValid(dfd, true);
if (getAID().equals(df)) {
// Register an agent with this DF
DFRegister(dfd);
}
else {
// Register an agent with another DF.
gui.showStatusMsg("Processing your request & waiting for result...");
Register r = new Register();
r.setDescription(dfd);
Behaviour b = new RemoteDFRequester(df, r) {
public int onEnd() {
Object result = getResult();
if (!(result instanceof InternalError)) {
gui.showStatusMsg("Registration request processed. Ready for new request");
if(dfd.getName().equals(myAgent.getAID())) {
// The registered agent is the DF itself --> This is a federation
addParent(getRemoteDF(), dfd);
}
}
else {
gui.showStatusMsg("Error processing request. "+((InternalError) result).getMessage());
}
return 0;
}
};
addBehaviour(b);
}
break;
}
case DFGUIAdapter.DEREGISTER: {
AID df = (AID) ev.getParameter(0);
final DFAgentDescription dfd = (DFAgentDescription) ev.getParameter(1);
DFService.checkIsValid(dfd, false);
if (getAID().equals(df)) {
// Deregister an agent with this DF
DFDeregister(dfd);
}
else {
// Deregister an agent with another DF.
gui.showStatusMsg("Processing your request & waiting for result...");
Deregister d = new Deregister();
d.setDescription(dfd);
Behaviour b = new RemoteDFRequester(df, d) {
public int onEnd() {
Object result = getResult();
if (!(result instanceof InternalError)) {
gui.showStatusMsg("Deregistration request processed. Ready for new request");
if(dfd.getName().equals(myAgent.getAID())) {
// The deregistered agent is the DF itself --> Remove a federation
removeParent(getRemoteDF());
}
else {
gui.removeSearchResult(dfd.getName());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -