home *** CD-ROM | disk | FTP | other *** search
- import stardiv.tools.SjProtocolWindow;
-
- public class SJMTObject implements Runnable, SJMessageHandlerInterface {
- protected Thread aThread;
- private SJEventSemaphore aSem;
- protected JSbxQueue aMessageQueue;
- private SJMessageHandlerInterface aCallbackObj;
- private boolean bStopMessageLoop;
- private boolean bThreadIsReady;
- private static long nObjCount;
-
- protected void finalize() {
- SjProtocolWindow.DecSJMTObjectCount();
- if (SjProtocolWindow.IsMemTraceModeOn()) {
- System.out.println(--nObjCount + "***DESTR. " + this);
- }
-
- }
-
- protected void Constr() {
- SjProtocolWindow.IncSJMTObjectCount();
- if (SjProtocolWindow.IsMemTraceModeOn()) {
- System.out.println(++nObjCount + "***CONSTR. " + this);
- }
-
- }
-
- public SJMTObject() {
- this(true, true, (SJMessageHandlerInterface)null, (String)null, (ThreadGroup)null);
- }
-
- public SJMTObject(SJMessageHandlerInterface var1) {
- this(true, true, var1, (String)null, (ThreadGroup)null);
- }
-
- public SJMTObject(boolean var1, String var2, ThreadGroup var3) {
- this(var1, var1, (SJMessageHandlerInterface)null, var2, var3);
- }
-
- public SJMTObject(SJMessageHandlerInterface var1, String var2, ThreadGroup var3) {
- this(true, true, var1, var2, var3);
- }
-
- public SJMTObject(SJMessageHandlerInterface var1, String var2) {
- this(true, true, var1, var2, (ThreadGroup)null);
- }
-
- public SJMTObject(boolean var1) {
- this(var1, true, (SJMessageHandlerInterface)null, (String)null, (ThreadGroup)null);
- }
-
- public SJMTObject(SJMessageHandlerInterface var1, boolean var2) {
- this(var2, true, var1, (String)null, (ThreadGroup)null);
- }
-
- private SJMTObject(boolean var1, boolean var2, SJMessageHandlerInterface var3, String var4, ThreadGroup var5) {
- this.Constr();
- this.bStopMessageLoop = false;
- this.bThreadIsReady = false;
- this.aCallbackObj = var3;
- if (var1) {
- this.aMessageQueue = new JSbxQueue(this);
- if (var5 != null && var4 != null) {
- this.aThread = new Thread(var5, this, var4);
- }
-
- if (var5 != null && var4 == null) {
- this.aThread = new Thread(var5, this);
- }
-
- if (var5 == null && var4 != null) {
- this.aThread = new Thread(this, var4);
- }
-
- if (var5 == null && var4 == null) {
- this.aThread = new Thread(this);
- }
-
- if (var2) {
- this.aThread.start();
- return;
- }
- } else {
- this.aMessageQueue = null;
- this.aThread = null;
- }
-
- }
-
- public final boolean IsRunningInOwnThread() {
- return this.aThread != null;
- }
-
- public final void DoStartThread() {
- if (this.aThread != null) {
- this.aThread.start();
- }
-
- }
-
- public final void DoSuspendThread() {
- if (this.aThread != null) {
- this.aThread.suspend();
- }
-
- }
-
- public final void DoResumeThread() {
- if (this.aThread != null) {
- this.aThread.resume();
- }
-
- }
-
- public final void DoStopThread() {
- if (this.aThread != null) {
- this.aThread.stop();
- }
-
- }
-
- protected void ProcessMessage(SJMessage var1) {
- System.out.println("WARNING: SJMTObject.ProcessMessage() not overloaded ! this=" + this);
- }
-
- public void HandleMessage(SJMessage var1) {
- if (this.IsRunningInOwnThread()) {
- if (this.ExistsMessageQueue()) {
- this.aMessageQueue.Append(var1);
- return;
- }
- } else {
- this.ProcessMessage(var1);
- }
-
- }
-
- public void run() {
- this.SetThreadReady();
- if (this.aCallbackObj != null) {
- this.aCallbackObj.HandleMessage(new SJMessage(10021, (SJMessageHandlerInterface)null, this));
- }
-
- while(!this.bStopMessageLoop) {
- SJMessage var1 = (SJMessage)this.aMessageQueue.Get();
- this.ProcessMessage(var1);
- }
-
- if (this.aCallbackObj != null) {
- this.aCallbackObj.HandleMessage(new SJMessage(10023, (SJMessageHandlerInterface)null, this));
- }
-
- this.ClearThreadReady();
- }
-
- public final synchronized void StopMessageLoop() {
- this.bStopMessageLoop = true;
- this.AddToMessageQueue(new SJMessage());
- SjProtocolWindow.AddNotifyEvent(this, "SJMTObject.StopMessageLoop()");
- this.notifyAll();
- SjProtocolWindow.AddNotifyEventDONE(this, "SJMTObject.StopMessageLoop()");
- }
-
- public final boolean ExistsMessageQueue() {
- return this.aMessageQueue != null;
- }
-
- public final void AddToMessageQueue(SJMessage var1) {
- if (this.aMessageQueue != null) {
- this.aMessageQueue.Append(var1);
- }
-
- }
-
- public final boolean IsThreadReady() {
- return this.bThreadIsReady;
- }
-
- public final synchronized void WaitForThreadReady() {
- try {
- while(!this.bThreadIsReady) {
- SjProtocolWindow.AddWaitEvent(this, "SJMTObject.WaitForThreadReady()");
- this.wait();
- SjProtocolWindow.AddWaitEventDONE(this, "SJMTObject.WaitForThreadReady()");
- }
-
- } catch (InterruptedException var1) {
- }
- }
-
- protected final synchronized void SetThreadReady() {
- this.bThreadIsReady = true;
- SjProtocolWindow.AddNotifyEvent(this, "SJMTObject.SetThreadReady()");
- this.notifyAll();
- SjProtocolWindow.AddNotifyEventDONE(this, "SJMTObject.SetThreadReady()");
- }
-
- protected final synchronized void ClearThreadReady() {
- this.bThreadIsReady = false;
- SjProtocolWindow.AddNotifyEvent(this, "SJMTObject.ClearThreadReady()");
- this.notifyAll();
- SjProtocolWindow.AddNotifyEventDONE(this, "SJMTObject.ClearThreadReady()");
- }
- }
-