📄 rma.java
字号:
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("MoveAgent",requestMsg));
} catch(Exception fe) {
fe.printStackTrace();
}
}
/**
Callback method for platform management
*/
public void cloneAgent(AID name,String newName, String container)
{
CloneAction cloneAct = new CloneAction();
MobileAgentDescription desc = new MobileAgentDescription();
desc.setName(name);
ContainerID dest = new ContainerID(container, null);
desc.setDestination(dest);
cloneAct.setMobileAgentDescription(desc);
cloneAct.setNewName(newName);
try{
Action a = new Action();
a.setActor(getAMS());
a.setAction(cloneAct);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(MobilityOntology.NAME);
getContentManager().fillContent(requestMsg,a);
addBehaviour(new AMSClientBehaviour("CloneAgent",requestMsg));
} catch(Exception fe) {
fe.printStackTrace();
}
}
/**
Callback method for platform management
*/
public void saveAgent(AID name, String repository)
{
SaveAgent saveAct = new SaveAgent();
saveAct.setAgent(name);
saveAct.setRepository(repository);
try {
Action a = new Action();
a.setActor(getAMS());
a.setAction(saveAct);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(PersistenceVocabulary.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("SaveAgent", requestMsg));
}
catch(Exception fe) {
fe.printStackTrace();
}
}
/**
Callback method for platform management
*/
public void loadAgent(AID name, String repository, String container)
{
LoadAgent loadAct = new LoadAgent();
loadAct.setAgent(name);
loadAct.setRepository(repository);
ContainerID where = new ContainerID(container, null);
loadAct.setWhere(where);
try {
Action a = new Action();
a.setActor(getAMS());
a.setAction(loadAct);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(PersistenceVocabulary.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("LoadAgent", requestMsg));
}
catch(Exception fe) {
fe.printStackTrace();
}
}
/**
Callback method for platform management
*/
public void freezeAgent(AID name, String repository)
{
FreezeAgent freezeAct = new FreezeAgent();
freezeAct.setAgent(name);
freezeAct.setRepository(repository);
try {
Action a = new Action();
a.setActor(getAMS());
a.setAction(freezeAct);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(PersistenceVocabulary.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("FreezeAgent", requestMsg));
}
catch(Exception fe) {
fe.printStackTrace();
}
}
/**
Callback method for platform management
*/
public void thawAgent(AID name, String repository, ContainerID newContainer)
{
ThawAgent thawAct = new ThawAgent();
thawAct.setAgent(name);
thawAct.setRepository(repository);
thawAct.setNewContainer(newContainer);
try {
Action a = new Action();
a.setActor(getAMS());
a.setAction(thawAct);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(PersistenceVocabulary.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("ThawAgent", requestMsg));
}
catch(Exception fe) {
fe.printStackTrace();
}
}
/**
Callback method for platform management <em>GUI</em>.
*/
public void exit() {
if(myGUI.showExitDialog("Exit this container"))
killContainer(myContainerName);
}
/**
Callback method for platform management <em>GUI</em>.
*/
public void shutDownPlatform() {
if(myGUI.showExitDialog("Shut down the platform")) {
ShutdownPlatform sp = new ShutdownPlatform();
try {
Action a = new Action();
a.setActor(getAMS());
a.setAction(sp);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(JADEManagementOntology.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("ShutdownPlatform", requestMsg));
}
catch(Exception fe) {
fe.printStackTrace();
}
}
}
public void installMTP(String containerName) {
InstallMTP imtp = new InstallMTP();
imtp.setContainer(new ContainerID(containerName, null));
if(myGUI.showInstallMTPDialog(imtp)) {
try {
Action a = new Action();
a.setActor(getAMS());
a.setAction(imtp);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(JADEManagementOntology.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("InstallMTP", requestMsg));
}
catch(Exception fe) {
fe.printStackTrace();
}
}
}
public void uninstallMTP(String containerName) {
UninstallMTP umtp = new UninstallMTP();
umtp.setContainer(new ContainerID(containerName, null));
if(myGUI.showUninstallMTPDialog(umtp)) {
uninstallMTP(umtp.getContainer().getName(), umtp.getAddress());
}
}
public void uninstallMTP(String containerName, String address) {
UninstallMTP umtp = new UninstallMTP();
umtp.setContainer(new ContainerID(containerName, null));
umtp.setAddress(address);
try {
Action a = new Action();
a.setActor(getAMS());
a.setAction(umtp);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(JADEManagementOntology.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("UninstallMTP", requestMsg));
}
catch(Exception fe) {
fe.printStackTrace();
}
}
//this method sends a request to a remote AMS to know the APDescription of a remote Platform
public void addRemotePlatform(AID remoteAMS){
if(logger.isLoggable(Logger.FINE))
logger.log(Logger.FINE,"AddRemotePlatform"+remoteAMS.toString());
try{
ACLMessage requestMsg = new ACLMessage(ACLMessage.REQUEST);
requestMsg.setSender(getAID());
requestMsg.clearAllReceiver();
requestMsg.addReceiver(remoteAMS);
requestMsg.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
requestMsg.setLanguage(FIPANames.ContentLanguage.FIPA_SL0);
requestMsg.setOntology(FIPAManagementOntology.NAME);
GetDescription action = new GetDescription();
List l = new ArrayList(1);
Action a = new Action();
a.setActor(remoteAMS);
a.setAction(action);
getContentManager().fillContent(requestMsg,a);
addBehaviour(new handleAddRemotePlatformBehaviour("GetDescription",requestMsg));
}catch(Exception e){
e.printStackTrace();
}
}
public void addRemotePlatformFromURL(String url){
try{
URL AP_URL = new URL(url);
BufferedReader in = new BufferedReader(new InputStreamReader(AP_URL.openStream()));
StringBuffer buf=new StringBuffer();
String inputLine;
while( (inputLine = in.readLine()) != null ) {
if( ! inputLine.equals("") ) {
buf.append(inputLine);
buf.append(" ");
}
}
//to parse the APDescription it is put in a Dummy ACLMessage
ACLMessage dummyMsg = new ACLMessage(ACLMessage.NOT_UNDERSTOOD);
dummyMsg.setOntology(FIPAManagementOntology.NAME);
dummyMsg.setLanguage(FIPANames.ContentLanguage.FIPA_SL0);
String content = "(( result (action ( agent-identifier :name ams :addresses (sequence IOR:00000000000000) :resolvers (sequence ) ) (get-description ) ) (set " + buf.toString() +" ) ) )";
dummyMsg.setContent(content);
try{
Result r = (Result)getContentManager().extractContent(dummyMsg);
Iterator i = r.getItems().iterator();
APDescription APDesc = null;
while( i.hasNext() && ((APDesc = (APDescription)i.next()) != null) ){
String amsName = "ams@" + APDesc.getName();
if(amsName.equalsIgnoreCase(getAMS().getName())){
if(logger.isLoggable(Logger.WARNING))
logger.log(Logger.WARNING,"ERROR: Action not allowed.");
}
else
{
// create the proper AID for AMS by adding all available addresses
AID ams = new AID(amsName, AID.ISGUID);
for (Iterator is = APDesc.getAllAPServices(); is.hasNext(); ) {
APService s = (APService)is.next();
for (Iterator js = s.getAllAddresses(); js.hasNext(); )
ams.addAddresses(js.next().toString());
}
myGUI.addRemotePlatformFolder();
myGUI.addRemotePlatform(ams,APDesc);
}
}
}catch(Exception e){
e.printStackTrace();}
in.close();
}catch(java.net.MalformedURLException e){
e.printStackTrace();
}catch(java.io.IOException ioe){
ioe.printStackTrace();
}
}
public void viewAPDescription(String title){
myGUI.viewAPDescriptionDialog(myPlatformProfile,title);
}
public void viewAPDescription(APDescription remoteAP, String title){
myGUI.viewAPDescriptionDialog(remoteAP,title);
}
public void removeRemotePlatform(APDescription platform){
myGUI.removeRemotePlatform(platform.getName());
}
//make a search on a specified ams in order to return
//all the agents registered with that ams.
public void refreshRemoteAgent(APDescription platform,AID ams){
try{
// FIXME. Move all this block into the constructor for better performance
// because it is invariant to the method parameters
ACLMessage request; // variable that keeps the request search message
Action act; // variable that keeps the search action
request = new ACLMessage(ACLMessage.REQUEST);
request.setProtocol(FIPANames.InteractionProtocol.FIPA_REQUEST);
request.setLanguage(FIPANames.ContentLanguage.FIPA_SL0);
request.setOntology(FIPAManagementOntology.NAME);
AMSAgentDescription amsd = new AMSAgentDescription();
SearchConstraints constraints = new SearchConstraints();
constraints.setMaxResults(new Long(-1)); // all results back
// Build a AMS action object for the request
Search s = new Search();
s.setDescription(amsd);
s.setConstraints(constraints);
act = new Action();
act.setAction(s);
// request has been already initialized in the constructor
request.clearAllReceiver();
request.addReceiver(ams);
act.setActor(ams); // set the actor of this search action
getContentManager().fillContent(request, act);
addBehaviour(new handleRefreshRemoteAgentBehaviour ("search",request,platform));
}catch(Exception e){
e.printStackTrace();
}
}
// ask the local AMS to register a remote Agent.
public void registerRemoteAgentWithAMS(AMSAgentDescription amsd){
Register register_act = new Register();
register_act.setDescription(amsd);
try{
Action a = new Action();
a.setActor(getAMS());
a.setAction(register_act);
ACLMessage requestMsg = getRequest();
requestMsg.setOntology(FIPAManagementOntology.NAME);
getContentManager().fillContent(requestMsg, a);
addBehaviour(new AMSClientBehaviour("Register", requestMsg));
}catch(Exception e){e.printStackTrace();}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -