package messenger

import "k8s.io/kubernetes/Godeps/_workspace/src/github.com/mesos/mesos-go/messenger"

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

Functions

func UPIDBindingAddress

func UPIDBindingAddress(hostname string, bindingAddress net.IP) (string, error)

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 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) *HTTPTransporter

NewHTTPTransporter creates a new http transporter with an optional binding address.

func (*HTTPTransporter) Inject

func (t *HTTPTransporter) Inject(ctx context.Context, msg *Message) error

Inject places a message into the incoming message queue.

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() <-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(upid *upid.UPID, t Transporter) *MesosMessenger

func NewHttp

func NewHttp(upid *upid.UPID) *MesosMessenger

NewMesosMessenger creates a new mesos messenger.

func NewHttpWithBindingAddress

func NewHttpWithBindingAddress(upid *upid.UPID, address net.IP) *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

func (m *MesosMessenger) Route(ctx context.Context, upid *upid.UPID, msg proto.Message) error

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

func (m *MesosMessenger) Send(ctx context.Context, upid *upid.UPID, msg proto.Message) error

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.

func (*MesosMessenger) Stop

func (m *MesosMessenger) Stop() 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

type Message struct {
	UPID         *upid.UPID
	Name         string
	ProtoMessage proto.Message
	Bytes        []byte
}

Message defines the type that passes in the Messenger.

func (*Message) RequestURI

func (m *Message) RequestURI() string

RequestURI returns the request URI of the message.

type MessageHandler

type MessageHandler func(from *upid.UPID, pbMsg proto.Message)

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) (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 MockedMessenger

type MockedMessenger struct {
	mock.Mock
	// contains filtered or unexported fields
}

MockedMessenger is a messenger that returns error on every operation.

func NewMockedMessenger

func NewMockedMessenger() *MockedMessenger

NewMockedMessenger returns a mocked messenger used for testing.

func (*MockedMessenger) Install

func (m *MockedMessenger) Install(handler MessageHandler, msg proto.Message) error

Install is a mocked implementation.

func (*MockedMessenger) Recv

func (m *MockedMessenger) Recv(from *upid.UPID, msg proto.Message)

Recv receives a upid and a message, it will dispatch the message to its handler with the upid. This is for testing.

func (*MockedMessenger) Route

func (m *MockedMessenger) Route(ctx context.Context, upid *upid.UPID, msg proto.Message) error

func (*MockedMessenger) Send

func (m *MockedMessenger) Send(ctx context.Context, upid *upid.UPID, msg proto.Message) error

Send is a mocked implementation.

func (*MockedMessenger) Start

func (m *MockedMessenger) Start() error

Start is a mocked implementation.

func (*MockedMessenger) Stop

func (m *MockedMessenger) Stop() error

Stop is a mocked implementation.

func (*MockedMessenger) UPID

func (m *MockedMessenger) UPID() *upid.UPID

UPID is a mocked implementation.

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)

	//Inject injects a message to the incoming queue. Must use context to
	//determine cancelled requests. Injection is aborted if the transport
	//is stopped.
	Inject(ctx context.Context, msg *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() <-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

doc.go http_transporter.go message.go messenger.go mocked_messenger.go transporter.go

Directories

PathSynopsis
Godeps/_workspace/src/github.com/mesos/mesos-go/messenger/testmessagePackage testmessage is a generated protocol buffer package.
Version
v1.1.0-alpha.1
Published
Aug 28, 2015
Platform
linux/amd64
Imports
21 packages
Last checked
7 minutes ago

Tools for package owners.