service

package
v0.0.0-...-219e647 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2016 License: BSD-3-Clause Imports: 9 Imported by: 70

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

Types

type ActivatorService

type ActivatorService interface {
	// Activate represents the public interface that bundles the following lookup
	// functions.
	//
	//     GetNetworkPayload
	//     New
	//
	// Activate fetches the list of all queued network payloads of the requested
	// CLG from the underlying storage. The stored list is merged with the given
	// network payload and provided to the lookup functions listed above. Once
	// Activate found a matching network payload, the network payloads it is made
	// of are removed from the stored queue and the created network payload is
	// returned. The modifications of the updated queue are also persisted.
	// TODO the CLG is a service, it should not be provided as arguments, all information are provided by networkPayload
	Activate(clgService CLGService, networkPayload objectspec.NetworkPayload) (objectspec.NetworkPayload, error)
	Boot()
	// GetNetworkPayload compares the given queue against the stored configuration
	// of the requested CLG. This configuration is a combination of behaviour IDs
	// that are known to be successful. We know that this configuration was
	// already successful in the past when it was created by newNetworkPayload
	// beforehand. Such a creation then happened in some CLG tree execution before
	// the current one. Anyway, in case the queue of network payloads given
	// contains network payloads sent by the CLGs listed in the stored
	// configuration, the interface of the requested CLG is fulfilled. Then a new
	// network payload is created by merging the matching network payloads of the
	// stored queue. In case no activation configuration of the requested CLG is
	// stored, or no match using the stored configuration associated with the
	// requested CLG can be found, an error is returned.
	GetNetworkPayload(clgService CLGService, queue []objectspec.NetworkPayload) (objectspec.NetworkPayload, error)
	Metadata() map[string]string
	// New uses the given queue to find a combination of network
	// payloads that fulfill the interface of the requested CLG. This creation
	// process may be random or biased in some way. In case some created
	// combination of network payloads fulfills the interface of the requested
	// CLG, this found combination is stored as activation configuration for the
	// requested CLG. In case no match using the permuted network payloads of the
	// given queue can be found, an error is returned.
	New(clgService CLGService, queue []objectspec.NetworkPayload) (objectspec.NetworkPayload, error)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

ActivatorService represents an management layer to organize CLG activation rules. The activator obtains network payloads for every single requested CLG of every possible CLG tree.

type CLGService

type CLGService interface {
	Boot()
	// GetCalculate returns the CLG's calculate function which implements its
	// actual business logic.
	GetCalculate() interface{}
	Metadata() map[string]string
	Service() ServiceCollection
	// SetServiceCollection configures the CLG's factory collection. This is done
	// for all CLGs, regardless if a CLG is making use of the factory collection
	// or not.
	SetServiceCollection(serviceCollection ServiceCollection)
}

CLGService represents the CLGs interacting with each other within the neural network. Each CLG is registered in the neural network. From there signal are dispatched in a dynamic fashion until some useful calculation took place.

type ConnectionService

type ConnectionService interface {
	Boot()
	// Create creates a new connection for the given peer values.
	Create(peerA, peerB string) error
	// Delete deletes the connection identified by the given peer values.
	Delete(peerA, peerB string) error
	Metadata() map[string]string
	// Search returns all metadata associated with the connecion identified by the
	// given peer values.
	Search(peerA, peerB string) (map[string]string, error)
	// SearchPeers returns all peers identified as being connected to the peer
	// identified by the given peer value.
	SearchPeers(peer string) ([]string, error)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	Weight() float64
}

ConnectionService represents a service being able to manage connections within the connection space.

Following is some explanation about the wording being used in documentation and code.

Coordinate

    Coordinate is a point on a single dimension.

Depth

    Depth is the size of each directional coordinate within the
    connection space. E.g. using a Depth of 3, the resulting volume being
    taken by a 3 dimensional space would be 9.

Dimension

    Dimensions is the number of directional coordinates within the
    connection space. E.g. a dice has 3 dimensions.

Position

    Position is a point within the connection space. It is described by
    one coordinate for each dimension of the connection space.

Weight

    Weight is the score applied to a connection expressing its
    importance.

Following is an example of a possible storage key structure, to illustrate persisted connections. The given peers being used to create the peer and connection keys are ordered as such, that they form directed and reproducible storage keys. This means a connection can only be resolved into a certain, desired direction.

This is a peer pointing to other peers. The key on the left is a string being formed by a prefix and a peer value. The value on the right is a list of strings being formed by peer values. See also documentation for SearchPeers in the interface below.

peer:layer:information:sum     peer:layer:information:$id1
peer:layer:information:$id1    peer:layer:information:sum,peer:layer:information:$id2,peer:layer:information:$id4
peer:layer:information:$id2    peer:layer:information:$id3
peer:layer:information:$id4    peer:layer:information:$id5

This is a connection holding metadata. The key on the left is a string being formed by a prefix and the values of the two peers forming the connection. The order of the peers within the key expresses the connection direction. The value on the right is a map of strings. See also documentation for Search in the interface below.

connection:peer:layer:information:sum:peer:layer:information:$id1     created: 1481473182, updated: 1481473182, weight: 23.775
connection:peer:layer:information:$id1:peer:layer:information:sum     created: 1481473182, updated: 1481473182, weight: 23.775
connection:peer:layer:information:$id1:peer:layer:information:$id2    created: 1481473182, updated: 1481473182, weight: 23.775
connection:peer:layer:information:$id1:peer:layer:information:$id4    created: 1481473182, updated: 1481473182, weight: 23.775
connection:peer:layer:information:$id2:peer:layer:information:$id3    created: 1481473182, updated: 1481473182, weight: 23.775
connection:peer:layer:information:$id4:peer:layer:information:$id5    created: 1481473182, updated: 1481473182, weight: 23.775

Following is a list of properties each connection has applied in form of metadata to itself.

created
updated
weight

type EndpointCollection

type EndpointCollection interface {
	Boot()
	Metric() EndpointService
	SetMetricService(metricService EndpointService)
	SetTextService(textService EndpointService)
	Shutdown()
	Text() EndpointService
}

EndpointCollection represents a collection of endpoint services. This scopes different endpoint service implementations in a simple container, which can easily be passed around.

type EndpointService

type EndpointService interface {
	// Boot initializes and starts the whole server like booting a machine.
	// Listening to a socket should be done here internally. The call to Boot
	// blocks forever.
	Boot()
	Service() ServiceCollection
	SetAddress(address string)
	SetServiceCollection(serviceCollection ServiceCollection)
	// Shutdown ends all processes of the server like shutting down a machine.
	// The call to Shutdown blocks until the server is completely shut down, so
	// you might want to call it in a separate goroutine.
	Shutdown()
}

EndpointService represents a simple bootable object being able to serve network resources.

type FSService

type FSService interface {
	Boot()
	Metadata() map[string]string
	// ReadFile is aligned to ioutil.ReadFile.
	ReadFile(filename string) ([]byte, error)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	// WriteFile is aligned to ioutil.WriteFile.
	WriteFile(filename string, bytes []byte, perm os.FileMode) error
}

FSService provides certain file system implementations for abstraction and testing reasons.

type FeatureService

type FeatureService interface {
	Boot()
	Metadata() map[string]string
	// Scan analyses the given sequences to detect patterns. Found patterns are
	// returned in form of a list of features.
	Scan(config ScanConfig) ([]objectspec.Feature, error)
	// ScanConfig returns a default scan config configured by best effort.
	ScanConfig() ScanConfig
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

FeatureService represents a service being able to scan for features within information sequences.

type ForwarderService

type ForwarderService interface {
	Boot()
	// Forward represents the public interface that bundles the following lookup
	// functions.
	//
	//     GetNetworkPayloads
	//     News
	//
	// The network payloads being found by any of the lookup functions listed
	// above are queued by Forward.
	Forward(clgService CLGService, networkPayload objectspec.NetworkPayload) error
	// MaxSignals returns the maximum number of signals being forwarded by one
	// CLG.
	MaxSignals() int
	// GetNetworkPayloads tries to lookup behaviour IDs that can be used to
	// forward a certain network payload from the requested CLG to other CLGs. If
	// there are behaviour IDs found, a network payload for each behaviour ID is
	// created and the list of new network payloads is returned. If there could
	// not any behaviour ID be found, an error is returned.
	GetNetworkPayloads(clgService CLGService, networkPayload objectspec.NetworkPayload) ([]objectspec.NetworkPayload, error)
	// NewNetworkpayloads creates new connections to other CLGs in a pseudo random
	// manner. For each connection one network payload is created. The resulting
	// list is returned.
	NewNetworkpayloads(clgService CLGService, networkPayload objectspec.NetworkPayload) ([]objectspec.NetworkPayload, error)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

ForwarderService represents an management layer to organize CLG forwarding rules. The forwarder obtains behaviour IDs for every single requested CLG of every possible CLG tree.

type IDService

type IDService interface {
	Boot()
	Metadata() map[string]string
	// New tries to create a new object ID using the configured ID type. The
	// returned error might be caused by timeouts reached during the ID creation.
	New() (string, error)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	// WithType tries to create a new object ID using the given ID type. The
	// returned error might be caused by timeouts reached during the ID creation.
	WithType(idType int) (string, error)
}

IDService creates pseudo random hash generation used for ID assignment.

type InputCollection

type InputCollection interface {
	Boot()
	SetTextService(textService InputService)
	Text() InputService
}

InputCollection represents a collection of input services. This scopes different input service implementations in a simple container, which can easily be passed around.

type InputService

type InputService interface {
	Boot()
	Channel() chan objectspec.TextInput
	Metadata() map[string]string
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

InputService provides a communication channel for information sequences.

type InstrumentorService

type InstrumentorService interface {
	Boot()
	// ExecFunc wraps basic instrumentation around the given action and executes
	// it.
	//
	// The wrapped action causes the following metric's to be emitted. <prefix>
	// is described by the configured prefix of the current instrumentor.
	//
	//     <prefix>_<key>_durations_histogram_milliseconds
	//
	//         Holds the action's duration in milliseconds. This metric is
	//         emitted for each executed action.
	//
	//     <prefix>_<key>_errors_total
	//
	//         Holds the action's error count. This metric is emitted for each
	//         error returned by the given action.
	//
	ExecFunc(key string, action func() error) error
	// GetCounter provides a Counter for the given key. In case there does no
	// counter exist for the given key, one is created.
	GetCounter(key string) (objectspec.InstrumentorCounter, error)
	// GetGauge provides a Gauge for the given key. In case there does no
	// counter exist for the given key, one is created.
	GetGauge(key string) (objectspec.InstrumentorGauge, error)
	// GetGauge provides a Gauge for the given key. In case there does no
	// counter exist for the given key, one is created.
	GetHistogram(key string) (objectspec.InstrumentorHistogram, error)
	// GetHTTPEndpoint returns the instrumentor's metric endpoint supposed to
	// be registered in the HTTP server using the instrumentor's HTTP handler.
	GetHTTPEndpoint() string
	// GetHTTPHandler returns the instrumentor's HTTP handler supposed to be
	// registered in the HTTP server using the instrumentor's HTTP endpoint.
	GetHTTPHandler() http.Handler
	// GetPrefixes returns the instrumentor's configured prefix.
	GetPrefixes() []string
	Metadata() map[string]string
	// NewKey returns a new metrics key having all configured prefixes and all
	// given parts properly joined. This could happen e.g. using underscores. In
	// this case it would look as follows.
	//
	//     prefix_prefix_s_s_s_s
	//
	NewKey(s ...string) string
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	// WrapFunc wraps basic instrumentation around the given action. The returned
	// function can be used as e.g. retry action.
	//
	// The wrapped action causes the same metric's to be emitted as WrapFunc.
	WrapFunc(key string, action func() error) func() error
}

InstrumentorService represents an abstraction of instrumentation libraries to manage application metrics.

type LayerCollection

type LayerCollection interface {
	Boot()
	Behaviour() LayerService
	Information() LayerService
	Position() LayerService
	SetBehaviourService(behaviourService LayerService)
	SetInformationService(informationService LayerService)
	SetPositionService(positionService LayerService)
}

LayerCollection represents a collection of layer services. This scopes different layer service implementations in a simple container, which can easily be passed around.

type LayerService

type LayerService interface {
	Boot()
	// CreatePeer creates the peer of the current layer using the given peer
	// argument. CreatePeer also creates the position peer for the actual peer
	// being created and connects both.
	CreatePeer(peer string) (string, error)
	// DeletePeer deletes the peer of the current layer using the given peer
	// argument. DeletePeer also deletes the position peer for the actual peer
	// being deleted and disconnects both.
	DeletePeer(peer string) (string, error)
	Kind() string
	Metadata() map[string]string
	PeerPosition(peer string) (string, error)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

LayerService provides business logic to manage peers inside network layers. There are three different kinds of layer service implementations in use. Each implementation takes care about peers within the layer of its own responsibility. Connections across layers can be managed using the plain usage of the connection service (see ConnectionService).

behaviour

    The behaviour layer service manages peers of the behaviour layer of
    the connection space. Subject of this layer are peers associated with
    behaviours. Note that behaviour is implemented in form of CLG
    services (see CLGService).

information

    The information layer service manages peers of the information layer
    of the connection space. Subject of this layer are peers associated
    with information. Note that information are provided in form of
    input, which is received via input services (see InputService).

position

    The position layer service manages peers of the position layer of the
    connection space. Subject of this layer are peers representing the
    position of behaviour and information peers.

type LogService

type LogService interface {
	Boot()
	// Line logs a message based on the provided key-value pairs.
	Line(v ...interface{})
	Metadata() map[string]string
	Service() ServiceCollection
	SetRootLogger(rootLogger RootLogger)
	SetServiceCollection(serviceCollection ServiceCollection)
}

LogService represents a log service used to print log messages.

type NetworkService

type NetworkService interface {
	// Activate decides if a requested CLG shall be activated. It needs to be
	// decided if the requested CLG shall be activated. In case the requested CLG
	// shall be activated it needs to be decided how this activation shall happen.
	// For more information on the activation process see
	// ActivatorService.Activate. This is how it might look like when a CLG is
	// requested and multiple CLGs forward signals to it.
	//
	//     |-----|     |-----|     |-----|     |-----|     |-----|
	//     | CLG |     | CLG |     | CLG |     | CLG |     | CLG |
	//     |-----|     |-----|     |-----|     |-----|     |-----|
	//        |           |           |           |           |
	//        V           V           V           V           V
	//        -------------------------------------------------
	//                                |
	//                                V
	//                             |-----|
	//                             | CLG |
	//                             |-----|
	//
	Activate(clgService CLGService, networkPayload objectspec.NetworkPayload) (objectspec.NetworkPayload, error)
	// Boot initializes and starts the whole network like booting a machine. The
	// call to Boot blocks until the network is completely initialized, so you
	// might want to call it in a separate goroutine.
	//
	// Boot makes the network listen on requests from the outside. Here each
	// CLG input channel is managed. This way Listen acts as kind of cortex in
	// which signals are dispatched into all possible direction and finally flow
	// back again. Errors during processing of the neural network will be logged
	// to the provided logger.
	Boot()
	// Calculate executes the activated CLG and invokes its actual implemented
	// behaviour. This behaviour can be anything. It is up to the CLG what it
	// does with the provided NetworkPayload.
	Calculate(clgService CLGService, networkPayload objectspec.NetworkPayload) (objectspec.NetworkPayload, error)
	// EventListener is a worker pool function which is executed multiple times
	// concurrently to listen for network events. A network event is qualified by
	// a network payload being queued and waiting to be processed. A network event
	// and its processing represents an event associated with a very specific CLG.
	// Thus EventListener represents the entrypoint for every single CLG execution
	// step. canceler is provided by the worker pool that executes EventListener.
	// Therefore EventListener should respect canceler by implementing a clean
	// shutdown behaviour. EventListener calls EventHandler.
	EventListener(canceler <-chan struct{}) error
	// EventHandler effectively executes a network event associated to a CLG and
	// the corresponding network payload. EventHandler is called by EventListener.
	EventHandler(clgService CLGService, networkPayload objectspec.NetworkPayload) error
	// Forward is triggered after the CLGs calculation. Here will be decided what
	// to do next. Like Activate, it is up to the CLG if it forwards signals to
	// further CLGs. E.g. a CLG may or may not forward its calculated results to
	// one or more CLGs. All this depends on the information provided by the given
	// network payload, the CLG's connections and its therefore resulting
	// behaviour properties. This is how it might look like when one CLG forwards
	// signals to multiple other CLGs.
	//
	//                             |-----|
	//                             | CLG |
	//                             |-----|
	//                                |
	//                                V
	//        -------------------------------------------------
	//        |           |           |           |           |
	//        V           V           V           V           V
	//     |-----|     |-----|     |-----|     |-----|     |-----|
	//     | CLG |     | CLG |     | CLG |     | CLG |     | CLG |
	//     |-----|     |-----|     |-----|     |-----|     |-----|
	//
	Forward(clgService CLGService, networkPayload objectspec.NetworkPayload) error
	// InputListener is a worker pool function which is executed multiple times
	// concurrently to listen for network inputs. A network input is qualified by
	// information sequences sent by clients who request some calculation from the
	// network. InputListener also calls InputHandler.
	InputListener(canceler <-chan struct{}) error
	// InputHandler effectively executes the network input by invoking the input
	// CLG using the incoming text request. InputHandler is called by
	// InputListener.
	InputHandler(clgService CLGService, textInput objectspec.TextInput) error
	// Shutdown ends all processes of the network like shutting down a machine.
	// The call to Shutdown blocks until the network is completely shut down, so
	// you might want to call it in a separate goroutine.
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	Shutdown()
	// Track tracks connections being created to learn from connection path
	// patterns. Various data structures are stored to observe the behaviour of
	// the neural network to act accordingly.
	Track(clgService CLGService, networkPayload objectspec.NetworkPayload) error
}

NetworkService provides a neural network based on dynamic and self improving CLG execution. The network provides input and output channels. When input is received it is injected into the neural communication. The following neural activity calculates outputs which are streamed through the output channel back to the requestor.

type OutputCollection

type OutputCollection interface {
	Boot()
	SetTextService(textService OutputService)
	Text() OutputService
}

OutputCollection represents a collection of output services. This scopes different output service implementations in a simple container, which can easily be passed around.

type OutputService

type OutputService interface {
	Boot()
	Channel() chan objectspec.TextOutput
	Metadata() map[string]string
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

OutputService provides a communication channel to send information sequences.

type PeerService

type PeerService interface {
	Boot()
	// Create creates a new peer for the given peer value.
	Create(peer string) error
	// Delete deletes the peer identified by the given peer value.
	Delete(peer string) error
	Metadata() map[string]string
	// Search returns all metadata associated with the peer identified by the
	// given peer value.
	Search(peer string) (map[string]string, error)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	Shutdown()
}

PeerService implemnents a service to manage peers within the connection space.

Following is a list of properties each peer has applied in form of metadata to itself.

created

type PermutationService

type PermutationService interface {
	Boot()
	Metadata() map[string]string
	// PermuteBy permutes the configured values by applying the given delta to
	// the currently configured indizes. Error might indicate that the configured
	// max growth is reached. It processes the essentiaal operation of permuting
	// the list's indizes using the given delta. Indizes are capped by the
	// amount of configured values. E.g. having a list of two values configured
	// will increment the indizes in a base 2 number system.
	//
	//     Imagine the following values being configured.
	//
	//         []interface{"a", "b"}
	//
	//     Here the index 0 translates to indizes []int{0} and causes the
	//     following permutation on the raw values.
	//
	//         []interface{"a"}
	//
	//     Here the index 1 translates to indizes []int{1} and causes the
	//     following permutation on the raw values.
	//
	//         []interface{"b"}
	//
	//     Here the index 00 translates to indizes []int{0, 0} and causes the
	//     following permutation on the raw values.
	//
	//         []interface{"a", "a"}
	//
	PermuteBy(list objectspec.PermutationList, delta int) error
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

PermutationService creates permutations of arbitrary lists as configured.

type PositionService

type PositionService interface {
	Boot()
	Default() (string, error)
	Metadata() map[string]string
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

PositionService implemnents a service to manage position peers within the connection space.

type RandomService

type RandomService interface {
	Boot()
	// CreateMax tries to create one new pseudo random number. The generated
	// number is within the range [0 max), which means that max is exclusive.
	CreateMax(max int) (int, error)
	// CreateNMax tries to create a list of new pseudo random numbers. n
	// represents the number of pseudo random numbers in the returned list. The
	// generated numbers are within the range [0 max), which means that max is
	// exclusive.
	CreateNMax(n, max int) ([]int, error)
	Metadata() map[string]string
	Service() ServiceCollection
	SetBackoffFactory(backoffFactory func() objectspec.Backoff)
	SetRandFactory(randFactory func(randReader io.Reader, max *big.Int) (n *big.Int, err error))
	SetServiceCollection(serviceCollection ServiceCollection)
	SetTimeout(timeout time.Duration)
}

RandomService creates pseudo random numbers. The service might implement retries using backoff strategies and timeouts.

type RootLogger

type RootLogger interface {
	Log(v ...interface{}) error
}

RootLogger is the underlying logger actually printing log messages.

type ScanConfig

type ScanConfig struct {
	// MaxLength represents the length maximum of a sequence detected as feature.
	// E.g. MaxLength set to 3 results in sequences having a length not larger
	// than 3 when detected as features. The value -1 disables any limitiation.
	MaxLength int
	// MinLength represents the minimum length of a sequence detected as feature.
	// E.g. MinLength set to 3 results in sequences having a length not smaller
	// than 3 when detected as features. The value -1 disables any limitiation.
	MinLength int
	// MinCount represents the number of occurrences at least required to be
	// detected as feature. E.g. MinCount set to 3 requires a feature to be
	// present within a given input sequence at least 3 times.
	MinCount int
	// Separator represents the separator used to split sequences into smaller
	// parts. By default this is an empty string resulting in a character split.
	// This can be set to a whitespace to split for words. Note that the concept
	// of words is a feature known to humans based on contextual information
	// humans connected to create reasonable sences. This needs to be achieved by
	// Anna herself. So later this separator needs to be configured by Anna once
	// she is able to recognize improvements in feature detection, resulting in
	// even more awareness of contextual information.
	Separator string
	// Sequences represents the input sequences being analysed. Out of this
	// information features are detected, if any.
	Sequences []string
}

TODO provide interface and move implementation to feature service and remove error.go ScanConfig represents the configuration used to scan for new feature objects.

func (*ScanConfig) Validate

func (sc *ScanConfig) Validate() error

Validate checks whether ScanConfig is valid for proper execution in Feature.Scan.

type ServiceCollection

type ServiceCollection interface {
	Activator() ActivatorService
	Boot()
	Connection() ConnectionService
	Endpoint() EndpointCollection
	Feature() FeatureService
	Forwarder() ForwarderService
	// FSService returns a file system service. It is used to operate on file
	// system abstractions of a certain type.
	FS() FSService
	// IDService returns an ID service. It is used to create IDs of a certain
	// type.
	ID() IDService
	Input() InputCollection
	Instrumentor() InstrumentorService
	Layer() LayerCollection
	// Log returns a log service. It is used to print log messages.
	Log() LogService
	Network() NetworkService
	Output() OutputCollection
	Peer() PeerService
	// Permutation returns a permutation service. It is used to permute instances
	// of type PermutationList.
	Permutation() PermutationService
	Position() PositionService
	// Random returns a random service. It is used to create random numbers.
	Random() RandomService
	SetActivatorService(activatorService ActivatorService)
	SetConnectionService(connectionService ConnectionService)
	SetEndpointCollection(endpointCollection EndpointCollection)
	SetFeatureService(featureService FeatureService)
	SetForwarderService(forwarderService ForwarderService)
	SetFSService(fsService FSService)
	SetIDService(idService IDService)
	SetInputCollection(inputCollection InputCollection)
	SetInstrumentorService(instrumentorService InstrumentorService)
	SetLayerCollection(layerCollection LayerCollection)
	SetLogService(logService LogService)
	SetNetworkService(networkService NetworkService)
	SetOutputCollection(outputCollection OutputCollection)
	SetPeerService(peerService PeerService)
	SetPermutationService(permutationService PermutationService)
	SetPositionService(positionService PositionService)
	SetRandomService(randomService RandomService)
	SetStorageCollection(storageCollection StorageCollection)
	SetTrackerService(trackerService TrackerService)
	SetWorkerService(workerService WorkerService)
	// Shutdown ends all processes of the service collection like shutting down a
	// machine. The call to Shutdown blocks until the service collection is
	// completely shut down, so you might want to call it in a separate goroutine.
	Shutdown()
	Storage() StorageCollection
	Tracker() TrackerService
	Worker() WorkerService
}

ServiceCollection represents a collection of services. This scopes different service implementations in a simple container, which can easily be passed around.

type StorageCollection

type StorageCollection interface {
	Boot()
	Connection() StorageService
	// Feature represents a feature storage. It is used to store features of
	// information sequences separately. Because of the used key structures and
	// scanning algorithms the feature storage must only be used to store data
	// serving the same conceptual purpose. For instance random features can be
	// retrieved more efficiently when there are only keys belonging to features.
	// Other data structures in here would make the scanning algorithms less
	// efficient.
	//
	// TODO rename to information service???
	Feature() StorageService

	// General represents a general storage. It is used to store general data
	// which is not stored in specialized storage instances.
	General() StorageService
	Peer() StorageService
	SetConnectionService(connectionService StorageService)
	SetFeatureService(featureService StorageService)
	SetGeneralService(generalService StorageService)
	SetPeerService(peerService StorageService)
	// Shutdown ends all processes of the storage collection like shutting down a
	// machine. The call to Shutdown blocks until the storage collection is
	// completely shut down, so you might want to call it in a separate goroutine.
	Shutdown()
}

StorageCollection represents a collection of storage services. This scopes different storage service implementations in a simple container, which can easily be passed around.

type StorageService

type StorageService interface {

	// PopFromList returns the next element from the list identified by the given
	// key. Note that a list is an ordered sequence of arbitrary elements.
	// PushToList and PopFromList are operating according to a "first in, first
	// out" primitive. If the requested list is empty, PopFromList blocks
	// infinitely until an element is added to the list. Returned elements will
	// also be removed from the specified list.
	PopFromList(key string) (string, error)
	// PushToList adds the given element to the list identified by the given key.
	// Note that a list is an ordered sequence of arbitrary elements. PushToList
	// and PopFromList are operating according to a "first in, first out"
	// primitive.
	PushToList(key string, element string) error

	// GetElementsByScore looks up all elements associated with the given score.
	// To limit the number of returned elements, maxElements ca be used. Note
	// that the list has this scheme.
	//
	//     element1,element2,...
	//
	GetElementsByScore(key string, score float64, maxElements int) ([]string, error)
	// GetHighestScoredElements searches a list that is ordered by their
	// element's score, and returns the elements and their corresponding scores,
	// where the highest scored element is the first in the returned list. Note
	// that the list has this scheme.
	//
	//     element1,score1,element2,score2,...
	//
	// Note that the resulting list will have the length of maxElements*2,
	// because the list contains the elements and their scores.
	//
	GetHighestScoredElements(key string, maxElements int) ([]string, error)
	// RemoveScoredElement removes the given element from the scored set under
	// key.
	RemoveScoredElement(key string, element string) error
	// SetElementByScore persists the given element in the weighted list
	// identified by key with respect to the given score.
	SetElementByScore(key, element string, score float64) error
	// WalkScoredSet scans the scored set given by key and executes the callback
	// for each found element. Note that the walk might ignores the score order.
	//
	// The walk is throttled. That means some amount of elements are fetched at
	// once from the storage. After all fetched elements are iterated, the next
	// batch of elements is fetched to continue the next iteration, until the
	// given set is walked completely. The given closer can be used to end the
	// walk immediately.
	WalkScoredSet(key string, closer <-chan struct{}, cb func(element string, score float64) error) error

	// GetAllFromSet returns all elements from the stored set under key.
	GetAllFromSet(key string) ([]string, error)
	// PushToSet adds the given element to the set identified by the given key.
	// Note that a set is an unordered collection of distinct elements.
	PushToSet(key string, element string) error
	// RemoveFromSet removes the given element from the set identified by the
	// given key.
	RemoveFromSet(key string, element string) error
	// WalkSet scans the set given by key and executes the callback for each found
	// element.
	//
	// The walk is throttled. That means some amount of elements are fetched at
	// once from the storage. After all fetched elements are iterated, the next
	// batch of elements is fetched to continue the next iteration, until the
	// given set is walked completely. The given closer can be used to end the
	// walk immediately.
	WalkSet(key string, closer <-chan struct{}, cb func(element string) error) error

	// GetStringMap returns the hash map stored under the given key.
	GetStringMap(key string) (map[string]string, error)
	// SetStringMap stores the given stringMap under the given key.
	SetStringMap(key string, stringMap map[string]string) error

	// Get returns data associated with key. This is a simple key-value
	// relationship.
	Get(key string) (string, error)
	// GetRandom returns a random key which was formerly stored within the
	// underlying storage.
	GetRandom() (string, error)
	// Remove deletes the given key.
	Remove(key string) error
	// Set stores the given key value pair. Once persisted, value can be
	// retrieved using Get.
	Set(key string, value string) error
	// WalkKeys scans the key space with respect to the given glob and executes
	// the callback for each found key.
	//
	// The walk is throttled. That means some amount of keys are fetched at once
	// from the storage. After all fetched keys are iterated, the next batch of
	// keys is fetched to continue the next iteration, until the whole key space
	// is walked completely. The given closer can be used to end the walk
	// immediately.
	WalkKeys(glob string, closer <-chan struct{}, cb func(key string) error) error

	Boot()
	SetBackoffFactory(backoffFactory func() objectspec.Backoff)
	SetPool(pool *redis.Pool)
	SetPrefix(prefix string)
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	// Shutdown ends all processes of the storage like shutting down a machine.
	// The call to Shutdown blocks until the storage is completely shut down, so
	// you might want to call it in a separate goroutine.
	Shutdown()
}

StorageService represents a persistency management object. Different storages may be provided in a StorageCollection. Within a receiver function the usage of the feature storage may look like this.

func (s *service) Foo() error {
  rk, err := s.Storage().Feature().GetRandom()
  ...
}

type TrackerService

type TrackerService interface {
	Boot()
	// CLGIDs is a lookup function used by Track. It persists the single
	// connections between the destination and sources provided by networkPayload
	// in the underlying storage.
	CLGIDs(clgService CLGService, networkPayload objectspec.NetworkPayload) error
	// CLGNames is a lookup function used by Track. It resolves the CLG names of
	// the destination and sources provided by networkPayload and persists the
	// single connections between them in the underlying storage.
	CLGNames(clgService CLGService, networkPayload objectspec.NetworkPayload) error
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
	// Track tracks connection path patterns.
	Track(clgService CLGService, networkPayload objectspec.NetworkPayload) error
}

TrackerService represents a management object to track connection path patterns.

type WorkerService

type WorkerService interface {
	Boot()
	// Execute processes all configured actions concurrently. The call to Execute
	// blocks until all goroutines within the worker pool have finished their
	// work.
	Execute(config objectspec.WorkerExecuteConfig) error
	// ExecuteConfig provides a default configuration for Execute.
	ExecuteConfig() objectspec.WorkerExecuteConfig
	Metadata() map[string]string
	Service() ServiceCollection
	SetServiceCollection(serviceCollection ServiceCollection)
}

WorkerService implements a service to process work concurrently.

Jump to

Keyboard shortcuts

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