de.fhg.igd.semoa.agent
Class JumpingAgent

java.lang.Object
  extended byde.fhg.igd.semoa.agent.JumpingAgent
All Implemented Interfaces:
ActionListener, EventListener, Resumable, Runnable, Serializable, WindowListener

public class JumpingAgent
extends Object
implements Resumable, Serializable, ActionListener, WindowListener

This agent was designed to graphically demonstrate the migration behavior. It creates a Frame that contains a ComboBox and a Button. The ComboBox offers the user all servers that are known to the agent. If the JumpButton is pressed, the migration takes place and the agent "jumps" to the selected server.

Version:
"$Id: JumpingAgent.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Jan Haevecker , Ulrich Pinsdorf , Jan Peters
See Also:
Serialized Form

Field Summary
private  JFrame commandFrame_
          Holds the GUI.
private  Object lock_
          Lock object for internal synchronization.
private  MobilityContext mob_
          The agents ability for mobility.
private static String PREFIX_SERVER_PROP
           
private  JComboBox serverChoiceBox_
          Offers all known server destinations for selection
 
Constructor Summary
JumpingAgent()
          Default constructor.
 
Method Summary
 void actionPerformed(ActionEvent a)
          Set the ticket accoring to user's choice and dispose the window.
 ArrayList findTargets()
          Initializes the URL array from the Vicinity service.
private  String getCurrentHost()
           
private  String getLastHost()
           
private  void initGUI()
          Arranges the gui components.
static void main(String[] argv)
          This method is used for the initial launch of the agent from the jshell.
 void resume(ErrorCode err)
          Resumes the agent.
 void run()
          Runs the agent.
 void windowActivated(WindowEvent e)
           
 void windowClosed(WindowEvent e)
          Awake the agent who is waiting for user input.
 void windowClosing(WindowEvent e)
          A closed window will kill the agent.
 void windowDeactivated(WindowEvent e)
           
 void windowDeiconified(WindowEvent e)
           
 void windowIconified(WindowEvent e)
           
 void windowOpened(WindowEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandFrame_

private transient JFrame commandFrame_
Holds the GUI. The memeber is transient because GUIs can't be migrated because they aren't seralizable due to their native references to the wiindow manager. Hence the agent will re-create its GUI on every host after migration.


serverChoiceBox_

private transient JComboBox serverChoiceBox_
Offers all known server destinations for selection


mob_

private transient MobilityContext mob_
The agents ability for mobility. This is has to be reread on each new host and can therefor be transient.


lock_

private Object lock_
Lock object for internal synchronization.


PREFIX_SERVER_PROP

private static final String PREFIX_SERVER_PROP
See Also:
Constant Field Values
Constructor Detail

JumpingAgent

public JumpingAgent()
Default constructor.

Method Detail

resume

public void resume(ErrorCode err)
Description copied from interface: Resumable
Resumes the agent. This method runs the agent after it was suspended. In principle, this method is equivalent to the start() method (from the server's perspective). The server calls this method when the agent is set up from persistent storage rather than being received from a remote host. The difference to start() is basically a semantic one.

Specified by:
resume in interface Resumable
Parameters:
err - The error code that is passed to the agent. If the error code is ErrorCode.OK then this method should behave more or less like start(). Otherwise, this method should start the agent in a way that is appropriate for the error code. For instance, if the agent is set up again after a failed migration then ErrorCode.DESTINATION_UNREACHABLE might be passed.

run

public void run()
Runs the agent. This method will be called after each migration to restart the agent on the new server.

Specified by:
run in interface Runnable

findTargets

public ArrayList findTargets()
Initializes the URL array from the Vicinity service.

Returns:
The ArrayList of found targets or null, if Vicinity is not installed.

initGUI

private void initGUI()
Arranges the gui components.


getLastHost

private String getLastHost()

getCurrentHost

private String getCurrentHost()

actionPerformed

public void actionPerformed(ActionEvent a)
Set the ticket accoring to user's choice and dispose the window. See windowClosed() about how this will affect the agent. param a The action event (unused).

Specified by:
actionPerformed in interface ActionListener

windowClosed

public void windowClosed(WindowEvent e)
Awake the agent who is waiting for user input. This method will be invoked by the user interface thread. It will be called after a commandFrame_.dispose(). At this point the GUI is no longer available and we can tell the agent thread to continue its execution in order to terminate.

Here are two cases possible. First, the window was closed by clicking the JUMP! button. This will set a ticket and then dispose the window. Because the ticket was set the gent will be migrated after its termination. The destination is stated in the ticket.

The second option is that the window was closed by clicking the windows closing icon in the frame. In this case no ticket has been specified, but we tell the agent also to continue and terminate. Hence the agent will die.

Specified by:
windowClosed in interface WindowListener
Parameters:
e - The window event (unused).

windowClosing

public void windowClosing(WindowEvent e)
A closed window will kill the agent. See description of windowClosed() for more details.

Specified by:
windowClosing in interface WindowListener
Parameters:
e - The window event (unused).

windowActivated

public void windowActivated(WindowEvent e)
Specified by:
windowActivated in interface WindowListener

windowDeactivated

public void windowDeactivated(WindowEvent e)
Specified by:
windowDeactivated in interface WindowListener

windowDeiconified

public void windowDeiconified(WindowEvent e)
Specified by:
windowDeiconified in interface WindowListener

windowIconified

public void windowIconified(WindowEvent e)
Specified by:
windowIconified in interface WindowListener

windowOpened

public void windowOpened(WindowEvent e)
Specified by:
windowOpened in interface WindowListener

main

public static void main(String[] argv)
                 throws Exception
This method is used for the initial launch of the agent from the jshell.

Throws:
Exception


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.