Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithDummyProcessKey(ctx context.Context) context.Context
- type Config
- type Executor
- type GroupExecutor
- type GroupProcessFactory
- type InstanceServer
- type Logger
- type Process
- func (p *Process) Close() (err error)
- func (p *Process) Kill()
- func (p *Process) Serve(ctx context.Context, services ServiceRegistry, buffers *snapshot.Buffers) (Result, trap.ID, error)
- func (p *Process) Start(code ProgramCode, state ProgramState, policy ProcessPolicy) (err error)
- func (p *Process) Suspend()
- type ProcessChan
- type ProcessFactory
- type ProcessGroup
- type ProcessKey
- type ProcessPolicy
- type ProgramCode
- type ProgramState
- type Result
- type ResultProcess
- type ServiceConfig
- type ServiceRegistry
- type ServiceState
Constants ¶
const MaxProcs = 16384 // Per Executor.
const ResultSuccess = 0
ResultSuccess is the Result.Value() which indicates success.
Variables ¶
var DefaultConfig = Config{ MaxProcs: MaxProcs, Container: container.DefaultConfig, }
var ErrDuplicateService error = badprogram.Error("duplicate service")
Functions ¶
Types ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor manages Process resources in an isolated environment.
func NewExecutor ¶
func (*Executor) Dead ¶
func (e *Executor) Dead() <-chan struct{}
Dead channel will be closed when the executor process dies. If that wasn't requested by calling Close, it indicates an internal error.
func (*Executor) Group ¶
func (e *Executor) Group(group *ProcessGroup) GroupExecutor
Group returns a factory type which creates processes into the specified group. If group is nil, the default group will be used.
func (*Executor) NewGroupProcess ¶
NewGroupProcess creates a process into the specified group. If group is nil, the default group will be used.
type GroupExecutor ¶
type GroupExecutor struct { *Executor *ProcessGroup }
GroupExecutor overrides the default process group of an executor.
func (GroupExecutor) NewGroupProcess ¶
func (ge GroupExecutor) NewGroupProcess(ctx context.Context, group *ProcessGroup) (*Process, error)
NewGroupProcess creates a process into the specified group. If group is nil, ge.ProcessGroup will be used.
func (GroupExecutor) NewProcess ¶
func (ge GroupExecutor) NewProcess(ctx context.Context) (*Process, error)
NewProcess creates a process into ge.ProcessGroup.
type GroupProcessFactory ¶
type GroupProcessFactory interface { ProcessFactory NewGroupProcess(context.Context, *ProcessGroup) (*Process, error) }
func DistributeGroupProcesses ¶
func DistributeGroupProcesses(executors ...GroupProcessFactory) GroupProcessFactory
DistributeGroupProcesses among multiple executors.
type InstanceServer ¶
type InstanceServer interface { Start(context.Context, chan<- packet.Thunk) error Discover(ctx context.Context, newNames []string) (all []ServiceState, err error) Handle(context.Context, chan<- packet.Thunk, packet.Buf) (packet.Buf, error) Shutdown(ctx context.Context, suspend bool) ([]snapshot.Service, error) }
type Process ¶
type Process struct {
// contains filtered or unexported fields
}
Process is used to execute a single program image once. Created via an Executor or a derivative ProcessFactory.
A process is idle until its Start method is called. Close must eventually be called to release resources.
func (*Process) Kill ¶
func (p *Process) Kill()
Kill the process if it is still alive. If killed, Serve call will return with the Killed trap.
This can be called multiple times, concurrently with Start, Serve, Suspend, Close and itself.
func (*Process) Serve ¶
func (p *Process) Serve(ctx context.Context, services ServiceRegistry, buffers *snapshot.Buffers) (Result, trap.ID, error)
Serve the user program until the process terminates. Canceling the context suspends the program.
Start must have been called before this.
Buffers will be mutated (unless nil).
A meaningful trap id is returned also when an error is returned. The result is meaningful when trap is Exit.
func (*Process) Start ¶
func (p *Process) Start(code ProgramCode, state ProgramState, policy ProcessPolicy) (err error)
Start the program. The program state will be undergoing mutation until the process terminates.
This function must be called before Serve.
func (*Process) Suspend ¶
func (p *Process) Suspend()
Suspend the program if it is still running. If suspended, Serve call will return with the Suspended trap. (The program may get suspended also through other means.)
This can be called multiple times, concurrently with Start, Serve, Kill, Close and itself.
type ProcessChan ¶
type ProcessChan <-chan ResultProcess
func PrepareProcesses ¶
func PrepareProcesses(ctx context.Context, f ProcessFactory, bufsize int) ProcessChan
PrepareProcesses in advance.
func (ProcessChan) NewProcess ¶
func (c ProcessChan) NewProcess(ctx context.Context) (*Process, error)
type ProcessFactory ¶
func DistributeProcesses ¶
func DistributeProcesses(executors ...ProcessFactory) ProcessFactory
DistributeProcesses among multiple executors.
type ProcessGroup ¶
type ProcessGroup struct {
// contains filtered or unexported fields
}
func OpenCgroup ¶
func OpenCgroup(name string) (*ProcessGroup, error)
func (*ProcessGroup) Close ¶
func (g *ProcessGroup) Close() error
type ProcessKey ¶
type ProcessKey struct {
// contains filtered or unexported fields
}
ProcessKey is an opaque handle to a single instance of a program image being executed.
func MustContextProcessKey ¶
func MustContextProcessKey(ctx context.Context) ProcessKey
func (ProcessKey) Compare ¶
func (key ProcessKey) Compare(other ProcessKey) int
type ProgramCode ¶
type ProgramState ¶
type ResultProcess ¶
type ServiceConfig ¶
type ServiceConfig struct {
MaxSendSize int // Maximum size which the program is prepared to receive.
}
ServiceConfig for program instance specific ServiceRegistry invocation.
type ServiceRegistry ¶
type ServiceRegistry interface {
CreateServer(context.Context, ServiceConfig, []snapshot.Service, chan<- packet.Thunk) (InstanceServer, []ServiceState, <-chan error, error)
}
ServiceRegistry is a collection of configured services.
StartServing is called once for each program instance. The receive channel is closed when the program is being shut down.
config.MaxSendSize may be used when buffering data.
The snapshot buffers must not be mutated, and references to them shouldn't be retained for long as they may be parts of a large memory allocation.
The returned channel will deliver up to one error if one occurs after initialization.
The service package contains an implementation of this interface.
type ServiceState ¶
type ServiceState struct {
// contains filtered or unexported fields
}
ServiceState is used to respond to a service discovery request.
func (*ServiceState) SetAvail ¶
func (s *ServiceState) SetAvail()