Google

JanosVM v0.6.0 Java API Documentation: Class Importable
JanosVM v0.6.0 Java API

edu.utah.janosvm.sys
Class Importable

java.lang.Object
  |
  +--edu.utah.janosvm.sys.ListNode
        |
        +--edu.utah.janosvm.sys.Importable
Direct Known Subclasses:
CommHashtableHandle, CommQueuePuller, CommQueuePusher, CommSpaceHandle, FaxPortHandle, TeamHandle, TeamList

public abstract class Importable
extends ListNode

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).

Author:
Tim Stack, Utah Janos Team
See Also:
TeamHandle.switchTo(), Exportable

Fields inherited from class edu.utah.janosvm.sys.ListNode
pred, succ
 
Constructor Summary
Importable()
          Construct an empty Importable.
 
Method Summary
protected abstract  void bindTo(Exportable ex)
          Bind this Importable to the given Exportable.
protected  void copy(Importable im)
          Copy the reference of the given Importable.
protected  void finalize()
           
 void revoke()
           
 java.lang.String toString()
           
protected abstract  void unbindFrom()
          Unbind this Importable from any objects its referencing.
 
Methods inherited from class edu.utah.janosvm.sys.ListNode
append, clone, prepend, remove
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Importable

public Importable()
Construct an empty Importable.
Method Detail

bindTo

protected abstract void bindTo(Exportable ex)
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.

copy

protected void copy(Importable im)
Copy the reference of the given Importable.
Parameters:
im - The Importable to copy the reference from.

revoke

public void revoke()

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class ListNode

JanosVM v0.6.0 Java API

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