Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithDummyProcessKey(ctx Context) Context
- type Config
- type Executor
- type GroupExecutor
- type GroupProcessFactory
- type InstanceServer
- type Process
- func (p *Process) Close() error
- func (p *Process) Kill()
- func (p *Process) Serve(ctx Context, services ServiceRegistry, buffers *snapshot.Buffers) (Result, trap.ID, *snapshot.Buffers, error)
- func (p *Process) Start(code ProgramCode, state ProgramState, policy ProcessPolicy) 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 ¶
func ContextWithDummyProcessKey ¶
func ContextWithDummyProcessKey(ctx Context) Context
ContextWithDummyProcessKey for testing.
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 ¶
func (e *Executor) NewGroupProcess(ctx Context, group *ProcessGroup) (*Process, error)
NewGroupProcess creates a process into the specified group. If group is nil, the default group will be used.
func (*Executor) NewProcess ¶
NewProcess creates a process into the default group.
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, 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) (*Process, error)
NewProcess creates a process into ge.ProcessGroup.
type GroupProcessFactory ¶
type GroupProcessFactory interface { ProcessFactory NewGroupProcess(Context, *ProcessGroup) (*Process, error) }
func DistributeGroupProcesses ¶
func DistributeGroupProcesses(executors ...GroupProcessFactory) GroupProcessFactory
DistributeGroupProcesses among multiple executors.
type InstanceServer ¶
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, services ServiceRegistry, buffers *snapshot.Buffers) (Result, trap.ID, *snapshot.Buffers, error)
Serve the user program until the process terminates. Canceling the context suspends the program.
Start must have been called before this.
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) 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, f ProcessFactory, bufsize int) ProcessChan
PrepareProcesses in advance.
func (ProcessChan) NewProcess ¶
func (c ProcessChan) NewProcess(ctx 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) 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, 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()