Hi Paul,
Offhand, I'm not sure.

There are really several different headless modes:

1) Run Ptolemy and do not invoke any classes that attempt to communicate
with the display.  This means that no gui classes in java are called
by Ptolemy.  This is what I usually call "Headless".  

2) Run Ptolemy and use the Java headless facility:
Here, Ptolemy can probably invoke methods in the Java gui classes.

3) Run Ptolemy and use a fake display.  We do this under Solaris

4) Run with a real display.  This is not headless. 

The problem with #1 is that I've not found an easy way to catch the
exception that occurs when a Java gui class tries to communicate with
the Display.  This could have changed, but below is a braindump:

If you run 
export JAVAFLAGS=-verbose
in a headless environment, say over ssh with X11 forwarding turned off,
then you can see what classses are loaded while trying to start

The issue is that VergilApplication.java imports 
javax.swing.SwingUtilities, which starts loading libraries
[Loaded ptolemy.vergil.VergilApplication$1 from 
[Loaded javax.swing.SwingConstants from /usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]
[Loaded javax.swing.SwingUtilities from /usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]
[Loaded java.awt.EventQueue from /usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]
[Loaded sun.awt.DebugHelper from /usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]
[Loaded sun.awt.NativeLibLoader from /usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]
[Loaded sun.security.action.LoadLibraryAction from 
[Loaded java.awt.GraphicsEnvironment from /usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]
[Loaded java.awt.GraphicsEnvironment$1 from /usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]

The actual exception is:

Command failed
java.lang.Exception: Failed to parse ""
        at ptolemy.actor.gui.MoMLApplication.<init>(MoMLApplication.java:245)
        at ptolemy.vergil.VergilApplication.<init>(VergilApplication.java:98)
        at ptolemy.vergil.VergilApplication$1.run(VergilApplication.java:141)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Caused by: java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which 
requires it.
        at java.awt.Window.<init>(Window.java:318)
        at java.awt.Frame.<init>(Frame.java:419)
        at java.awt.Frame.<init>(Frame.java:384)
        at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1624)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:836)
        at ptolemy.moml.MoMLParser.startElement(MoMLParser.java:3248)

You could try doing a class lookup by calling Class.forName() on 
a swing class and see what happens.  Maybe you could query the display
for the width or something.

You could also try checking to see if the Swing Event Thread is
present.  One way to do this is to call
However, I believe that at one time, merely loading
javax.swing.SwingUtilities would start up the entire display in
a way that would just crash the process if there was no display.

Let us know what you find out.  I suspect things have changed since
I last tried this.



    Hi all, What's the easiest way to tell if Ptolemy/Kepler is running in 
    headless mode? I have actors that want to customize what they do 
    depending on whether we are in a headless or GUI environment.
    Posted to the ptolemy-hackers mailing list.  Please send administrative
    mail for this list to: [EMAIL PROTECTED]

Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to