github.com/godevsig/adaptiveservice@v0.9.23/message.go (about)

     1  package adaptiveservice
     2  
     3  // KnownMessage represents a message with a handler that knows how to process the message.
     4  // KnownMessage is normal priority message.
     5  type KnownMessage interface {
     6  	// Handle handles the message.
     7  	// If reply is nil, no message will be sent back.
     8  	// If reply is not nil, the value will be sent back to the stream peer.
     9  	// If reply is error type, the peer's Recv() call will return it as error.
    10  	// Otherwise the reply will be received by the peer's Recv() as normal message.
    11  	//
    12  	// The message may be marshaled or compressed.
    13  	// Remember in golang assignment to interface is also value copy,
    14  	// so return reply as &someStruct whenever possible in your handler implementation.
    15  	//
    16  	// Users can directly use ContextStream to send/receive messages to/from the stream
    17  	// peer(the client) via a private dedicated channel.
    18  	//
    19  	// Use of reply is more like RPC fashion, where clients "call" the Handle() method
    20  	// on the server side as if Handle() were called on clients.
    21  	// Always return reply to client is a good idea since client is waiting for the reply.
    22  	// In the case where only final status is needed, return builtin OK on success or
    23  	// return error type if any error happened, e.g. return errors.New("some error").
    24  	//
    25  	// Use of ContextStream is more like client and server entered in an interactive
    26  	// session, in which several messages are exchanged between client and server.
    27  	//
    28  	// Cares should be taken if you mix the use of reply and ContextStream.
    29  	Handle(stream ContextStream) (reply interface{})
    30  }
    31  
    32  // HighPriorityMessage is high priority KnownMessage.
    33  type HighPriorityMessage interface {
    34  	KnownMessage
    35  	IsHighPriority()
    36  }
    37  
    38  // LowPriorityMessage is Low priority KnownMessage.
    39  type LowPriorityMessage interface {
    40  	KnownMessage
    41  	IsLowPriority()
    42  }