protocol

package
v27.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 11, 2020 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KnownCapabilities = []string{
	"graceful-termination",
}

Functions

This section is empty.

Types

type Capabilities

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

func EmptyCapabilities

func EmptyCapabilities() *Capabilities

func FromCapabilitiesList

func FromCapabilitiesList(caplist []string) *Capabilities

func FullCapabilities

func FullCapabilities() *Capabilities

func (*Capabilities) Add

func (caps *Capabilities) Add(c string)

func (*Capabilities) Has

func (caps *Capabilities) Has(c string) bool

func (*Capabilities) LimitTo

func (caps *Capabilities) LimitTo(other *Capabilities)

func (*Capabilities) List

func (caps *Capabilities) List() []string

func (*Capabilities) Remove

func (caps *Capabilities) Remove(c string)

type FakeTransport

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

FakeTransport implements Transport and records sent messages. It is used for testing.

func NewFakeTransport

func NewFakeTransport() *FakeTransport

func (*FakeTransport) Messages

func (transp *FakeTransport) Messages() []Message

func (*FakeTransport) Recv

func (transp *FakeTransport) Recv() (Message, bool)

func (*FakeTransport) Send

func (transp *FakeTransport) Send(msg Message)

type Message

type Message struct {
	Type       string
	Properties map[string]interface{}
}

func (*Message) MarshalJSON

func (msg *Message) MarshalJSON() ([]byte, error)

func (*Message) UnmarshalJSON

func (msg *Message) UnmarshalJSON(b []byte) error

type MessageCallback

type MessageCallback func(msg Message)

type NullTransport

type NullTransport struct{}

NullTransport implements Transport without doing anything. It's suitable for workers that do not implement the protocol

func NewNullTransport

func NewNullTransport() *NullTransport

func (*NullTransport) Recv

func (transp *NullTransport) Recv() (Message, bool)

func (*NullTransport) Send

func (transp *NullTransport) Send(msg Message)

type Protocol

type Protocol struct {

	// current set of agreed capabilities (but call WaitUntilInitialized first
	// to avoid finding the empty set at startup)
	Capabilities *Capabilities
	// contains filtered or unexported fields
}

func NewProtocol

func NewProtocol(transport Transport) *Protocol

func (*Protocol) Capable

func (prot *Protocol) Capable(c string) bool

Check if a capability is supported, after waiting for initialization.

func (*Protocol) Register

func (prot *Protocol) Register(messageType string, callback MessageCallback)

Register a callback for the given message type. This must occur before the protocol is started.

func (*Protocol) Send

func (prot *Protocol) Send(msg Message)

Send a message. This happens without waiting for initialization; as the caller should already have used prot.Capable to determine whether the message was supported.

func (*Protocol) SetInitialized

func (prot *Protocol) SetInitialized()

Set this protocol as initialized. Ordinarily this happens automatically, but in cases where the worker does not support the protocol, this method can be used to indicate that the protocol is "initialized" with no capabilities.

func (*Protocol) Start

func (prot *Protocol) Start(asWorker bool)

Start the protocol and initiate the hello/welcome transaction.

func (*Protocol) WaitUntilInitialized

func (prot *Protocol) WaitUntilInitialized()

Wait until this protocol is initialized.

type StdioTransport

type StdioTransport struct {
	// channels of incoming and outgoing messages
	In  chan Message
	Out chan Message

	// a writer to which invalid lines are written, defaulting to
	// os.Stdout
	InvalidLines io.Writer
	// contains filtered or unexported fields
}

StdioTransport implements the worker-runner protocol over stdin/stdout. It implements Transport, io.Reader and io.WriteCloser, where it uses the encoding defined in `protocol.md`, and exposes channels of incoming and outgoing messages.

func NewStdioTransport

func NewStdioTransport() *StdioTransport

Create a new StdioTransport. The result implements both io.Reader and io.Writer so it can be specified as a cmd's Stdin and Stdout.

func (*StdioTransport) Close

func (transp *StdioTransport) Close() error

func (*StdioTransport) Read

func (transp *StdioTransport) Read(p []byte) (int, error)

func (*StdioTransport) Recv

func (transp *StdioTransport) Recv() (Message, bool)

func (*StdioTransport) Send

func (transp *StdioTransport) Send(msg Message)

func (*StdioTransport) Write

func (transp *StdioTransport) Write(p []byte) (int, error)

type Transport

type Transport interface {
	// Send a message to the worker
	Send(Message)

	// Receive a message from the worker, blocking until one is availble
	Recv() (Message, bool)
}

Transport is a means of sending and receiving messages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL