com.jogamp.newt.util
Class MainThread

java.lang.Object
  extended by com.jogamp.newt.util.MainThread
All Implemented Interfaces:
EDTUtil

public class MainThread
extends Object
implements EDTUtil

NEWT Utility class MainThread

This class provides a startup singleton main thread, from which a new thread with the users main class is launched.
Such behavior is necessary for native windowing toolkits, where the windowing management must happen on the so called main thread e.g. for Mac OS X !
Utilizing this class as a launchpad, now you are able to use a NEWT multithreaded application with window handling within the different threads, even on these restricted platforms.
To support your NEWT Window platform, you have to pass your main thread actions to invoke(..), have a look at the MacWindow implementation.
TODO: Some hardcoded dependencies exist in this implementation, where you have to patch this code or factor it out.

If your platform is not Mac OS X, but you want to test your code without modifying this class, you have to set the system property newt.MainThread.force to true.

The code is compatible with all other platform, which support multithreaded windowing handling. Since those platforms won't trigger the main thread serialization, the main method will be simply executed, in case you haven't set newt.MainThread.force to true.

Test case on Mac OS X (or any other platform):

    java -XstartOnFirstThread com.jogamp.newt.util.MainThread demos.es1.RedSquare -GL2 -GL2 -GL2 -GL2
 
Which starts 4 threads, each with a window and OpenGL rendering.


Field Summary
static boolean MAIN_THREAD_CRITERIA
           
 
Fields inherited from interface com.jogamp.newt.util.EDTUtil
defaultEDTPollGranularity
 
Constructor Summary
MainThread()
           
 
Method Summary
static void addPumpMessage(Display dpy, Runnable pumpMessage)
           
static MainThread getSingleton()
           
 void invoke(boolean wait, Runnable r)
          Append task to the EDT task queue.
Wait until execution is finished if wait == true.
Shall start the thread if not running.
Can be issued from within EDT, ie from within an enqueued task.
 void invokeStop(Runnable r)
          Append the final task to the EDT task queue, signals EDT to stop and wait until stopped.
Due to the nature of this method: All previous queued tasks will be finished. No new tasks are allowed, an Exception is thrown. Can be issued from within EDT, ie from within an enqueued task. EDTUtil.reset() may follow immediately, ie creating a new EDT
 boolean isCurrentThreadEDT()
           
 boolean isRunning()
           
static void main(String[] args)
          Your new java application main entry, which pipelines your application
static Runnable removePumpMessage(Display dpy)
           
 void reset()
          Create a new EDT.
 void run()
           
 void start()
          Start the EDT
 void waitUntilIdle()
          Wait until the EDT task queue is empty.
The last task may still be in execution when this method returns.
 void waitUntilStopped()
          Wait until EDT task is stopped.
No stop action is performed, EDTUtil.invokeStop(java.lang.Runnable) should be used before.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAIN_THREAD_CRITERIA

public static final boolean MAIN_THREAD_CRITERIA
Constructor Detail

MainThread

public MainThread()
Method Detail

main

public static void main(String[] args)
Your new java application main entry, which pipelines your application


getSingleton

public static MainThread getSingleton()

removePumpMessage

public static Runnable removePumpMessage(Display dpy)

addPumpMessage

public static void addPumpMessage(Display dpy,
                                  Runnable pumpMessage)

reset

public final void reset()
Description copied from interface: EDTUtil
Create a new EDT. One should invoke reset()
after invokeStop(..) in case another start() or invoke(..) is expected.

Specified by:
reset in interface EDTUtil
See Also:
EDTUtil.start(), EDTUtil.invoke(boolean, java.lang.Runnable), EDTUtil.invokeStop(java.lang.Runnable)

start

public final void start()
Description copied from interface: EDTUtil
Start the EDT

Specified by:
start in interface EDTUtil

isCurrentThreadEDT

public final boolean isCurrentThreadEDT()
Specified by:
isCurrentThreadEDT in interface EDTUtil
Returns:
True if the current thread is the EDT thread

isRunning

public final boolean isRunning()
Specified by:
isRunning in interface EDTUtil
Returns:
True if EDT is running

invokeStop

public final void invokeStop(Runnable r)
Description copied from interface: EDTUtil
Append the final task to the EDT task queue, signals EDT to stop and wait until stopped.
Due to the nature of this method:

Specified by:
invokeStop in interface EDTUtil

invoke

public final void invoke(boolean wait,
                         Runnable r)
Description copied from interface: EDTUtil
Append task to the EDT task queue.
Wait until execution is finished if wait == true.
Shall start the thread if not running.
Can be issued from within EDT, ie from within an enqueued task.

Specified by:
invoke in interface EDTUtil

waitUntilIdle

public final void waitUntilIdle()
Description copied from interface: EDTUtil
Wait until the EDT task queue is empty.
The last task may still be in execution when this method returns.

Specified by:
waitUntilIdle in interface EDTUtil

waitUntilStopped

public final void waitUntilStopped()
Description copied from interface: EDTUtil
Wait until EDT task is stopped.
No stop action is performed, EDTUtil.invokeStop(java.lang.Runnable) should be used before.

Specified by:
waitUntilStopped in interface EDTUtil

run

public void run()


Copyright 2010 JogAmp Community.