Documentation ¶
Overview ¶
Package messenger includes a messenger and a transporter. The messenger provides interfaces to send a protobuf message through the underlying transporter. It also dispatches messages to installed handlers.
Index ¶
- Constants
- Variables
- func ClientTLSConfig(config *tls.Config, handshakeTimeout time.Duration) httpOpt
- func ServerTLSConfig(config *tls.Config, ...) httpOpt
- func UPIDBindingAddress(hostname string, bindingAddress net.IP) (string, error)
- type Decoder
- type HTTPTransporter
- func (t *HTTPTransporter) Install(msgName string)
- func (t *HTTPTransporter) Recv() (*Message, error)
- func (t *HTTPTransporter) Send(ctx context.Context, msg *Message) (sendError error)
- func (t *HTTPTransporter) Start() (upid.UPID, <-chan error)
- func (t *HTTPTransporter) Stop(graceful bool) error
- func (t *HTTPTransporter) UPID() upid.UPID
- type MesosMessenger
- func (m *MesosMessenger) Install(handler MessageHandler, msg proto.Message) error
- func (m *MesosMessenger) Route(ctx context.Context, upid *upid.UPID, msg proto.Message) error
- func (m *MesosMessenger) Send(ctx context.Context, upid *upid.UPID, msg proto.Message) error
- func (m *MesosMessenger) Start() error
- func (m *MesosMessenger) Stop() (err error)
- func (m *MesosMessenger) UPID() upid.UPID
- type Message
- type MessageHandler
- type Messenger
- type Request
- type Response
- type Transporter
Constants ¶
const ( DefaultReadTimeout = 10 * time.Second DefaultWriteTimeout = 10 * time.Second )
Variables ¶
var ( ReadTimeout = DefaultReadTimeout WriteTimeout = DefaultWriteTimeout // HttpClient is used for sending messages to remote processes HttpClient = http.Client{ Timeout: DefaultReadTimeout, } )
Functions ¶
func ClientTLSConfig ¶
func ServerTLSConfig ¶
func UPIDBindingAddress ¶
UPIDBindingAddress determines the value of UPID.Host that will be used to build a Transport. If a non-nil, non-wildcard bindingAddress is specified then it will be used for both the UPID and Transport binding address. Otherwise hostname is resolved to an IP address and the UPID.Host is set to that address and the bindingAddress is passed through to the Transport.
Types ¶
type Decoder ¶
func DecodeHTTP ¶
func DecodeHTTP(w http.ResponseWriter, r *http.Request) Decoder
DecodeHTTP hijacks an HTTP server connection and generates mesos libprocess HTTP requests via the returned chan. Upon generation of an error in the error chan the decoder's internal goroutine will terminate. This func returns immediately. The caller should immediately *stop* using the ResponseWriter and Request that were passed as parameters; the decoder assumes full control of the HTTP transport.
type HTTPTransporter ¶
type HTTPTransporter struct {
// contains filtered or unexported fields
}
HTTPTransporter implements the interfaces of the Transporter.
func NewHTTPTransporter ¶
func NewHTTPTransporter(upid upid.UPID, address net.IP, opts ...httpOpt) *HTTPTransporter
NewHTTPTransporter creates a new http transporter with an optional binding address.
func (*HTTPTransporter) Install ¶
func (t *HTTPTransporter) Install(msgName string)
Install the request URI according to the message's name.
func (*HTTPTransporter) Recv ¶
func (t *HTTPTransporter) Recv() (*Message, error)
Recv returns the message, one at a time.
func (*HTTPTransporter) Send ¶
func (t *HTTPTransporter) Send(ctx context.Context, msg *Message) (sendError error)
Send sends the message to its specified upid.
func (*HTTPTransporter) Start ¶
func (t *HTTPTransporter) Start() (upid.UPID, <-chan error)
Start starts the http transporter
func (*HTTPTransporter) Stop ¶
func (t *HTTPTransporter) Stop(graceful bool) error
Stop stops the http transporter by closing the listener.
func (*HTTPTransporter) UPID ¶
func (t *HTTPTransporter) UPID() upid.UPID
UPID returns the upid of the transporter.
type MesosMessenger ¶
type MesosMessenger struct {
// contains filtered or unexported fields
}
MesosMessenger is an implementation of the Messenger interface.
func New ¶
func New(t Transporter) *MesosMessenger
func NewHttp ¶
func NewHttp(upid upid.UPID, opts ...httpOpt) *MesosMessenger
NewMesosMessenger creates a new mesos messenger.
func NewHttpWithBindingAddress ¶
func NewHttpWithBindingAddress(upid upid.UPID, address net.IP, opts ...httpOpt) *MesosMessenger
func (*MesosMessenger) Install ¶
func (m *MesosMessenger) Install(handler MessageHandler, msg proto.Message) error
/ Install installs the handler with the given message.
func (*MesosMessenger) Route ¶
Route puts a message either in the incoming or outgoing queue. This method is useful for: 1) routing internal error to callback handlers 2) testing components without starting remote servers.
func (*MesosMessenger) Send ¶
Send puts a message into the outgoing queue, waiting to be sent. With buffered channels, this will not block under moderate throughput. When an error is generated, the error can be communicated by placing a message on the incoming queue to be handled upstream.
func (*MesosMessenger) Start ¶
func (m *MesosMessenger) Start() error
Start starts the messenger; expects to be called once and only once.
func (*MesosMessenger) Stop ¶
func (m *MesosMessenger) Stop() (err error)
Stop stops the messenger and clean up all the goroutines.
func (*MesosMessenger) UPID ¶
func (m *MesosMessenger) UPID() upid.UPID
UPID returns the upid of the messenger.
type Message ¶
Message defines the type that passes in the Messenger.
func (*Message) RequestURI ¶
RequestURI returns the request URI of the message.
type MessageHandler ¶
MessageHandler is the callback of the message. When the callback is invoked, the sender's upid and the message is passed to the callback.
type Messenger ¶
type Messenger interface { Install(handler MessageHandler, msg proto.Message) error Send(ctx context.Context, upid *upid.UPID, msg proto.Message) error Route(ctx context.Context, from *upid.UPID, msg proto.Message) error Start() error Stop() error UPID() upid.UPID }
Messenger defines the interfaces that should be implemented.
func ForHostname ¶
func ForHostname(proc *process.Process, hostname string, bindingAddress net.IP, port uint16, publishedAddress net.IP) (Messenger, error)
ForHostname creates a new default messenger (HTTP), using UPIDBindingAddress to determine the binding-address used for both the UPID.Host and Transport binding address.
type Transporter ¶
type Transporter interface { //Send sends message to remote process. Must use context to determine //cancelled requests. Will stop sending when transport is stopped. Send(ctx context.Context, msg *Message) error //Rcvd receives and delegate message handling to installed handlers. //Will stop receiving when transport is stopped. Recv() (*Message, error) //Install mount an handler based on incoming message name. Install(messageName string) //Start starts the transporter and returns immediately. The error chan //is never nil. Start() (upid.UPID, <-chan error) //Stop kills the transporter. Stop(graceful bool) error //UPID returns the PID for transporter. UPID() upid.UPID }
Transporter defines methods for communicating with remote processes.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package testmessage is a generated protocol buffer package.
|
Package testmessage is a generated protocol buffer package. |