circuit

package
v0.0.0-...-fd2add7 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package circuit exposes the core functionalities provided by the circuit programming environment

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(v runtime)

Bind is used internally to bind an implementation of this package to the public methods of this package

func DialSelf

func DialSelf(service string) interface{}

DialSelf works similarly to Dial, except it dials into the calling worker itself and instead of returning a cross-interface to the service receiver, it returns a native Go interface. DialSelf never fails.

func Export

func Export(val ...interface{}) interface{}

Export recursively rewrites the values val into a Go type that can be serialiazed with package encoding/gob. The values val can contain permanent cross-interfaces (but no non-permanent ones).

func Hang

func Hang()

Hang never returns

func HangInBack

func HangInBack()

func Import

func Import(exported interface{}) ([]interface{}, string, error)

Import converts the exported value, that was produced as a result of Export, back into its original form.

func Kill

func Kill(addr n.Addr) error

Kill kills the process of the worker with address addr.

func Listen

func Listen(service string, receiver interface{})

Listen registers the receiver object as a receiver for the named service. Subsequent calls to Dial from other works, addressing this worker and the same service name, will return a cross-interface to receiver.

func RegisterFunc

func RegisterFunc(fn Func)

RegisterFunc registers the worker function type fn with the circuit runtime type system. fn must be of a not-necessarily public type having a single public method. As a result, this program is able to spawn fn on remote hosts, as well as to host remote invokations of fn. By convention, RegisterFunc should be invoked from a dedicated init function within of the package that defines the type of fn.

func RegisterValue

func RegisterValue(v interface{})

RegisterValue registers the type of v with the circuit runtime type system. As a result this program becomes able to send and receive cross-interfaces pointing to objects of this type. By convention, RegisterValue should be invoked from a dedicated init function within of the package that defines the type of v.

func RunInBack

func RunInBack(fn func())

RunInBack can only be called during the execution of a worker function, invoked with Spawn, and can only be called once. RunInBack instructs the circuit runtime that the hosting worker should not be killed until fn completes, even if the invoking worker function completes prior to that.

func ServerAddr

func ServerAddr() n.Addr

ServerAddr returns the address of this worker.

func Spawn

func Spawn(host worker.Host, anchor []string, fn Func, in ...interface{}) (retrn []interface{}, addr n.Addr, err error)

Spawn starts a new worker process on host. The worker is registered under all directories in the anchor file system named by anchor. The worker function fn, whose type must have previously been registered with RegisterFunc, is executed on the newly spawned worker with arguments given by in. Spawn blocks until the execution of fn completes. Spawn returns the return values of fn's invokation in the slice retrn. The types of the elements of retrn exactly match the declared return types of fn's singleton public method. Spawn also returns the address of the spawned worker in addr. The new worker will be killed as soon as fn completes, unless an extension of its life is explicitly requested during the execution of fn via a call to RunInBack. Spawn does not panic. It returns any error conditions in err, in which case retrn and addr are undefined.

Types

type Func

type Func interface{}

Func is a symbolic type that refers to circuit worker function types. These are types with a singleton public method.

type HandleID

type HandleID uint64

HandleID is a universal ID referring to a circuit value accessible across workers

func ChooseHandleID

func ChooseHandleID() HandleID

ChooseHandleID returns a random ID

func (HandleID) String

func (h HandleID) String() string

type PermX

type PermX interface {

	// A permanent cross-interface can be used as a non-permanent one.
	X

	// IsPerm is used internally.
	IsPermX()
}

PermX represents a permanent cross-interface value.

func Dial

func Dial(addr n.Addr, service string) PermX

Dial contacts the worker specified by addr and requests a cross-worker interface to the named service. If service is not being listened to at this worker, nil is returned. Failures to contact the worker for external/physical reasons result in a panic.

func PermRef

func PermRef(v interface{}) PermX

PermRef returns a permanent cross-interface to the local value v.

func TryDial

func TryDial(addr n.Addr, service string) (PermX, error)

TryDial behaves like Dial, with the difference that instead of panicking in the event of external/physical issues, an error is returned instead.

type X

type X interface {

	// Addr returns the address of the runtime, hosting the object underlying the cross-interface value.
	Addr() n.Addr

	// HandleID uniquely identifies the local reference to the receiver that was exported for this cross-reference
	HandleID() HandleID

	// Call invokes the method named proc of the actual object (possibly
	// living remotely) underlying the cross-interface. The invokation
	// arguments are take from in, and the returned values are placed in
	// the returned slice.
	//
	// Errors can only occur as a result of physical/external circumstances
	// that impede cross-worker communication. Such errors are returned in
	// the form of panics.
	Call(proc string, in ...interface{}) []interface{}

	// IsX is used internally.
	IsX()

	// String returns a human-readable representation of the cross-interface.
	String() string
}

X represents a cross-interface value.

func Ref

func Ref(v interface{}) X

Ref returns a cross-interface to the local value v.

Jump to

Keyboard shortcuts

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