Author: kohsuke
Date: Mon Aug 15 22:07:15 2005
New Revision: 232938

URL: http://svn.apache.org/viewcvs?rev=232938&view=rev
Log:
expanded the classloader section

Modified:
    jakarta/commons/sandbox/javaflow/trunk/xdocs/tutorial.xml

Modified: jakarta/commons/sandbox/javaflow/trunk/xdocs/tutorial.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/xdocs/tutorial.xml?rev=232938&r1=232937&r2=232938&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/xdocs/tutorial.xml (original)
+++ jakarta/commons/sandbox/javaflow/trunk/xdocs/tutorial.xml Mon Aug 15 
22:07:15 2005
@@ -14,7 +14,7 @@
                        First, consider the following program:

                </p>

 <source>

-class MyRunnable implements Runnable, Continuable {

+class MyRunnable implements Runnable {

        public void run() {

                System.out.println("started!");

                for( int i=0; i&lt;10; i++ )

@@ -85,16 +85,14 @@
        </section>

        <section name="Preparation">

                <p>

-                       For these to work, javaflow needs to enhance the byte 
code of your program that runs inside the continuation-enabled environment. The 
<tt>Continuable</tt> interface is used to mark those classes. Javaflow uses 
this marker interface to decide which class to instrument. 
(<tt>Continuable</tt> classes can be still executed normally outside the 
environment, but it runs somewhat slower.)

-               </p>

-               <p>

-                       When the <tt>Continuation.suspend</tt> runs, all the 
methods on the stack frames need to be on classes marked as 
<tt>Continuable</tt>.

+                       For these to work, javaflow needs to enhance the byte 
code of your program that runs inside the continuation-enabled environment. 
When the <tt>Continuation.suspend</tt> runs, all the methods on the stack 
frames (up to <tt>Continuation.startWith</tt> or 
<tt>Continuation.continueWith</tt>) need to be enhanced.

                </p>

                <p>

                        There are two ways to instrument bytecode. One way is 
to do it statically. This means using the following Ant task as a part of your 
build process:

                </p>

 <source><![CDATA[

-<taskdef name="javaflow" 
classname="org.apache.commons.javaflow.ant.AntRewriteTask">

+<taskdef name="javaflow"

+  classname="org.apache.commons.javaflow.ant.AntRewriteTask">

        <classpath>

                ...

        </classpath>

@@ -105,11 +103,30 @@
 </rewriteTask>

 ]]></source>

                <p>

-                       This scans the build/classes directory for any class 
file that needs instrumentation. For more details about this Ant task, see <a 
href="javascript:window.alert('todo')">this document</a>.

+                       This scans the build/classes directory and enhance all 
the classes. For more details about this Ant task, see <a 
href="javascript:window.alert('todo')">this document</a>. Since the byte-code 
enhancement increases the class file size, you might want to consider avoiding 
unnecessary class files enhancement.

                </p>

                <p>

-                       Alternatively, you can do this dynamically at runtime, 
by using javaflow's custom class loader. *TODO*TODO*TODO*

+                       Alternatively, you can do this dynamically at runtime, 
by using javaflow's <tt>ContinuationClassLoader</tt>. This works like a 
<tt>URLClassLoader</tt> with the byte-code enhancement. To use this, you need 
to separate your application into two parts; one for classes that don't need 
enhancement, and the other that do need enhancement. You can then configure the 
first portion to be loaded by the system class loader, and then load the second 
portion by a <tt>ContinuationClassLoader</tt>. The following code shows how to 
do this:

+               </p>

+<source>

+// this class lives in the system class loader

+public class Foo {

+       public static void main(String[] args) {

+               ClassLoader cl = new ContinuationClassLoader(

+                       new URL[]{new URL("latter.jar")},

+                       Foo.class.getClassLoader()); // parent class loader

+               cl.loadClass(...);

+       }

+}

+</source>

+                       

+                       <!-- One is <tt>ContinuationClassLoader</tt>, which 
locates class files by using its ancestor class loaders, and then loads it 
after the enhancement. This is convenient for a simple Java SE application, 
where all the application classes are available in the default class loader. 
The following code illustrates how to set up a <tt>ContinuationClassLoader</tt>.

                </p>

+<source>

+</source>

+               <p>

+                       The downside of this approach is that this model goes 
against the default class loader delegation model, and therefore classes of the 
same name are always available from two ClassLoaders. You need to carefully 
think what class is loaded from where, or you'll get mysterious 
<tt>ClassCastException</tt>, or some strange behavior when you suspend, etc.

+               </p-->

        </section>

        </body>

 </document>




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to