package bridge

import "github.com/Microsoft/opengcs/service/gcs/bridge"

Package bridge defines the bridge struct, which implements the control loop and functions of the GCS's bridge client.

Index

Functions

func NotSupported

func NotSupported(w ResponseWriter, r *Request)

NotSupported represents the default handler logic for an unmatched request type sent from the bridge.

Types

type Bridge

type Bridge struct {
	// Transport is the transport interface used by the bridge.
	Transport transport.Transport

	// Handler to invoke when messages are received.
	Handler Handler
	// contains filtered or unexported fields
}

Bridge defines the bridge client in the GCS. It acts in many ways analogous to go's `http` package and multiplexer.

It has two fundamentally different dispatch options:

  1. Request/Response where using the `Handler` a request of a given type will be dispatched to the apprpriate handler and an appropriate `ResponseWriter` will respond to exactly that request that caused the dispatch.
  1. `PublishNotification` where a notification that was not initiated by a request from any client can be written to the bridge at any time in any order.

func (*Bridge) AssignHandlers

func (b *Bridge) AssignHandlers(mux *Mux, gcs core.Core)

AssignHandlers creates and assigns the appropriate bridge events to be listen for and intercepted on `mux` before forwarding to `gcs` for handling.

func (*Bridge) ListenAndServe

func (b *Bridge) ListenAndServe() (conerr error)

ListenAndServe connects to the bridge transport, listens for messages and dispatches the appropriate handlers to handle each event in an asynchronous manner.

func (*Bridge) PublishNotification

func (b *Bridge) PublishNotification(n *prot.ContainerNotification)

PublishNotification writes a specific notification to the bridge.

type Handler

type Handler interface {
	ServeMsg(ResponseWriter, *Request)
}

Handler responds to a bridge request.

func NotSupportedHandler

func NotSupportedHandler() Handler

NotSupportedHandler creates a default HandlerFunc out of the NotSupported handler logic.

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Request)

HandlerFunc is an adapter to use functions as handlers.

func (HandlerFunc) ServeMsg

func (f HandlerFunc) ServeMsg(w ResponseWriter, r *Request)

ServeMsg calls f(w, r).

type Mux

type Mux struct {
	// contains filtered or unexported fields
}

Mux is a protocol multiplexer for request response pairs following the bridge protocol.

func NewBridgeMux

func NewBridgeMux() *Mux

NewBridgeMux creates a default bridge multiplexer.

func (*Mux) Handle

func (mux *Mux) Handle(id prot.MessageIdentifier, handler Handler)

Handle registers the handler for the given message id.

func (*Mux) HandleFunc

func (mux *Mux) HandleFunc(id prot.MessageIdentifier, handler func(ResponseWriter, *Request))

HandleFunc registers the handler function for the given message id.

func (*Mux) Handler

func (mux *Mux) Handler(r *Request) Handler

Handler returns the handler to use for the given request type.

func (*Mux) ServeMsg

func (mux *Mux) ServeMsg(w ResponseWriter, r *Request)

ServeMsg dispatches the request to the handler whose type matches the request type.

type Request

type Request struct {
	Header  *prot.MessageHeader
	Message []byte
}

Request is the bridge request that has been sent.

type ResponseWriter

type ResponseWriter interface {
	// Header is the request header that was requested.
	Header() *prot.MessageHeader
	// Write a successful response message.
	Write(interface{})
	// Error writes the provided error as a response to the message.
	Error(error)
}

ResponseWriter is the dispatcher used to construct the Bridge response.

Source Files

bridge.go connection.go

Version
v0.3.3
Published
Sep 6, 2017
Platform
darwin/amd64
Imports
15 packages
Last checked
8 minutes ago

Tools for package owners.