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:
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/
Here, Ptolemy can probably invoke methods in the Java gui classes.

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

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
$PTII/bin/vergil
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 
file:/export/home1/cxh/src/ptII/]
[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 
/usr/jdk/jdk1.5.0_15/jre/lib/rt.jar]
[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.throwArgsException(MoMLApplication.java:584)
        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.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at 
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        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.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
        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.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1666)
        at 
javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1743)
        at javax.swing.JOptionPane.getRootFrame(JOptionPane.java:1624)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:836)
        at 
ptolemy.vergil.VergilErrorHandler.handleError(VergilErrorHandler.java:133)
        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
javax.swing.SwingUtilities.isEventDispatchThread().
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.

_Christopher





--------

    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.
    
    Thanks,
    -Paul
    
    
    
    ---------------------------------------------------------------------------
   -
    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