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

     1  package remote
     2  
     3  import (
     4  	"github.com/asynkron/protoactor-go/actor"
     5  )
     6  
     7  type process struct {
     8  	pid    *actor.PID
     9  	remote *Remote
    10  }
    11  
    12  func newProcess(pid *actor.PID, r *Remote) actor.Process {
    13  	return &process{
    14  		pid:    pid,
    15  		remote: r,
    16  	}
    17  }
    18  
    19  var _ actor.Process = &process{}
    20  
    21  func (ref *process) SendUserMessage(pid *actor.PID, message interface{}) {
    22  	header, msg, sender := actor.UnwrapEnvelope(message)
    23  	ref.remote.SendMessage(pid, header, msg, sender, -1)
    24  }
    25  
    26  func (ref *process) SendSystemMessage(pid *actor.PID, message interface{}) {
    27  	// intercept any Watch messages and direct them to the endpoint manager
    28  	switch msg := message.(type) {
    29  	case *actor.Watch:
    30  		rw := &remoteWatch{
    31  			Watcher: msg.Watcher,
    32  			Watchee: pid,
    33  		}
    34  		// endpointManager.remoteWatch(rw)
    35  		ref.remote.edpManager.remoteWatch(rw)
    36  	case *actor.Unwatch:
    37  		ruw := &remoteUnwatch{
    38  			Watcher: msg.Watcher,
    39  			Watchee: pid,
    40  		}
    41  		// endpointManager.remoteUnwatch(ruw)
    42  		ref.remote.edpManager.remoteUnwatch(ruw)
    43  	default:
    44  		ref.remote.SendMessage(pid, nil, message, nil, -1)
    45  	}
    46  }
    47  
    48  func (ref *process) Stop(pid *actor.PID) {
    49  	ref.SendSystemMessage(pid, stopMessage)
    50  }