|
SunSPOT API V2.0 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.squawk.Isolate
public final class Isolate
The Isolate class represents a "process-like" unit of computation that is isolated from other instances of Isolate. The mutable objects of one isolate are
logically separate from the mutable objects of another isolate. Similarly, the static variables of one isolate are seperate from the static variables of another isolate.
// The creating isolate
Isolate i = new Isolate("org.example.App", "test", null, Isolate.currentIsolate().getParentSuiteSourceURI());
i.start();
i.join(); // wait for child isolate to finish
System.out.println("Child isolate returned with exit code: " + i.getExitCode());
// The newly created isolate
package org.example;
public class App {
public static void main(String[] args) {
for(int i = 0; i < args.length; i++ )
System.out.println(args[i]);
}
}
Note that the last two arguments to the constructor are a classpath, and a URI, which specify where the isolate's main class can be found. The classpath is used when Squawk is
configured with a class TranslatorInterface, while the URI specifies the Suite which contains the translated class file org.example.App. In this example code
we specified that the child isolate will use the same suite as the parent Isolate.
save(DataOutputStream, String) method. The saved form of the isolate includes all reachable objects, the state of all static variables, and
the current execution context of all of the isolate's threads (the thread stacks, etc). The saved form can be stored in a file, sent over a network, etc. load(DataInputStream, String) can be used
reconstruct the saved isolate.
isNew(), isAlive(), isHibernated(),
isExited() can be used to determine an isolate's current state. An Isolate starts out in the NEW state. When the start() method is called the isolate
becomes ALIVE. hibernate() causes an isolate to become HIBERNATED, while unhibernate() brings a HIBERNATED back to ALIVE. An ALIVE
isolate may become EXITED by calling exit(int).
Isolates may communicate between each other using Channel and ServerChannel instances,
or a parent isolate may pass arguments to the main method of the child isolate, or add properties to a child isolate be calling setProperty(String, String).
Each Isolate has independent output streams for System.out and System.err. These output streams can be attached to instances of
Connection by passing Generic Connection Framework URIs to addOut(String) or addErr(String).
Squawk Isolates are loosely based on the Isolates of JSR 121 - Application Isolation API, but
are not compliant with that specification. In particular, Squawk Isolates support hibernation, and use a different inter-isolate communication mechanism than JSR 121.
Channel,
ServerChannel
| Constructor Summary | |
|---|---|
Isolate(String mainClassName,
String[] args,
String classPath,
String parentSuiteSourceURI)
Creates an new isolate. |
|
| Method Summary | |
|---|---|
void |
addErr(String url)
Adds a new connection to which System.err will send its output. |
void |
addOut(String url)
Adds a new connection to which System.out will send its output. |
void |
clearErr()
Removes all the connections to which System.err is sending its output. |
void |
clearOut()
Removes all the connections to which System.out is sending its output. |
static Isolate |
currentIsolate()
Gets the current isolate context. |
void |
exit(int code)
Stop the isolate. |
String |
getClassPath()
Gets the class path for the isolate. |
int |
getExitCode()
Get the isolate exit code. |
int |
getId()
Gets the unique id for this isolate |
static Isolate[] |
getIsolates()
Returns an array of active Isolate objects. |
String[] |
getMainClassArguments()
Get the arguments. |
String |
getMainClassName()
Get the name of the main class. |
String |
getParentSuiteSourceURI()
|
String |
getProperty(String key)
Gets a named property of this isolate. |
void |
hibernate()
Hibernate the isolate. |
String |
intern(String value)
Returns a canonical representation for the string object. |
boolean |
isAlive()
Determines if this isolate has been (re)started and not yet (re)hibernated or exited. |
boolean |
isBeingDebugged()
Determines whether this isolate is being debugged |
boolean |
isExited()
Determines if this isolate is exited. |
boolean |
isHibernated()
Determines if this isolate is hibernated. |
boolean |
isNew()
Determines if this isolate has not yet been started. |
boolean |
isTrusted()
Determines if this isolate can access trusted classes. |
void |
join()
Waits for all the other threads and child isolates belonging to this isolate to stop. |
String[] |
listErr()
Gets a list of URLs denoting the streams to which System.err is currently sending its output. |
String[] |
listOut()
Gets a list of URLs denoting the streams to which System.out is currently sending its output. |
static Isolate |
load(DataInputStream dis,
String uri)
Loads a serialized isolate from an input stream into RAM. |
void |
removeErr(String url)
Removes the connection identified by url (if any) to which System.err
is currently sending its output. |
void |
removeOut(String url)
Removes the connection identified by url (if any) to which System.out
is currently sending its output. |
void |
run()
Deprecated. This is called by start(), and shouldn't be called directly |
void |
save(DataOutputStream dos,
String uri)
Serializes the object graph rooted by this hibernated isolate and writes it to a given stream. |
void |
save(DataOutputStream dos,
String uri,
boolean bigEndian)
Serializes the object graph rooted by this hibernated isolate and writes it to a given stream. |
void |
setProperty(String key,
String value)
Adds a named property to this isolate. |
void |
start()
Start the isolate running. |
String |
toString()
Get the string representation of the isolate. |
void |
unhibernate()
Unhibernate the isolate. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Isolate(String mainClassName,
String[] args,
String classPath,
String parentSuiteSourceURI)
start() will create a new execution context, and start executing the main method of the class
specified by mainClassName.
mainClassName - the name of the class with main()args - the command line argumentsclassPath - the path where classes and suites can be found (may be null)parentSuiteSourceURI - the URI of the suite containing mainClassName. (may be null)
NullPointerException - if mainClassName or args is null| Method Detail |
|---|
public void addErr(String url)
System.err will send its output.
If the current thread is not owned by this isolate,
opening of the connection is delayed until the next time System.err
is written to by one of this isolate's threads. Otherwise the connection is
opened as part of this call.
Output will be multicast to the new stream as well as any preexisting connection streams.
url - the URL used to open the connection via Connector.openOutputStream(java.lang.String)public void addOut(String url)
System.out will send its output.
If the current thread is not owned by this isolate,
opening of the connection is delayed until the next time System.out
is written to by one of this isolate's threads. Otherwise the connection is
opened as part of this call.
Output will be multicast to the new stream as well as any preexisting connection streams.
The following code snippet is an example of how to pipe the standard output of the current isolate to a network connection:
Thread.currentThread().getIsolate().addOut("socket://server.domain.com:9999").
url - the URL used to open the connection via Connector.openOutputStream(java.lang.String)public void clearErr()
System.err is sending its output.
The removed connections are immediately flushed and closed. Any
IO exceptions are caught and are unlikely to be printed.
public void clearOut()
System.out is sending its output.
The removed connections are immediately flushed and closed.. Any
IO exceptions are caught and might be printed.
public static Isolate currentIsolate()
public void exit(int code)
code - the exit code
IllegalStateException - if this isolate has not yet been started or is
already hibernated or exitedpublic String getClassPath()
public int getExitCode()
public int getId()
public static Isolate[] getIsolates()
public String[] getMainClassArguments()
public String getMainClassName()
public String getParentSuiteSourceURI()
public String getProperty(String key)
key - the name of the property to get
public void hibernate()
throws IOException,
IllegalStateException
IOException - if the underlying IO system cannot be serialized
IllegalStateException - if this isolate has not yet been started or is
already hibernated or exited or has a debugger attached to itpublic String intern(String value)
A pool of strings, initially empty, is maintained privately by the
class Isolate.
When the intern method is invoked, if the pool already contains a
string equal to this String object as determined by
the Object.equals(Object) method, then the string from the pool is
returned. Otherwise, this String object is added to the
pool and a reference to this String object is returned.
It follows that for any two strings s and t,
s.intern() == t.intern() is true
if and only if s.equals(t) is true.
All literal strings and string-valued constant expressions are interned. String literals are defined in §3.10.5 of the Java Language Specification
public boolean isAlive()
public boolean isBeingDebugged()
public boolean isExited()
exited.
public boolean isHibernated()
hibernated.
public boolean isNew()
started.
public boolean isTrusted()
public void join()
public String[] listErr()
System.err is currently sending its output.
Note that due to multi-threading, the returned list may not reflect the complete
set of streams. If a stream was added by another thread, then the returned list
may not include the URL of the added stream. If a stream was removed by another thread,
then the returned list may include the URL of the removed stream.
System.err is currently sending its outputpublic String[] listOut()
System.out is currently sending its output.
Note that due to multi-threading, the returned list may not reflect the complete
set of streams. If a stream was added by another thread, then the returned list
may not include the URL of the added stream. If a stream was removed by another thread,
then the returned list may include the URL of the removed stream.
System.out is currently sending its output
public static Isolate load(DataInputStream dis,
String uri)
dis - the data input stream to load fromuri - a URI identifying the serialized isolatepublic void removeErr(String url)
url (if any) to which System.err
is currently sending its output. The removed connection is immediately flushed and closed. Any
IO exceptions are caught and might be printed.
url - the URL identifying the connection to be removedpublic void removeOut(String url)
url (if any) to which System.out
is currently sending its output. The removed connection is immediately flushed and closed. Any
IO exceptions are caught and might be printed.
url - the URL identifying the connection to be removed
public final void run()
throws IllegalStateException
start(), and shouldn't be called directly
start(), and shouldn't be called directly.
run in interface RunnableIllegalStateException - if this isolate has already been startedThread.run()
public void save(DataOutputStream dos,
String uri)
throws IOException
dos - the DataOutputStream to which the serialized isolate should be writtenuri - a URI identifying the serialized isolate
OutOfMemoryError - if there was insufficient memory to do the save
IOException - if there was some IO problem while writing the output
IllegalStateException - if this isolate is not currently hibernated or exited
public void save(DataOutputStream dos,
String uri,
boolean bigEndian)
throws IOException
dos - the DataOutputStream to which the serialized isolate should be writtenuri - a URI identifying the serialized isolatebigEndian - the endianess to be used when serializing this isolate
OutOfMemoryError - if there was insufficient memory to do the save
IOException - if there was some IO problem while writing the output
IllegalStateException - if this isolate is not currently hibernated or exited
public void setProperty(String key,
String value)
System.getProperty(String).
key - the name of the propertyvalue - the value of the property or null to remove the propertypublic void start()
public String toString()
toString in class Objectpublic void unhibernate()
|
SunSPOT API V2.0 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||