home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / fp1os2.arj / OS2 / DATA / 49 / C / 0 / F_26836 / SJCondAckMsgStruct.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-15  |  2.4 KB  |  115 lines

  1. import stardiv.tools.SjProtocolWindow;
  2.  
  3. class SJCondAckMsgStruct extends SJCondMsgStruct implements SJMessageHandlerInterface {
  4.    private boolean bMessageDone = false;
  5.    private boolean bMessageError = false;
  6.    private SJMessageHandlerInterface aAckObject;
  7.  
  8.    private final void SendAck(SJMessage var1) {
  9.       if (this.aAckObject != null) {
  10.          this.aAckObject.HandleMessage(var1);
  11.       }
  12.  
  13.    }
  14.  
  15.    public SJCondAckMsgStruct(SJMessageHandlerInterface var1) {
  16.       super(var1);
  17.    }
  18.  
  19.    public final boolean IsTrue() {
  20.       return this.HasResult();
  21.    }
  22.  
  23.    public final synchronized void DeliverAndAcknowledge(SJMessageHandlerInterface var1) {
  24.       this.aAckObject = var1;
  25.       ((SJCondMsgStruct)this).GetMessage().JOB_SetNotifyObject(this);
  26.       ((SJCondMsgStruct)this).GetDestination().HandleMessage(((SJCondMsgStruct)this).GetMessage());
  27.    }
  28.  
  29.    public final boolean PeekMessageDone() {
  30.       return this.bMessageDone;
  31.    }
  32.  
  33.    public final synchronized void WaitForMessageDone() {
  34.       try {
  35.          while(!this.bMessageDone) {
  36.             SjProtocolWindow.AddWaitEvent(this, "SJJob.WaitForMessageDone()");
  37.             this.wait();
  38.             SjProtocolWindow.AddWaitEventDONE(this, "SJJob.WaitForMessageDone()");
  39.          }
  40.  
  41.       } catch (InterruptedException var1) {
  42.       }
  43.    }
  44.  
  45.    private final synchronized void SetMessageDone() {
  46.       this.bMessageDone = true;
  47.       SjProtocolWindow.AddNotifyEvent(this, "SJJob.SetMessageDone()");
  48.       this.notifyAll();
  49.       SjProtocolWindow.AddNotifyEventDONE(this, "SJJob.SetMessageDone()");
  50.    }
  51.  
  52.    public final boolean PeekMessageError() {
  53.       return this.bMessageError;
  54.    }
  55.  
  56.    private final synchronized void SetMessageError() {
  57.       this.bMessageError = true;
  58.       SjProtocolWindow.AddNotifyEvent(this, "SJJob.SetMessageError()");
  59.       this.notifyAll();
  60.       SjProtocolWindow.AddNotifyEvent(this, "SJJob.SetMessageError()");
  61.    }
  62.  
  63.    private final synchronized boolean HasDoneNothing() {
  64.       return !this.bMessageDone && !this.bMessageError && !((SJCondMsgStruct)this).PeekMessagePending();
  65.    }
  66.  
  67.    private final synchronized void WaitForSomething() {
  68.       try {
  69.          while(this.HasDoneNothing()) {
  70.             SjProtocolWindow.AddWaitEvent(this, "SJJob.WaitForSomething()");
  71.             this.wait();
  72.             SjProtocolWindow.AddWaitEventDONE(this, "SJJob.WaitForSomething()");
  73.          }
  74.  
  75.       } catch (InterruptedException var1) {
  76.       }
  77.    }
  78.  
  79.    public final synchronized boolean HasResult() {
  80.       return this.bMessageDone || this.bMessageError;
  81.    }
  82.  
  83.    private final synchronized void WaitForResult() {
  84.       try {
  85.          while(this.HasResult()) {
  86.             SjProtocolWindow.AddWaitEvent(this, "SJJob.WaitForResult()");
  87.             this.wait();
  88.             SjProtocolWindow.AddWaitEventDONE(this, "SJJob.WaitForResult()");
  89.          }
  90.  
  91.       } catch (InterruptedException var1) {
  92.       }
  93.    }
  94.  
  95.    public void HandleMessage(SJMessage var1) {
  96.       if (var1 != null) {
  97.          switch (var1.GetID()) {
  98.             case 10000:
  99.                this.SetMessageDone();
  100.                this.SendAck(var1);
  101.                return;
  102.             case 10001:
  103.                super.SetMessagePending();
  104.                this.SendAck(var1);
  105.                return;
  106.             case 10002:
  107.                this.SetMessageError();
  108.                this.SendAck(var1);
  109.                return;
  110.             default:
  111.          }
  112.       }
  113.    }
  114. }
  115.