github.com/asynkron/protoactor-go@v0.0.0-20240308120642-ef91a6abee75/actor/messages.go (about)

     1  package actor
     2  
     3  // ResumeMailbox is message sent by the actor system to resume mailbox processing.
     4  //
     5  // This will not be forwarded to the Receive method
     6  type ResumeMailbox struct{}
     7  
     8  // SuspendMailbox is message sent by the actor system to suspend mailbox processing.
     9  //
    10  // This will not be forwarded to the Receive method
    11  type SuspendMailbox struct{}
    12  
    13  type MailboxMessage interface {
    14  	MailboxMessage()
    15  }
    16  
    17  func (*SuspendMailbox) MailboxMessage() {}
    18  func (*ResumeMailbox) MailboxMessage()  {}
    19  
    20  // InfrastructureMessage is a marker for all built in Proto.Actor messages
    21  type InfrastructureMessage interface {
    22  	InfrastructureMessage()
    23  }
    24  
    25  // IgnoreDeadLetterLogging messages are not logged in deadletter log
    26  type IgnoreDeadLetterLogging interface {
    27  	IgnoreDeadLetterLogging()
    28  }
    29  
    30  // An AutoReceiveMessage is a special kind of user message that will be handled in some way automatically by the actor
    31  type AutoReceiveMessage interface {
    32  	AutoReceiveMessage()
    33  }
    34  
    35  // NotInfluenceReceiveTimeout messages will not reset the ReceiveTimeout timer of an actor that receives the message
    36  type NotInfluenceReceiveTimeout interface {
    37  	NotInfluenceReceiveTimeout()
    38  }
    39  
    40  // A SystemMessage message is reserved for specific lifecycle messages used by the actor system
    41  type SystemMessage interface {
    42  	SystemMessage()
    43  }
    44  
    45  // A ReceiveTimeout message is sent to an actor after the Context.ReceiveTimeout duration has expired
    46  type ReceiveTimeout struct{}
    47  
    48  // A Restarting message is sent to an actor when the actor is being restarted by the system due to a failure
    49  type Restarting struct{}
    50  
    51  // A Stopping message is sent to an actor prior to the actor being stopped
    52  type Stopping struct{}
    53  
    54  // A Stopped message is sent to the actor once it has been stopped. A stopped actor will receive no further messages
    55  type Stopped struct{}
    56  
    57  // A Started message is sent to an actor once it has been started and ready to begin receiving messages.
    58  type Started struct{}
    59  
    60  // Restart is message sent by the actor system to control the lifecycle of an actor
    61  type Restart struct{}
    62  
    63  // Failure message is sent to an actor parent when an exception is thrown by one of its methods
    64  type Failure struct {
    65  	Who          *PID
    66  	Reason       interface{}
    67  	RestartStats *RestartStatistics
    68  	Message      interface{}
    69  }
    70  
    71  type continuation struct {
    72  	message interface{}
    73  	f       func()
    74  }
    75  
    76  func (*Touch) GetAutoResponse(ctx Context) interface{} {
    77  	return &Touched{
    78  		Who: ctx.Self(),
    79  	}
    80  }
    81  
    82  func (*Restarting) AutoReceiveMessage() {}
    83  func (*Stopping) AutoReceiveMessage()   {}
    84  func (*Stopped) AutoReceiveMessage()    {}
    85  func (*PoisonPill) AutoReceiveMessage() {}
    86  
    87  func (*Started) SystemMessage()      {}
    88  func (*Stop) SystemMessage()         {}
    89  func (*Watch) SystemMessage()        {}
    90  func (*Unwatch) SystemMessage()      {}
    91  func (*Terminated) SystemMessage()   {}
    92  func (*Failure) SystemMessage()      {}
    93  func (*Restart) SystemMessage()      {}
    94  func (*continuation) SystemMessage() {}
    95  
    96  var (
    97  	restartingMessage     AutoReceiveMessage = &Restarting{}
    98  	stoppingMessage       AutoReceiveMessage = &Stopping{}
    99  	stoppedMessage        AutoReceiveMessage = &Stopped{}
   100  	poisonPillMessage     AutoReceiveMessage = &PoisonPill{}
   101  	receiveTimeoutMessage interface{}        = &ReceiveTimeout{}
   102  	restartMessage        SystemMessage      = &Restart{}
   103  	startedMessage        SystemMessage      = &Started{}
   104  	stopMessage           SystemMessage      = &Stop{}
   105  	resumeMailboxMessage  MailboxMessage     = &ResumeMailbox{}
   106  	suspendMailboxMessage MailboxMessage     = &SuspendMailbox{}
   107  	_                     AutoRespond        = &Touch{}
   108  )