next up previous contents
Next: B.6 VoyagerMasaGatewayApplet Up: B Source-Code des Voyager-MASA-Gateways Previous: B.4 VoyagerAgentManager

B.5 VoyagerProxyAgentMobileAgent

package de.unimuenchen.informatik.mnm.masa.agent.voyagerproxyagent;


import de.unimuenchen.informatik.mnm.masa.agentSystem.voyagerintegration.*;
import de.unimuenchen.informatik.mnm.masa.agentSystem.*;
import de.unimuenchen.informatik.mnm.masa.agent.*;
import de.unimuenchen.informatik.mnm.masa.agent.voyagermasagateway.*;
import CfMAF.*;

import de.unimuenchen.informatik.mnm.masa.tools.Debug;

import java.util.StringTokenizer;



/**
 * Class to represent a Voyager agent in MASA
 */

public class VoyagerProxyAgentMobileAgent extends MobileAgent
		implements VoyagerProxyAgentOperations 
{

		/**
		 * Name of the Voyager agent
		 * (not supported)
		 */
		private String myname;

		/**
		 * Mark if termination is executed by VoyagerAgentManager
		 * or by AgentSystemApplet
		 */
		private boolean readyForTermination = false;
		
		public VoyagerProxyAgentMobileAgent(String myname){
				Debug.debug("VoyagerProxyAgent.<init>");
				this.myname = myname;
		}

		/**
		 * To call for a clean temrination, i.e. if this method is not called before
		 * VoyagerProxyMobileAgent is terminated then VoyagerProxyMobileAgent supposes that the Voyager Agent is not terminated!!
		 */
		public void setReadyForTermination(){
				Debug.debug("VoyagerProxyAgent ready for termination");
				readyForTermination = true;
		}

		/**
		 * Is called during termination
		 * @see Agent.cleanUp()
		 */
		public void cleanUp() throws Throwable
    {
				Debug.debug("VoyagerProxyAgentMobileAgent.cleanUp()");
				// terminate Voyager Agent
				if(!readyForTermination)
						throw new Exception("VoyagerProxyAgent must not be terminated if voyager agent is still running");
    }

		/**
		 * @see Agent.checkSerialization()
		 */
		public void checkSerialization() throws CouldNotMigrate
    {
				Debug.debug("VoyagerVoyagerProxyAgentMobileAgent.checkSerialization()");
    } 
  	
		/**
		 * Modifies the _url: new _url shows Applet of the VoyagerMasaGatewayStationaryAgent
		 *
		 * @see Agent.run()
		 */
		public void run()
    {        
				Debug.debug("VoyagerVoyagerProxyAgentMobileAgent.run()");
				// Modify url
				Debug.debug("VoyagerVoyagerProxyAgentMobileAgent.run() - url:" + _url);
				StringTokenizer token = new StringTokenizer(_url,"/");
				String result = "/";
				String nextToken;
				while(token.hasMoreElements()){					
						nextToken = token.nextToken();
						if(!token.hasMoreElements())
								result = result + "VoyagerMasaGateway.html";
						else
								result = result + nextToken + "/";
				}
				_url = result;
				Debug.debug("VoyagerVoyagerProxyAgentMobileAgent.run() - url:" + _url);
    }
}



Copyright Munich Network Management Team