| java.lang.Object com.sun.midp.links.LinkPortal
LinkPortal | public class LinkPortal (Code) | | This class provides foreign methods of the Isolate class. (For discussion
of foreign methods, see Fowler, _Refactoring_, "Introduce Foreign Method",
p. 162.)
The technique for passing links between isolates is implemented as a
separate class in order to avoid short term dependencies on the
implementation of the Isolate class in CLDC. These functions will
eventually be moved to the Isolate class of CLDC.
IMPL_NOTE
The current arrangement is highly problematic and therefore should be
considered only as a temporary solution. The portal keeps track of links by
isolate ID. However, an isolate ID is only assigned after the isolate has
been started. Therefore, getLinks() must block until the parent isolate has
had a chance to call setLinks(). The sender and receiver must agree to pass
this initial set of links. This is pretty fragile, but it's only necessary
for passing the initial set of links. Any additional links can be passed
via the initial set of links.
If an isolate dies before it gets its links, they'll be stranded in the
portal. The parent isolate can overwrite them, though, and they should be
collected. Worse, if an isolate dies and another isolate is created and
gets the same IDs, it can get the links that were destined for the first.
This requires the parent isolate to be responsible for cleaning up any
unused links passed to its children, which could be difficult in general.
|
Method Summary | |
public static synchronized Link[] | getLinks() Gets the links for this isolate that had been set by its creator. | public static void | setLinks(Isolate isolate, Link[] linkarray) Sets the array of links for the given isolate. |
getLinks | public static synchronized Link[] getLinks()(Code) | | Gets the links for this isolate that had been set by its creator. If
links are available, this returns immediately. If no links are
available, this method will block until the creator sets them. This
requires close cooperation between the creator isolate and the newly
created isolate. The typical usage is that the creator creates the new
isolate and passes one set of links to it, and the first thing the new
new isolate does is to get this initial set of links. Any subsequent
links should be passed through the initial set of links.
|
setLinks | public static void setLinks(Isolate isolate, Link[] linkarray)(Code) | | Sets the array of links for the given isolate. Once set, the array of
links can be retrieved by the designated isolate using the getLinks()
method.
Setting of links should be done after the isolate is started and before
it terminates, so that a valid id is available. However, this
introduces a race condition between the starting of the isolate, the
call to setLinks(), and the new isolate calling getLinks(). This means
that the new isolate code will need to call getLinks() until it gets
the array of links it expects.
The linkarray parameter may be null, in which case it removes any links
that had been previously set for isolate. If getLinks() is called at
this point, it will block until a non-null array is set. Passing a
null linkarray to setLinks() differs from passing a zero-length array,
which will satisfy a call to getLinks() and cause it to return a
zero-length array.
If linkarray is an array whose length is greater than zero, every entry
must be a valid (non-null) Link object.
throws: NullPointerException - if isolate is null throws: NullPointerException - if any entry in linkarray is null throws: IllegalArgumentException - if any link in linkarray is closed throws: IllegalStateException - if isolate hasn't been started or has been terminated |
|
|