An Importable is a safe, cross-process reference to a remote
"Exportable" object.
Methods on Importable and subclasses of Importable may store
pointers in a remote process. Beware that getting these operations
wrong can create bogus pointers into remote heaps. Such problems
generally manifest as the VM crashing.
Example of a 'Foo' and 'FooRef'.
// The "server" object that other Teams will have references to
class FooBackEnd extends Exportable {
...
}
// The "client" object that Teams have locally as a reference to the
// "server"s Foo.
class FooHandle extends Importable {
...
private FooBackEnd be;
private FooHandle() { }
protected void bindTo(Exportable ex)
{
this.be = (FooBackEnd)ex;
}
protected void unbindFrom()
{
this.be = null;
}
// Lookup a FooBackEnd in the given team.
public static FooHandle lookupFoo(Team team, Object id) {
FooBackEnd be;
FooHandle fh = new FooHandle();
team.importObject(fh, id);
return fh;
}
// Create an anonymous FooBackEnd and import it into the current team.
public static FooHandle newFoo(Team team) {
FooHandle retval = new FooHandle();
team.switchTo();
{
FooBackEnd be = new FooBackEnd();
ExportManager em;
em = Team.current().exportAnonymousObject(be);
em.addImporter(retval);
}
team.returnFrom();
return retval;
}
// perform an operation via the foo handle on the foo back end
public void performOp(...) {
synchronized(this) {
// do some stuff in the context of current team
be.doSomethingHere(...);
// do some stuff in the context of the owner
be.switchToOwner();
be.doSomethingThere(...);
be.returnFromOwner();
}
}
...
}
In the above example, a FooHandle is bound to a particular
Team's FooBackEnd object by looking the object up with some
sort of key. Operations on the remote foo are perfomed by invoking
performOp() on the FooRef. Internally this function visits the
owner of the actual Foo, and performs the operation.
Note that all of the ops are done in a synchronized block on the importable.
This will prevent the remote team from revoking the FooHandle while the
operation is being performed on it (unless the operation in question is to
destroy the Foo... be careful).
Bind this Importable to the given Exportable. The most common
implementation of this method would be to cast the Exportable to the
type that the Importable subclass handles and store it in the object as
well as any other handy pointers/values.
Parameters:
ex - The Exportable that is being imported.
unbindFrom
protected abstract void unbindFrom()
Unbind this Importable from any objects its referencing. The most
common implementation of this method would be null out any object
references in this object.
This documentation is Copyright (C) 2000-2002 The University of Utah. All Rights Reserved. See the documentation license for distribution terms and restrictions. Documentation, software, and mailing lists for the JanosVM can be found at the Janos Project web page: http://www.cs.utah.edu/flux/janos/ Generated on Mar 17, 2002