lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Quintiq file version 2.0
#parent: #root
Method ExecuteFirstInboundMessage (
  DSP_ServiceCommitterBase local_committer
) as Boolean
{
  Description:
  [*
    Executes a single inbound message and returns true if this was succesful
    When not succesfull kick error processing.
  *]
  TextBody:
  [*
    soft_error := "";
    can_continue := false;
    dsp := this.DistributedServiceProviderBase();
    imsg := this.InboundMessageQueue().FirstMessage();
    is_full_sync_msg := imsg.istype( DSP_FullSyncMessage );
      
    if ( imsg.StateSeqNr() >=0 and local_committer.StateSeqNr() > imsg.StateSeqNr() ) 
    {
      dsp.Log( "Skipping message " + [String]imsg.StateSeqNr() + " while in state " + [String] local_committer.StateSeqNr(), false ); 
      imsg.Delete(); 
      can_continue := true;
    }
    else if ( imsg.StateSeqNr() >= 0 and local_committer.StateSeqNr() < imsg.StateSeqNr() )
    {
      dsp.Log( "Missing message for current state " + [String] local_committer.StateSeqNr() + ". First message is for state" + [String]imsg.StateSeqNr() + " --> Requesting sync", false );        
      // We need to update the StateSeqNr here so that the local_committer will eventually
      // has the same StateSeqNr as the master commiter. Otherwise, this will be an endless
      // loop which the process keeps requesting fullsync and master committer keeps sending
      // new StateSeqNr
      local_committer.StateSeqNr( imsg.StateSeqNr() );
      this.RequestSync( local_committer );
    }
    else
    {
      if ( not is_full_sync_msg and not imsg.Execute( local_committer, soft_error ) )
      {
        assert ( soft_error <> "", "Message execution returned false but did not provide error details" );
        dsp.Log("Soft error '" + soft_error + "' encountered while executing message: " + imsg.GetMessageDescription(), false );      
      }
      else
      {
        if ( is_full_sync_msg and not this.DistributedServiceProviderBase().IsMaster() )
        {
          dsp.Log( "Full sync message processed --> Requesting sync", false );        
          this.RequestSync( local_committer );
        }
      
        // Message was processed:
        // 1. Increase state seqnr
        // 2. Broadcast processed master message and discard processed slave messages
        dsp.Log( "Executed message: " + imsg.GetMessageDescription(), true );
        this.SetInboundMessageProcessed( imsg, local_committer );
        can_continue := true;
      }
    }
    
    if ( soft_error <> "" )
    {
      this.ExecuteInboundError( soft_error, true /*is_soft_error*/ );
    }
    
    return can_continue;
  *]
}