SunSPOT API V3.0


com.sun.spot.interisolate
Class InterIsolateServer

java.lang.Object
  extended by com.sun.spot.interisolate.InterIsolateServer

public class InterIsolateServer
extends Object

The purpose of classes in this package is to provide a generic framework for building remote-procedure-call (RPC) mechanisms between isolates.

The "context" is the object that wishes to provide inter-isolate access to its services. It doesn't need to know anything about the RPC mechanism. The "proxy" is the object in the other isolate that wishes to use the context. Many proxies can access the same context. The context is in a one-to-many relationship with the proxies. The proxy normally has the same api as the context, or a subset of it (the subset that needs to be available remotely).

The mechanism uses a ServerChannel for each context. This ServerChannel is created at startup time, and is given a name that reflects the context being served. E.g.:

InterIsolateServer.run("CONTEXT_ID_STRING", myContext);

When a new proxy object is created it asks the RequestSender class to create a Channel by which it can talk to a context, where the context is identified by the name given to its server channel. E.g.:

RequestSender myRequestSender = RequestSender.lookup("CONTEXT_ID_STRING");

That call returns a RequestSender that the proxy can use to talk to the context. To make a call the proxy creates a RequestEnvelope and asks the RequestSender to send it to the context. Different subclasses of RequestEnvelope are used for each different request that can be sent.

Imagine that the context provides a function:

public int doSomething();

The proxy might invoke this using:

public int doSomething() { ReplyEnvelope reply = myRequestSender.send(new DoSomethingCommand()); resultEnvelope.checkForRuntimeException(); return ((Integer)resultEnvelope.getContents()).intValue(); }

The class DoSomethingCommand would be subclass of RequestEnvelope, and it would have an implementation of execute(Object context) that looks like this:

public ReplyEnvelope execute(Object context) { int result = ((MyContext)context).doSomething(); return new ObjectReplyEnvelope(getUid(), new Integer(result)); }

If the function is void use a VoidReplyEnvelope instead. You can create other reply envelopes if you wish. We also provide BooleanReplyEnvelope, but you could achieve the same effect by wrapping the boolean in a Boolean, as with the int example above. Exceptions are caught and propagated back to the proxy.

This class defines a thread that listens on the ServerChannel


Method Summary
static void run(String channelName, Object context)
           
static void run(String channelName, Object context, int threadPriority)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

run

public static void run(String channelName,
                       Object context)

run

public static void run(String channelName,
                       Object context,
                       int threadPriority)

SunSPOT API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.