protocol

package
v28.2.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmptyCapabilities

func EmptyCapabilities() *capabilities

func FromCapabilitiesList

func FromCapabilitiesList(caplist []string) *capabilities

Types

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 PipeTransport

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

PipeTransport implements the worker-runner protocol over a pipe. It reads from its input in the `Recv` method, and writes to its output in Send. It is safe to assume that a message has been handed to the OS when Send returns.

func NewPipeTransport

func NewPipeTransport(input io.Reader, output io.Writer) *PipeTransport

Create a new PipeTransport. The result will read from input and write to output.

func (*PipeTransport) Recv

func (transp *PipeTransport) Recv() (msg Message, ok bool)

func (*PipeTransport) Send

func (transp *PipeTransport) Send(msg Message)

type Protocol

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

func NewProtocol

func NewProtocol(transport Transport) *Protocol

func (*Protocol) AddCapability

func (prot *Protocol) AddCapability(c string)

Add the given capability to the local capabilities

func (*Protocol) Capable

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

Check if a capability is supported by both ends of the protocol, 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) WaitForEOF added in v28.2.2

func (prot *Protocol) WaitForEOF()

Wait until all message have been read from the transport.

func (*Protocol) WaitUntilInitialized

func (prot *Protocol) WaitUntilInitialized()

Wait until this protocol is initialized.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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