Documentation ¶
Index ¶
- Constants
- Variables
- type CgroupConfig
- type Config
- type Cred
- type Executor
- 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 Result, trapID trap.ID, err error)
- func (p *Process) Start(code ProgramCode, state ProgramState, policy ProcessPolicy) (err error)
- func (p *Process) Suspend()
- type ProcessChan
- type ProcessFactory
- type ProcessPolicy
- type ProgramCode
- type ProgramState
- type Result
- type ResultProcess
- type ServiceConfig
- type ServiceDiscoverer
- type ServiceRegistry
- type ServiceState
Constants ¶
const DefaultCgroupTitle = "gate-runtime"
const MaxProcs = 16384 // Per Executor.
const ResultSuccess = 0
ResultSuccess is the Result.Value() which indicates success.
Variables ¶
var DefaultConfig = Config{ MaxProcs: MaxProcs, LibDir: DefaultLibDir, Cgroup: CgroupConfig{ Title: DefaultCgroupTitle, }, }
var DefaultLibDir string = func() string { var parent string if filename, err := os.Executable(); err == nil { parent = path.Join(path.Dir(filename), "..") } return path.Join(parent, "lib", "gate", "runtime") }()
var ErrDuplicateService error = badprogram.Errorf("duplicate service")
Functions ¶
This section is empty.
Types ¶
type CgroupConfig ¶
CgroupConfig is effective if gate-runtime-container was compiled with cgroup support.
type Cred ¶
type Cred = runtimeapi.Cred
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor manages Process resources in an isolated environment.
func NewExecutor ¶
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 Result, trapID trap.ID, err 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 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 ServiceDiscoverer ¶
type ServiceDiscoverer interface { Discover(ctx context.Context, newNames []string) (all []ServiceState, err error) NumServices() int Suspend() (snapshots []snapshot.Service) Shutdown() }
ServiceDiscoverer is used to look up service availability when responding to a program's service discovery packet. It modifies the internal state of the ServiceRegistry server.
type ServiceRegistry ¶
type ServiceRegistry interface { StartServing( ctx context.Context, config ServiceConfig, snapshots []snapshot.Service, send chan<- packet.Buf, recv <-chan packet.Buf, ) ( ServiceDiscoverer, []ServiceState, 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 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()