kernel

package
v0.0.0-...-71fdcac Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitSingle

func InitSingle() (*kdata, bool)

func MakeSidMidCombo

func MakeSidMidCombo(sid id.ServiceId, mid id.MethodId) string

MakeSidMidCombo is a utility for construction of a key (string) that is derived from the sid and mid given.

func NewSimpleNameServer

func NewSimpleNameServer(net chan proto.Message) *ns

NewSimpleNameServer returns a fully initialized instance of the NameServer interface. This version is designed for the single situation.

func NewStarter

func NewStarter() *starter

NewStarter returns an implementation of the starter that assumes we have global knowlege.

Types

type Binder

type Binder interface {
	Bind(hid id.HostId, sid id.ServiceId, mid id.MethodId, methodName string) syscall.KernelErr
}

Binder is an interface that gets notified when any method is bound. It connects the name of the method with the service and method id.

type Exporter

type Exporter interface {
	Export(hid id.HostId, sid id.ServiceId, fqn FQName) syscall.KernelErr
}

Exporter is an interface that gets notified when a service declares that it implements a particular interface (as an FQName).

type FQName

type FQName struct {
	Pkg, Name string
}

FQName is a fully qualified name of a service, analagous to syscall.FullyQualifiedName.

func (FQName) String

func (f FQName) String() string

type GeneralReceiver

type GeneralReceiver interface {
	Ch() chan *syscall.ReadOneResponse
	TimeoutInMillis() int
	HostId() id.HostId
}

type KLog

type KLog interface {
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
}

type Kernel

type Kernel interface {
	// CancelRead does nothing if the kernel is not waiting. If the kernel is
	// waiting, this method causes that to stop and the kernel returnns a timeout
	// from it's ReadOne() method.
	CancelRead()

	// SetApproach should be called once, at startup, to indicate what type of
	// deployment you are using.  Each type of deployment has exactly one approach
	// that does message send, receive, and finish.  Usually the Nameserver and
	// Starter also need to be coordinated to make the approach work. The last
	// three arguments are optional and can be nil.
	SetApproach(Nameserver, Starter, Registrar, Binder, Exporter) syscall.KernelErr

	// AddRecevier is the generic version of a receiver.  This is usually the most
	// useful if you want listen for an external network protocol.
	AddReceiver(GeneralReceiver)

	// Register is used to notify the kernel that a given service
	// should be assigned a service id.  Note that this may reach multiple
	// parts of the kernel based on the Registrar interface.
	Register(req *syscall.RegisterRequest, resp *syscall.RegisterResponse) syscall.KernelErr

	// Dispatch is used to send a call to a remote machine.  If this
	// returns a kernel error it is because the dispatch call itself could
	// not be made, not that the dispatch worked ok and an error was returned
	// by the remote code.
	Dispatch(req *syscall.DispatchRequest, resp *syscall.DispatchResponse) syscall.KernelErr

	// Launch logically causes a process to wait for all its dependencies to
	// be ready.  In practice, it returns immediately and then finishes the
	// process later.
	Launch(req *syscall.LaunchRequest, resp *syscall.LaunchResponse) syscall.KernelErr

	// BindMethod creates the mapping from the name of a method on a service to the
	// method id (and corresponding service id) that one can use to call
	// the method.
	BindMethod(req *syscall.BindMethodRequest, resp *syscall.BindMethodResponse) syscall.KernelErr

	// Export connects a particular service id to a named
	Export(req *syscall.ExportRequest, resp *syscall.ExportResponse) syscall.KernelErr

	// ReadOne returns the response to a (blocking) ReadOne request.
	// This queries various parts of the system to gather information
	// that may be needed for the response.
	ReadOne(req *syscall.ReadOneRequest, resp *syscall.ReadOneResponse) syscall.KernelErr

	// Require declares a dependency(ies) between the source and destination.
	// Destination must be started before source.
	Require(req *syscall.RequireRequest, resp *syscall.RequireResponse) syscall.KernelErr

	// Locate is the constructor for the types in parigot. It takes the name of
	// an interface (like "foo.v1.Bar") a returns a service id that implements
	// that service.
	Locate(req *syscall.LocateRequest, resp *syscall.LocateResponse) syscall.KernelErr

	// ReturnValue is used to finish a previous Dispatch call.  This is where the
	// original caller will get his call completed.
	ReturnValue(req *syscall.ReturnValueRequest, resp *syscall.ReturnValueResponse) syscall.KernelErr

	// Exit is a call that can be called to exit a single program
	// or the whole network of services.
	Exit(req *syscall.ExitRequest, resp *syscall.ExitResponse) syscall.KernelErr

	// HostDispatch mimics Dispatch but instead of returning a value to the
	// guest side code, it returns the value to the callback function passed here.
	HostDispatch(req *syscall.DispatchRequest, resp *syscall.DispatchResponse, hostFunc func(*syscall.ResolvedCall), w io.Writer) syscall.KernelErr

	// Nameserver gets the nameserver for the kernel.  This
	// does not lock.
	Nameserver() Nameserver
}

Kernel is... well... the kernel.

var K Kernel

K is the kernel. It is initialized by kernel.InitSingle or other kernel.InitXXX(). Each of these configure the kernel in different ways. This value should not set more than once.

type Nameserver

type Nameserver interface {
	Registrar
	Binder
	Exporter

	// AllHosts enumerates all the hosts that are known.
	AllHosts() []id.HostId

	// AddHosts adds a new host to the set of known hosts. Adding
	// a host multiple times is allowed.
	AddHost(id.HostId)

	// FindHost returns the host for a service id. It returns the
	// HostId zero value if this fails.
	FindHost(id.ServiceId) id.HostId

	// FindHostChan returns a chan that you can write messages
	// to and a remote host will receive them.  The remote host
	// is indicated by the parameter.  If the host is not known
	// the result will be nil
	FindHostChan(host id.HostId) chan proto.Message

	// FindMethod returns the name of a method, given host, service, and method id.
	FindMethod(id.HostId, id.ServiceId, id.MethodId) string

	// MethodDetail is used get the detailed information about a service
	// so you can potentially call one of the methods of it.  The first
	// two return values are the host/service pair for locating the
	// service.  If the returned HostId is zero value, then we could not
	// find the named service requested.  The returned map is a map from
	// string names of methods to the corresponding method ids.  MethodDetail
	// is a bit like Bind() in reverse.
	//
	// This method is not intended to be called from the guest side, but rather
	// from plugin code.
	MethodDetail(fqn FQName, methodName string) (id.HostId, id.ServiceId, id.MethodId, syscall.KernelErr)
}

type Registrar

type Registrar interface {
	Register(hid id.HostId, sid id.ServiceId, debugName string) syscall.KernelErr
}

Registrar is an interface that gets notified when any services registers. This effectively allows the implementor to become of aware of all services that are created and their corresponding host.

type SingleApproach

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

func NewSingleApproach

func NewSingleApproach(nameserver *ns) *SingleApproach

func (*SingleApproach) DispatchChan

func (s *SingleApproach) DispatchChan(hid id.HostId) chan *syscall.ReadOneResponse

func (*SingleApproach) FinishChan

func (s *SingleApproach) FinishChan(hid id.HostId) chan *syscall.ReadOneResponse

func (*SingleApproach) HandleDispatch

func (s *SingleApproach) HandleDispatch(req *syscall.DispatchRequest,
	dispChan chan *syscall.ReadOneResponse) syscall.KernelErr

HandleDispatch is called to generate a ReadOneResponse given an input dispatch request. It handles the exit call as a special case.

func (*SingleApproach) HandleReturnValue

func (s *SingleApproach) HandleReturnValue(req *syscall.ReturnValueRequest,
	finishChan chan *syscall.ReadOneResponse) syscall.KernelErr

func (*SingleApproach) Init

func (s *SingleApproach) Init() bool

Init() does initialization of this object and returns if it succeeds or not. Note that in this case of Single this method will be called three times, once for each Sender, Receiver, Finisher

func (*SingleApproach) ReadNetworkMessages

func (s *SingleApproach) ReadNetworkMessages(host id.HostId)

ReadNetworkMessages where messags to ths host "come in" from the outside world. Note that this method does not lock because it calls methods that do lock.

func (*SingleApproach) Register

func (s *SingleApproach) Register(hid id.HostId, sid id.ServiceId, debugName string) syscall.KernelErr

type Starter

type Starter interface {
	Registrar
	Binder
	Exporter
	// Require is used to indicate that a given service cannot run until all the given
	// services are already running.
	Require(*syscall.RequireRequest, *syscall.RequireResponse) syscall.KernelErr
	// Ready returns the next service id that can run and
	// the number of services left to consider.  If the returned
	// service id is the zero value, then no service is ready to run.
	Ready() (launchCompleteBundle, int)
	// Launch is called by a service indicating that all its preliminaries are
	// complete and it is waiting for the starter the tell
	// it to run.
	Launch(sid id.ServiceId, cid id.CallId, hid id.HostId, mid id.MethodId) syscall.KernelErr
	// This is the way that a named interface gets turned into a service
	// that implements that
	Locate(req *syscall.LocateRequest, resp *syscall.LocateResponse) syscall.KernelErr
}

Starter is the type that handles the machinery of getting the the services started up in the right order. "right" here means that a service doesn't start before all of it's dependencies are ready. Further, it will generally refuse attempts to locate, or "find" dependencies that were not previously declared.

Jump to

Keyboard shortcuts

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