back to API     back to index     back to guided tour index     prev     next  

1.4. migration of graphical interfaces

Graphical interfaces are not serializable, yet it is possible to migrate them with ProActive.
The idea is to associate the graphical object to an active object. The active object will control the activation and desactivation of this graphical entity during migrations.

Of course, this is a very basic example, but you can later build more sophisticated frames.

Design of the application

We will write a new active object class, that extends MigratableHello. The sayHello method will create a window containing the hello message. This window is defined in the class HelloFrame

Programming

HelloFrameController

The code of the HelloFrameController is here.

This class extends MigratableHello, and adds an activity and a migration strategy manager to the object .
It creates a graphical frame upon call of the sayHello method.

Here we have a more complex migration process than with the previous example. We need to make the graphical window disappear before and reappear in a new location after the migration (in this example though, we wait for a call to sayHello). The migration of the frame is actually controlled by a MigrationStrategyManager, that will be attached to the body of the active object.. An ideal location for this operation is the initActivity method (from InitActive interface), that we override :

/**
 * This method attaches a migration strategy manager to the current active object.
 * The migration strategy manager will help to define which actions to take before
 * and after migrating
 */
public void initActivity(Body body) {
	// add a migration strategy manager on the current active object
	migrationStrategyManager = new MigrationStrategyManagerImpl((Migratable) ProActive.getBodyOnThis());
	// specify what to do when the active object is about to migrate
	// the specified method is then invoked by reflection
	migrationStrategyManager.onDeparture("clean");
}

The MigrationStrategyManager defines methods such as "onDeparture", that can be configured in the application. For example here, the method "clean" will be called before the migration, conveniently killing the frame :

public void clean() {
	System.out.println("killing frame");
	helloFrame.dispose();
	helloFrame = null;
	System.out.println("frame is killed");
}

HelloFrame

This is an example of a graphical class that could be associated with the active object. Here is the code.

Execution

  • Similarly to the simple migration example (use the HelloFrameController class), you will start remote nodes and specify a migration path.
  • don't forget to set the security permissions
  • you have 2 ways for handling the display of the graphical objects :


  • The displayed window : it just contains a text label with the location of the active object.