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

📄 rma.java

📁 JADE(JAVA Agent开发框架)是一个完全由JAVA语言开发的软件,它简化了多Agent系统的实现。
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
		super.afterMove();
		
		getContentManager().registerOntology(MobilityOntology.getInstance());
		getContentManager().registerOntology(PersistenceOntology.getInstance());
		
		myGUI = new MainWindow(this);
		myGUI.ShowCorrect();
		
		// Make the AMS send back the whole container list
		send(getSubscribe());
		
	}
	
	protected void afterClone() {
		super.afterClone();
		
		getContentManager().registerOntology(MobilityOntology.getInstance());
		getContentManager().registerOntology(PersistenceOntology.getInstance());
		
		// Add yourself to the RMA list
		ACLMessage AMSSubscription = getSubscribe();
		send(AMSSubscription);
		myGUI = new MainWindow(this);
		myGUI.ShowCorrect();
	}
	
	public void afterLoad() {
		super.afterLoad();
		
		getContentManager().registerOntology(MobilityOntology.getInstance());
		getContentManager().registerOntology(PersistenceOntology.getInstance());
		
		// Add yourself to the RMA list
		ACLMessage AMSSubscription = getSubscribe();
		send(AMSSubscription);
		myGUI = new MainWindow(this);
		myGUI.ShowCorrect();
	}
	
	public void beforeReload() {
		super.beforeReload();
		
		myGUI.disposeAsync();
		send(getCancel());
	}
	
	public void afterReload() {
		super.afterReload();
		
		getContentManager().registerOntology(MobilityOntology.getInstance());
		getContentManager().registerOntology(PersistenceOntology.getInstance());
		
		myGUI = new MainWindow(this);
		myGUI.ShowCorrect();
		
		// Make the AMS send back the whole container list
		send(getSubscribe());
	}
	
	public void beforeFreeze() {
		super.beforeFreeze();
		
		myGUI.disposeAsync();
		send(getCancel());
	}
	
	public void afterThaw() {
		super.afterThaw();
		
		getContentManager().registerOntology(MobilityOntology.getInstance());
		getContentManager().registerOntology(PersistenceOntology.getInstance());
		
		myGUI = new MainWindow(this);
		myGUI.ShowCorrect();
		
		// Make the AMS send back the whole container list
		send(getSubscribe());
	}
	
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public AgentTreeModel getModel() {
		return myGUI.getModel();
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void newAgent(String agentName, String className, Object arg[], String containerName) {
		newAgent (agentName, className, arg, null, containerName);
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void newAgent(String agentName, String className, Object arg[], String ownerName, String containerName) {
		
		CreateAgent ca = new CreateAgent();
		
		if(containerName.equals(""))
			containerName = AgentContainer.MAIN_CONTAINER_NAME;
		
		// fill the create action with the intended agent owner
		jade.security.JADEPrincipal intendedOwner = null;
		jade.security.Credentials initialCredentials = null;
		
		if ((ownerName==null) || (ownerName.trim().length()==0)) {
			// it is requested the creation of an agent 
			// with the same owner of the RMA
			try {
				jade.security.JADEPrincipal rmaOwner = null;
				jade.security.Credentials rmaCredentials = null;
				jade.security.CredentialsHelper ch = (jade.security.CredentialsHelper) getHelper("jade.core.security.Security");
				// get RMA's owner
				if (ch!=null) {  rmaCredentials = ch.getCredentials();    }
				if (rmaCredentials!=null) {  rmaOwner = rmaCredentials.getOwner();    }
				intendedOwner = rmaOwner;
			}
			catch (ServiceException se) { // Security service not present. Owner is null. 
				intendedOwner=null;
				initialCredentials=null;
			}
			
		} else {
			// it is requested the creation of an agent 
			// with a specified owner name 
			try
			{
				Class c = Class.forName("jade.security.impl.JADEPrincipalImpl");
				intendedOwner = (JADEPrincipal) c.newInstance();
				java.lang.reflect.Method setName = c.getDeclaredMethod("setName", new Class[]{ String.class });
				setName.invoke(intendedOwner, new Object[] {ownerName});
			} catch (Exception e)
			{
				//e.printStackTrace();
				// Security service not present. Owner is null. 
				intendedOwner=null;
				initialCredentials=null;
			}
		}
		
		ca.setOwner( intendedOwner );
		ca.setInitialCredentials( initialCredentials );
		
		ca.setAgentName(agentName);
		ca.setClassName(className);
		ca.setContainer(new ContainerID(containerName, null));
		for(int i = 0; i<arg.length ; i++)
			ca.addArguments((Object)arg[i]);
		
		try {
			Action a = new Action();
			a.setActor(getAMS());
			a.setAction(ca);
			
			ACLMessage requestMsg = getRequest();
			requestMsg.setOntology(JADEManagementOntology.NAME);
			getContentManager().fillContent(requestMsg, a);
			addBehaviour(new AMSClientBehaviour("CreateAgent", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
		
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void suspendAgent(AID name) {
		AMSAgentDescription amsd = new AMSAgentDescription();
		amsd.setName(name);
		amsd.setState(AMSAgentDescription.SUSPENDED);
		Modify m = new Modify();
		m.setDescription(amsd);
		
		try {
			Action a = new Action();
			a.setActor(getAMS());
			a.setAction(m);
			
			ACLMessage requestMsg = getRequest();
			requestMsg.setOntology(FIPAManagementOntology.NAME);
			getContentManager().fillContent(requestMsg, a);
			addBehaviour(new AMSClientBehaviour("SuspendAgent", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
	}
	
	
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void suspendContainer(String name) {
		// FIXME: Not implemented
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void resumeAgent(AID name) {
		AMSAgentDescription amsd = new AMSAgentDescription();
		amsd.setName(name);
		amsd.setState(AMSAgentDescription.ACTIVE);
		Modify m = new Modify();
		m.setDescription(amsd);
		
		try {
			Action a = new Action();
			a.setActor(getAMS());
			a.setAction(m);
			
			ACLMessage requestMsg = getRequest();
			requestMsg.setOntology(FIPAManagementOntology.NAME);
			getContentManager().fillContent(requestMsg, a);
			addBehaviour(new AMSClientBehaviour("ResumeAgent", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void changeAgentOwnership(AID name, String ownership) {
		AMSAgentDescription amsd = new AMSAgentDescription();
		amsd.setName(name);
		amsd.setState(AMSAgentDescription.ACTIVE);//SUSPENDED);
		amsd.setOwnership(ownership);
		Modify m = new Modify();
		m.setDescription(amsd);
		
		try {
			Action a = new Action();
			a.setActor(getAMS());
			a.setAction(m);
			
			ACLMessage requestMsg = getRequest();
			requestMsg.setOntology(FIPAManagementOntology.NAME);
			getContentManager().fillContent(requestMsg, a);
			addBehaviour(new AMSClientBehaviour("ChangeAgentOwnership", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void resumeContainer(String name) {
		// FIXME: Not implemented
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void killAgent(AID name) {
		
		KillAgent ka = new KillAgent();
		
		ka.setAgent(name);
		
		try {
			Action a = new Action();
			a.setActor(getAMS());
			a.setAction(ka);
			
			ACLMessage requestMsg = getRequest();
			requestMsg.setOntology(JADEManagementOntology.NAME);
			getContentManager().fillContent(requestMsg, a);
			addBehaviour(new AMSClientBehaviour("KillAgent", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
		
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void saveContainer(String  name, String repository) {
		SaveContainer saveAct = new SaveContainer();
		saveAct.setContainer(new ContainerID(name, null));
		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("SaveContainer", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
	}
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void loadContainer(String name, String repository) {
		LoadContainer saveAct = new LoadContainer();
		saveAct.setContainer(new ContainerID(name, null));
		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("LoadContainer", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
	}
	
	
	/**
	 Callback method for platform management <em>GUI</em>.
	 */
	public void killContainer(String name) {
		
		KillContainer kc = new KillContainer();
		
		kc.setContainer(new ContainerID(name, null));
		
		try {
			Action a = new Action();
			a.setActor(getAMS());
			a.setAction(kc);
			
			ACLMessage requestMsg = getRequest();
			requestMsg.setOntology(JADEManagementOntology.NAME);
			getContentManager().fillContent(requestMsg, a);
			addBehaviour(new AMSClientBehaviour("KillContainer", requestMsg));
		}
		catch(Exception fe) {
			fe.printStackTrace();
		}
		
	}
	
	/**
	 Callback method for platform management
	 */
	public void moveAgent(AID name, String container)
	{
		MoveAction moveAct = new MoveAction();
		MobileAgentDescription desc = new MobileAgentDescription();
		desc.setName(name);
		ContainerID dest = new ContainerID(container, null);
		
		desc.setDestination(dest);
		moveAct.setMobileAgentDescription(desc);
		
		try{
			Action a = new Action();
			a.setActor(getAMS());
			a.setAction(moveAct);
			
			ACLMessage requestMsg = getRequest();
			requestMsg.setOntology(MobilityOntology.NAME);

⌨️ 快捷键说明

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