Forum Controls
Spotlight Features

The Rich Engineering Heritage Behind Dependency Injection

Andrew McVeigh takes us on a tour of the rich heritage behind dependency injection, what it represents, and tells us why its here to stay.

NetBeans 6: Matisse Updates

NetBeans 6 delivers great updates to the Matisse GUI builder. Spend a few minutes with Roman Strobl and get an expert briefing on what's new and what has changed.

Introduction to Groovy Part 3

In this, the third and final installation of Andres' Introduction to Groovy series, you learn about how Groovy handles variable numbers of arguments, named parameters, currying, and more about Groovy operators. Including, some new operators.

Easier Custom Components with Swing Fuse

Swing Fuse (actually just Fuse), is a framework designed to make it easier to create your own custom desktop components. In this article, Daniel Spiewak shows you how to get started and provides sample source code you can download.

Benchmark Analysis: Guice vs Spring

Willam Louth shows how he uses JXInsight Probes to investigate probable performance issues with code bases that he is not familiar with. He also highlights possible pitfalls in creating a benchmark, as well as in the analysis of results.
Replies: 5 - Pages: 1  
Threads: [ Previous | Next ]
  Click to reply to this thread Reply

Aranea, Continuations, and Swing

At 8:06 PM on Oct 10, 2007, Geertjan wrote:

I've watched Geert Bevin, from RIFE, a number of times, doing presentations where he talks about 'Save Game' functionality. That's how he presents the concept of 'continuations'. "When playing a computer game," he says, "don't you commonly want to save the game at a point where things are becoming exciting, and then return to it later?"

Aranea has brought this concept to Swing some time ago, on top of the JavaFlow library. However, you need to perform some instrumentation on your classes prior to being able to make use of these continuations. This can be during the build process or at runtime via a special classloader. I don't want to do this from the command line, but as part of some Ant process. I haven't been able to find anywhere a good description, or at least a simple description, of how either of these instrumentations should be done via Ant, exactly, but I spent some time figuring it out, and here is the result, via a handy Ant script, that turned out to be a lot simpler than I thought, which is run after compilation of the classes:

<target name="javaflow" depends="compile, jar" description="javaflow">
    <java classname="${main.class}" dir="${work.dir}" fork="true">
        <jvmarg value="-javaagent:lib/aranea-blocking.jar=mypackage, anotherpackage" />
        <classpath>
            <fileset dir="${build.classes.dir}"/>
        </classpath>
    </java>
</target>

As indicated above, you need a comma separated list of packages.

Once you have run the above script, you'll be able to run code such as the following, which blocks the application and forces it to wait for actions applicable to specified Swing components. For example:

@Resumable
public void init() {
    initComponents();
    ResumableRunnable myRunnable = new ResumableRunnable() {
        public void run() {
            for (int i = 1; i <= 10; i++) {
                SwingBlockingUtil.waitForOneAction(someButton);
                System.out.println("You have clicked me " + i);
            }
            System.exit(0);
        }
    };
    BlockingUtil.execute(myRunnable);
}

Finally, the annotation indicates that the method can be resumed later.

Take careful note of the information supplied at the end of the documentation referred to above: "Nothing comes for free and this is doubly so for bytecode modification. JavaFlow will definitely add a performance penalty to your application. However you should consider that it will almost exclusively add CPU consumption and will not stress IO or memory. This means that in most projects the impact will not be considerable or possibly even noticeable. This goes specially to desktop Swing applications, which are highly unlikely to be CPU-bound. Of course one should stress-test the application to make sure what the impact is in your environment."

1 . At 9:16 PM on Oct 12, 2007, Carl Dea wrote:
  Click to reply to this thread Reply

Re: Aranea, Continuations, and Swing

Geertjan,

I have not downloaded and tried this yet, but by reading the code at the web site, I noticed the System.exit(0); after the loop (1 to 10). I'm not really understanding the use case.

Is this what it is supposed to do:
1) user clicks button 5 times.
result: "You have clicked me 1", 2, 3, 4, 5
2) user closes application.
3) user launches application.
4) user clicks button 1 time.
result: "You have clicked me 6"

If the above is the use case:
It looks like the annotation tells JavaFlow to collect the stack trace and the program counter(the guts) and shoves it into a continuation object to be serialized or stuffs it into the JPanel, but where does it get stored on the disk?

There's a lot of hand waving and I'm not clear as to how this magic occurs.

This seems cool, but with Great Power Comes Great Responsibility.

I thought CGlib was cool.

-Carl
2 . At 4:55 PM on Oct 15, 2007, Geertjan wrote:
  Click to reply to this thread Reply

Re: Aranea, Continuations, and Swing

Hi Carl! I believe that that's how it's supposed to work. Personally I'm not an expert when it comes to Aranea continuations, just beginning to explore it. The main thing I've learned is how to create an Ant script for instrumenting the Java classes that use the continuations, which is what this tip is about. I've been trying to get hold of one of the Aranea developers to give more insight, but no luck thus far.
3 . At 12:20 AM on Oct 17, 2007, Carl Dea wrote:
  Click to reply to this thread Reply

Re: Aranea, Continuations, and Swing

Geertjan,

I never heard of Aranea continuations until I saw this very tip. Keep us all posted, I'm sure this kind of magic will really come in handy some day.

I'm trying to imagine applications that would need this sort of ability.

Maybe when I'm in the middle of a presentation slide with an animated transition or a moving bulleted point sliding across the screen, and then all of a sudden, I mention to the audience that I have to leave immediately. I also tell them "We will resume tomorrow!".


-Carl
4 . At 12:40 PM on Oct 17, 2007, Jevgeni Kabanov wrote:
  Click to reply to this thread Reply

Re: Aranea, Continuations, and Swing

Hello Geertjan!

We are not that hard to get hold of :) I think the easiest would be to post on forum (http://forum.araneaframework.org/ ).
5 . At 3:05 AM on Oct 18, 2007, Geertjan wrote:
  Click to reply to this thread Reply

Re: Aranea, Continuations, and Swing

Hi Jevgeni! I will do that for sure. Your continuations approach seems very interesting.

thread.rss_message