views:

60

answers:

1

I'd like to use Processing to render a visualization on the server side (headlessly, with no GUI). The Processing sketch is static (i.e. does not animate), so I only need to grab the first frame, and I'd like to serve this result out to the users of our web application on-demand.

I've searched around a bit on the processing.org forums and it's been suggested that Processing is not intended to be launched headlessly. The only hack I've seen to do it is one involving launching a headless X11 display:

Xvfb :2 &
export DISPLAY=":2"
./myapp
killall -9 Xvfb

.. Which is not going to work for us as we'd like to have a pure-Java solution and can't always guarantee an X renderer on the server-side.

How do I do this in pure Java?

+1  A: 

Xvfb is likely to be faster than a java renderer, and a hardware-accelerated X server will be the fastest by a large margin, but if you want a 'pure' java solution you could try the Pure Java AWT Toolkit.

EDIT: Here's a boot command line example lifted from here:

java -Xbootclasspath:JDK/jre/lib/rt.jar:LIB/pja.jar -Dawt.toolkit=com.eteks.awt.PJAToolkit -Djava.awt.graphicsenv=com.eteks.java2d.PJAGraphicsEnvironment -Djava.awt.fonts=JDK/jre/lib/fonts mainclassname args
disown
This 3 year old thread on processing.org says that PJA is not compatible with Processing: http://processing.org/discourse/yabb2/YaBB.pl?num=1193317878 . Any thoughts on whether this has progressed at all?
Maciek
When I've had this problem I just bit the bullet and installed an X server. This is the fastest and most compatible - and why make the situation more difficult than it already is? In my company we spent a year trying to build a 'pure java' solution which we then threw out the window since it couldn't deal with all the corner cases. You got to use the right tool for the job. I suggest you go for X, xvfb if you don't have a graphics card on the box.
disown
Xvfb would be fine for our Linux server, but some of our development boxes are Windows-based. Is it possible to run Xvfb on Cygwin?
Maciek
Can you even run windows headless? I can imagine that you could get some sort of problem if you are running as a service, due to the restricted access to the user graphics environment, but I wouldn't expect so. Are you running into this problem?
disown