|
" 2013 FRC Java API " |
|||||||||
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 String[] args = {"test"}; Isolate i = new Isolate("org.example.App", args, 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 to translate classes to the Squawk suite format dynamically, 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)
.
Isolate.LifecycleListener
, and register the listener using
addLifecycleListener(com.sun.squawk.Isolate.LifecycleListener, int)
and one or more of the lifecycle event masks (such as SHUTDOWN_EVENT_MASK
). When the isolate state changes to the specified event, the system
will call the listener's Isolate.LifecycleListener.handleLifecycleListenerEvent(com.sun.squawk.Isolate, int)
method, passing in the appropriate isolate and event kind.
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)
.The properties parameter to the Isolate constructor provides another way to set the system properties of the new isolate. If this parameter is not specified, the child isolate starts with the same set of system properties that it would have if initiated as a standalone application. If this parameter is specified, this default set of properties is augmented with those specified in the parameter, in the same way as if they had been specified with -D on a command line invocation. In addition, all isolate's inherit the properties defined on the Squawk command line using the -D option.
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
Nested Class Summary | |
---|---|
static class |
Isolate.Breakpoint
A Breakpoint instance describes a point in a method at which a breakpoint has been set. |
static interface |
Isolate.LifecycleListener
Monitor isolate lifecycle events such as shutdown, hibernate, and unhibernate. |
Field Summary | |
---|---|
static int |
HIBERNATE_EVENT_MASK
Event kind indicating that an isolate is hibernating. |
static int |
SHUTDOWN_EVENT_MASK
Event kind indicating that an isolate is exiting. |
MulticastOutputStream |
stderr
|
MulticastOutputStream |
stdout
|
static int |
UNHIBERNATE_EVENT_MASK
Event kind indicating that an isolate is unhibernating. |
Constructor Summary | |
---|---|
Isolate(Hashtable properties,
int midletNum,
String classPath,
String parentSuiteSourceURI)
Creates an new isolate. |
|
Isolate(Hashtable properties,
String mainClassName,
String[] args,
String classPath,
String parentSuiteSourceURI)
Creates an new isolate. |
|
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 |
addLifecycleListener(Isolate.LifecycleListener listener,
int eventSet)
Add a listener to be run when this isolate terminates, hibernates, or unhibernates, depending on evenSet . |
void |
addOut(String url)
Adds a new connection to which System.out will send its output. |
void |
cleanupMailboxes()
Tell remote isolates that we won't talk to them again, and close our Mailboxes. |
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. |
void |
forgetMailbox(Mailbox mailbox)
Tell the system to forget about this mailbox. |
void |
forgetMailboxAddress(MailboxAddress address)
Tell the system to forget about this mailbox. |
int |
getChildThreadCount()
Gets the number of child threads of this isolate. |
Enumeration |
getChildThreads()
Gets the child threads of this isolate. |
String |
getClassPath()
Gets the class path for the isolate. |
Debugger |
getDebugger()
Gets the debugger under which this isolate is executing. |
static TranslatorInterface |
getDefaultTranslator()
Gets a translator that is to be used to locate, load and convert classes that are not currently installed in this isolate's runtime environment. |
int |
getExitCode()
Get the isolate exit code. |
int |
getId()
Gets the unique id for this isolate. |
static Isolate[] |
getIsolates()
Returns an array of Isolate objects. |
Suite |
getLeafSuite()
Gets the suite that is the starting point for class lookup in this isolate. |
String[] |
getMainClassArguments()
Get the arguments. |
String |
getMainClassName()
Get the name of the main class. |
String |
getName()
Gets name of the isolate. |
String |
getParentSuiteSourceURI()
|
Enumeration |
getProperties()
Get an enumeration of isolate property keys. |
String |
getProperty(String key)
Gets a named property of this isolate. |
TranslatorInterface |
getTranslator()
Gets a translator that is to be used to locate, load and convert classes that are not currently installed in this isolate's runtime environment. |
void |
hibernate()
Hibernate the isolate. |
static String |
intern(String value)
Returns a canonical representation for the string object from the current isolate. |
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 |
isClassKlassInitialized()
Test to see if class Klass is initialized. |
boolean |
isExited()
Determines if this isolate is exited . |
boolean |
isHibernated()
Determines if this isolate is hibernated . |
boolean |
isMidlet()
Return true if this isolate was created to run a midlet. |
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. |
static void |
printAllIsolateStates(PrintStream out)
Print out the thread state and stack trace for each thread of each isolate in the system. |
void |
printAllThreadStates(PrintStream out)
Print out the thread state and stack trace for each thread belonging this isolate. |
void |
recordMailbox(Mailbox mailbox)
Record this mailbox with the system. |
void |
recordMailboxAddress(MailboxAddress address)
Record all MailboxAddress objects that this Isolate uses to send messages to. |
void |
removeErr(String url)
Removes the connection identified by url (if any) to which System.err
is currently sending its output. |
boolean |
removeLifecycleListener(Isolate.LifecycleListener listener,
int eventSet)
Remove an Isolate.LifecycleListener from this isolate. |
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 the system (in 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 |
setName(String newName)
Sets name of the isolate. |
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. |
void |
updateBreakpoints(Isolate.Breakpoint[] breakpoints)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int SHUTDOWN_EVENT_MASK
Isolate.LifecycleListener
s that will be called when the Isolate terminates via
exit(int)
, VM.stopVM(int)
, or when the last non-daemon thread in this isolate ends.
All other ways to terminate an isolate,
including VM.haltVM(int)
do not cause the shutdown hooks to be run.
public static final int HIBERNATE_EVENT_MASK
Isolate.LifecycleListener
s that will be called when the Isolate suspends via
hibernate()
.
public static final int UNHIBERNATE_EVENT_MASK
Isolate.LifecycleListener
s that will be called when the Isolate resumes via
unhibernate()
.
public final MulticastOutputStream stdout
public final MulticastOutputStream stderr
Constructor Detail |
---|
public Isolate(Hashtable properties, 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
. System properties can be set for the isolate by passing in a hashtable where the keys are strings of property names
and the values are strings containing property values. The passed in property values will override any property values that the isolate inherits
from the command line properties.
Note that system properties are disjoint from manifest properties.
properties
- a hashtable of properties to be set in the isolate (may be null)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
ClassCastException
- if properties
contains keys or values that are not Strings.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
public Isolate(Hashtable properties, int midletNum, String classPath, String parentSuiteSourceURI)
start()
will create a new execution context, and start executing the startApp
method of the MIDlet
specified by the manifest property named MIDlet-
midletNum. System properties can be set for the isolate by passing in a hashtable where
the keys are strings of property names and the values are strings containing property values. The passed in property values will override any property
values that the isolate inherits from the command line properties.
Note that system properties are disjoint from manifest properties.
properties
- a hashtable of properties to be set in the isolate (may be null)midletNum
- the midlet property that contains the name of the MIDlet to instantiateclassPath
- the path where classes and suites can be found (may be null)parentSuiteSourceURI
- the URI of the suite containing the midlet and the MIDlet properties. (may be null)
NullPointerException
- if mainClassName
or args
is null
ClassCastException
- if properties
contains keys or values that are not Strings.Method Detail |
---|
public String getName()
public void setName(String newName)
newName
- (must not be null)public String getClassPath()
public static Isolate[] getIsolates()
NEW
, ALIVE
,
HIBERNATED
, or EXITED
states. The system only keeps ALIVE
isolates reachable,
so isolates in other states may become unreachable unless referenced by an ALIVE
isolate.
New isolates may have been constructed or existing ones terminated by the time method returns.
public String getParentSuiteSourceURI()
public String getMainClassName()
public static Isolate currentIsolate()
public boolean isTrusted()
public String[] getMainClassArguments()
public Suite getLeafSuite()
closed
, then it's also the suite into which
any dynamically loaded classes (i.e. those loaded via Class.forName(String)
)
are installed.
public static TranslatorInterface getDefaultTranslator() throws AllowInlinedPragma
AllowInlinedPragma
public TranslatorInterface getTranslator() throws AllowInlinedPragma
AllowInlinedPragma
public void setProperty(String key, String value)
System.getProperty(java.lang.String)
.
key
- the name of the propertyvalue
- the value of the property or null to remove the propertypublic String getProperty(String key)
Isolate properties include those passed into the isolate's constructor,
properties inhertited from the squawk command line, and properties set
by setProperty(java.lang.String, java.lang.String)
.
key
- the name of the property to get
public Enumeration getProperties()
getProperty(String)
to get the
property values.
Isolate properties include those passed into the isolate's constructor,
properties inhertited from the squawk command line, and properties set
by setProperty(java.lang.String, java.lang.String)
.
public void addLifecycleListener(Isolate.LifecycleListener listener, int eventSet)
evenSet
. The listener may listen to multiple events by using bitwise OR to construct a set of events from the various event masks.
This isolate may be the current isolate (the local case) or another isolate (the remote case). If this isolate is remote, then this method will also add a listener to the local isolate that will remove this listener on the remote isolate. This cleans up the listeners if the local isolate exits before the remote isolate does.
Execution:
The listener will run in the current Isolate's context. All listener from the same Isolate may run in the same thread. Any RuntimeExceptions thrown by the listener will be printed to System.err, but are otherwise ignored.
listener
- a LifecycleListener that will be called when event occurs.eventSet
- a set of lifecycle events to be monitored.
One or more of SHUTDOWN_EVENT_MASK
, HIBERNATE_EVENT_MASK
, or UNHIBERNATE_EVENT_MASK
.
IllegalArgumentException
- when eventSet does not contain SHUTDOWN_EVENT_MASK
, HIBERNATE_EVENT_MASK
, or UNHIBERNATE_EVENT_MASK
removeLifecycleListener(com.sun.squawk.Isolate.LifecycleListener, int)
,
exit(int)
,
hibernate()
,
unhibernate()
public boolean removeLifecycleListener(Isolate.LifecycleListener listener, int eventSet)
Isolate.LifecycleListener
from this isolate. Must be called from the same isolate that added the listener.
listener
- a Isolate.LifecycleListener to be removed.eventSet
- a set of lifecycle events that the listener should stop listening to.
One or more of SHUTDOWN_EVENT_MASK
, HIBERNATE_EVENT_MASK
, or UNHIBERNATE_EVENT_MASK
.
IllegalArgumentException
- when eventSet does not contain SHUTDOWN_EVENT_MASK
, HIBERNATE_EVENT_MASK
, or UNHIBERNATE_EVENT_MASK
addLifecycleListener(com.sun.squawk.Isolate.LifecycleListener, int)
public static 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
value
-
public void start()
IllegalStateException
- if the isolate has already been startedpublic final void run() throws IllegalStateException
start()
}, and shouldn't be called directly
run
in interface Runnable
IllegalStateException
- if this isolate has already been startedThread.run()
public void join()
public boolean isClassKlassInitialized()
public void exit(int code)
handleLifecycleListenerEvent()
method will be called on any LifecycleListeners
registered
to handle EXIT
events on this isolate.
code
- the exit code
IllegalStateException
- if this isolate is not ALIVE
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
IOException
IllegalStateException
- if this isolate is not currently hibernated or exitedpublic 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
IOException
IllegalStateException
- if this isolate is not currently hibernated or exitedpublic static Isolate load(DataInputStream dis, String uri)
dis
- the data input stream to load fromuri
- a URI identifying the serialized isolate
public void hibernate() throws IOException, IllegalStateException
handleLifecycleListenerEvent()
method will be called on any LifecycleListeners
registered
to handle HIBERNATE
events on this isolate. Any Channel I/O will be hibernated, and interisolate communication channels
will be broken.
If the current thread is in this isolate then this function will only return when the isolate is unhibernated.
IOException
- if the underlying IO system cannot be serialized
IllegalStateException
- if this isolate is not ALIVE
or if it has a debugger attached to itpublic void unhibernate()
handleLifecycleListenerEvent()
method will be called on any LifecycleListeners
registered
to handle UNHIBERNATE
events on this isolate.
IllegalStateException
- if the isolate is not HIBERNATED
public boolean isHibernated()
hibernated
.
public boolean isAlive()
public boolean isExited()
exited
.
public boolean isNew()
started
.
public boolean isBeingDebugged()
public boolean isMidlet()
public int getExitCode()
public String toString()
toString
in class Object
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)
listOut()
,
removeOut(java.lang.String)
,
clearOut()
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)
listErr()
,
removeErr(java.lang.String)
,
clearErr()
public 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
IllegalArgumentException
- if url
does not name a current out streamlistOut()
,
addOut(java.lang.String)
,
clearOut()
public 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 removed
IllegalArgumentException
- if url
does not name a current error streamlistErr()
,
addErr(java.lang.String)
,
clearErr()
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.
addOut(java.lang.String)
,
removeOut(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.
addErr(java.lang.String)
,
removeErr(java.lang.String)
public 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 outputaddOut(java.lang.String)
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 outputaddErr(java.lang.String)
public void recordMailbox(Mailbox mailbox)
mailbox
- the mailbox to record.public void forgetMailbox(Mailbox mailbox)
mailbox
- the mailbox to forget.public void recordMailboxAddress(MailboxAddress address)
address
- the mailbox to record.public void forgetMailboxAddress(MailboxAddress address)
address
- the mailbox to forget.public void cleanupMailboxes()
public void printAllThreadStates(PrintStream out)
out
- stream to print onpublic static void printAllIsolateStates(PrintStream out)
out
- stream to print onpublic Debugger getDebugger()
public Enumeration getChildThreads()
public int getChildThreadCount()
public int getId()
public void updateBreakpoints(Isolate.Breakpoint[] breakpoints)
|
" 2013 FRC Java API " |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |