run

package
v1.0.1-3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2022 License: MIT Imports: 8 Imported by: 23

Documentation

Index

Constants

View Source
const DefaultCancellationSignal int8 = 1

Variables

View Source
var Cleaner = &_TCleaner{}

Cleaner helper class that cleans stored object state.

View Source
var Closer = &_TCloser{}

Closer helper class that closes previously opened components.

View Source
var Executor = &_TExecutor{}

Executor Helper class that executes components.

View Source
var Notifier = &_TNotifier{}

Notifier helper class that notifies components.

View Source
var Opener = &_TOpener{}

Opener Helper class that opens components.

Functions

func CancelContextFeedback

func CancelContextFeedback(ctx context.Context) bool

CancelContextFeedback sends interrupt signal up to the context owner

Parameters: context.Context is a current context
Returns: bool true if signal sends successful or false

func CancelContextFeedbackWithData

func CancelContextFeedbackWithData[T any](ctx context.Context, data T) bool

CancelContextFeedbackWithData sends custom data and interrupt signal up to the context owner

Parameters:
	- context.Context is a current context
	- T custom data
Returns: bool true if signal sends successful or false

func CancelContextFeedbackWithError

func CancelContextFeedbackWithError(ctx context.Context, err error) bool

CancelContextFeedbackWithError sends error and interrupt signal up to the context owner

Parameters:
	- context.Context is a current context
	- error
Returns: bool true if signal sends successful or false

func NewCancelContext

func NewCancelContext(ctx context.Context, contextFeedbackChan ContextFeedbackChan) (context.Context, bool)

NewCancelContext wrap context with ContextFeedbackChan

see context.WithValue
Parameters:
	- context.Context parent context
	- ContextFeedbackChan channel to put into context
Returns:
	- context.Context is a context with value
	- bool true if channel is not nil or false

func NewCancelContextWithCustomDataChannel

func NewCancelContextWithCustomDataChannel[T any](ctx context.Context, contextFeedbackChan ContextFeedbackChanWithCustomData[T]) (context.Context, bool)

NewCancelContextWithCustomDataChannel wrap context with ContextFeedbackChanWithCustomData

T is a custom data type
see context.WithValue
Parameters:
	- context.Context - parent context
	- ContextFeedbackChanWithCustomData - channel to put into context
Returns:
	- context.Context is a context with value
	- bool true if channel is not nil or false

func NewCancelContextWithError

func NewCancelContextWithError(ctx context.Context, contextFeedbackChan ContextFeedbackChanWithError) (context.Context, bool)

NewCancelContextWithError wrap context with ContextFeedbackChanWithError

see context.WithValue
Parameters:
	- context.Context - parent context
	- ContextFeedbackChanWithError - channel to put into context
Returns:
	- context.Context is a context with value
	- bool true if channel is not nil or false

Types

type ContextFeedbackChan

type ContextFeedbackChan chan int8

ContextFeedbackChan a channel to send default context feedback

type ContextFeedbackChanWithCustomData

type ContextFeedbackChanWithCustomData[T any] chan T

ContextFeedbackChanWithCustomData a channel to send context feedback with specific data.

type ContextFeedbackChanWithError

type ContextFeedbackChanWithError chan error

ContextFeedbackChanWithError a channel to send context feedback with error

type ContextValueType

type ContextValueType string

ContextValueType an enum to describe specific context feedback channel

Possible values:
	- ContextFeedbackChanType
	- ContextFeedbackChanWithErrorType
	- ContextFeedbackChanWithCustomDataType
const (
	ContextFeedbackChanType               ContextValueType = "pip.ContextFeedbackChan"
	ContextFeedbackChanWithErrorType      ContextValueType = "pip.ContextFeedbackChanWithError"
	ContextFeedbackChanWithCustomDataType ContextValueType = "pip.ContextFeedbackChanWithCustomData"
)

type FixedRateTimer

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

FixedRateTimer timer that is triggered in equal time intervals. It has summetric cross-language implementation and is often used by Pip.Services toolkit to perform periodic processing and cleanup in microservices.

see INotifiable
Example:
	type MyComponent {
		timer FixedRateTimer
	}
	...
	func (mc* MyComponent) Open(ctx, context.Context, correlationId string) {
		...
		mc.timer = NewFixedRateTimerFromCallback(func(ctx context.Context){ this.cleanup }, 60000, 0, 5);
		mc.timer.Start(ctx);
		...
	}
	func (mc* MyComponent) Close(ctx, context.Context, correlationId: string){
		...
		mc.timer.Stop(ctx);
		...
	}

func NewFixedRateTimer

func NewFixedRateTimer() *FixedRateTimer

NewFixedRateTimer creates new instance of the timer and sets its values.

Returns: *FixedRateTimer

func NewFixedRateTimerFromCallback

func NewFixedRateTimerFromCallback(callback func(ctx context.Context),
	interval int, delay int, workerCount int) *FixedRateTimer

NewFixedRateTimerFromCallback creates new instance of the timer and sets its values.

Parameters:
	- callback func() callback function to call when timer is triggered.
	- interval int an interval to trigger timer in milliseconds.
	- delay int a delay before the first triggering in milliseconds.
	- workerCount int a count of parallel running workers.
Returns: *FixedRateTimer

func NewFixedRateTimerFromTask

func NewFixedRateTimerFromTask(task INotifiable,
	interval int, delay int, workerCount int) *FixedRateTimer

NewFixedRateTimerFromTask creates new instance of the timer and sets its values.

Parameters:
	- callback INotifiable Notifiable object to call when timer is triggered.
	- interval int an interval to trigger timer in milliseconds.
	- delay int a delay before the first triggering in milliseconds.
	- workerCount int a count of parallel running workers.
Returns: *FixedRateTimer

func (*FixedRateTimer) Callback

func (c *FixedRateTimer) Callback() func(ctx context.Context)

Callback gets the callback function that is called when this timer is triggered.

Returns: function the callback function or null if it is not set.

func (*FixedRateTimer) Close

func (c *FixedRateTimer) Close(ctx context.Context, correlationId string) error

Close closes the timer. This is required by ICloseable interface, but besides that it is identical to stop().

Parameters: correlationId: string transaction id to trace execution through call chain.
Returns: error

func (*FixedRateTimer) Delay

func (c *FixedRateTimer) Delay() int

Delay gets initial delay before the timer is triggered for the first time.

Returns: number the delay in milliseconds.

func (*FixedRateTimer) Interval

func (c *FixedRateTimer) Interval() int

Interval gets periodic timer triggering interval.

Returns: number the interval in milliseconds

func (*FixedRateTimer) IsStarted

func (c *FixedRateTimer) IsStarted() bool

IsStarted checks if the timer is started.

Returns: bool true if the timer is started and false if it is stopped.

func (*FixedRateTimer) SetCallback

func (c *FixedRateTimer) SetCallback(value func(ctx context.Context))

SetCallback sets the callback function that is called when this timer is triggered.

Parameters: value func() the callback function to be called.

func (*FixedRateTimer) SetDelay

func (c *FixedRateTimer) SetDelay(value int)

SetDelay sets initial delay before the timer is triggered for the first time.

Parameters: value int a delay in milliseconds.

func (*FixedRateTimer) SetInterval

func (c *FixedRateTimer) SetInterval(value int)

SetInterval sets periodic timer triggering interval.

Parameters: value int an interval in milliseconds.

func (*FixedRateTimer) SetTask

func (c *FixedRateTimer) SetTask(value INotifiable)

SetTask sets a new INotifiable object to receive notifications from this timer.

Parameters: value INotifiable a INotifiable object to be triggered.

func (*FixedRateTimer) SetWorkerCount

func (c *FixedRateTimer) SetWorkerCount(workerCount int)

SetWorkerCount sets a new worker count.

Parameters: workerCount int.

func (*FixedRateTimer) Start

func (c *FixedRateTimer) Start(ctx context.Context)

Start starts the timer. Initially the timer is triggered after delay. After that it is triggered after interval until it is stopped.

func (*FixedRateTimer) Stop

func (c *FixedRateTimer) Stop(ctx context.Context)

Stop the timer.

func (*FixedRateTimer) Task

func (c *FixedRateTimer) Task() INotifiable

Task gets the INotifiable object that receives notifications from this timer.

Returns: INotifiable the INotifiable object or null if it is not set.

func (*FixedRateTimer) WorkerCount

func (c *FixedRateTimer) WorkerCount() int

WorkerCount gets the worker count.

Returns: int worker count.

type ICleanable

type ICleanable interface {
	// Clear clears component state.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId string
	//  transaction id to trace execution through call chain.
	Clear(ctx context.Context, correlationId string) error
}

ICleanable Interface for components that should clean their state. Cleaning state most often is used during testing. But there may be situations when it can be done in production.

see Cleaner
Example:
	type MyObjectWithState {
		_state any
	}
	...
	func (mo *MyObjectWithState) clear(ctx context.Context, correlationId string) {
		mo._state = any
	}

type IClosable

type IClosable interface {
	Close(ctx context.Context, correlationId string) error
}

IClosable interface for components that require explicit closure. For components that require opening as well as closing use IOpenable interface instead.

see IOpenable
see Closer
Example:
	type MyConnector {
		_client interface{}
	}
	... // The _client can be lazy created
	func (mc *MyConnector) Close(correlationId: string):error {
		if (mc._client != nil) {
			mc._client.Close()
			mc._client = nil
			return nil
		}
	}

type IExecutable

type IExecutable interface {
	// Execute component with arguments and receives execution result.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId string transaction id to trace execution through call chain.
	//		- args *Parameters execution arguments.
	//	Returns: any, error result or execution and error
	Execute(ctx context.Context, correlationId string, args *Parameters) (result any, err error)
}

IExecutable interface for components that can be called to execute work.

Example:
	type EchoComponent {}
	...
	func  (ec* EchoComponent) Execute(correlationId: string, args: Parameters) (result any, err error) {
		return nil, result = args.getAsObject("message")
	}
	echo := EchoComponent{};
	message = "Test";
	res, err = echo.Execute("123", NewParametersFromTuples("message", message));
	fmt.Println(res);

type INotifiable

type INotifiable interface {
	// Notify notifies the component about occured event.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId string transaction id to trace execution through call chain.
	//		- args *Parameters notification arguments.
	Notify(ctx context.Context, correlationId string, args *Parameters)
}

INotifiable interface for components that can be asynchronously notified. The notification may include optional argument that describe the occurred event.

see Notifier
see IExecutable
Example:
	type MyComponent {}
	...
	func (mc *MyComponent)Notify(correlationId: string, args: Parameters){
		fmt.Println("Occured event " + args.GetAsString("event"));
	}
	myComponent := MyComponent{};
	myComponent.Notify("123", NewParametersFromTuples("event", "Test Event"));

type IOpenable

type IOpenable interface {
	IClosable

	// IsOpen Checks if the component is opened.
	//	Returns: bool true if the component has been opened and false otherwise.
	IsOpen() bool

	// Open opens the component.
	//	Parameters:
	//		- ctx context.Context
	//		- correlationId: string transaction id to trace execution through call chain.
	//	Return: error
	Open(ctx context.Context, correlationId string) error
}

IOpenable interface for components that require explicit opening and closing. For components that perform opening on demand consider using ICloseable interface instead.

see IOpenable
see Opener
Example:
	type MyPersistence {
		_client any
	}
	func (mp* MyPersistence)IsOpen() bool {
		return mp._client != nil;
	}
	func (mp* MyPersistence) Open(correlationId: string) error {
		if (mp.isOpen()) {
			return nil;
		}
	}
	func (mp* MyPersistence) Close(correlationId: string) {
		if (mp._client != nil) {
			mp._client.close();
			mp._client = nil;
		}
	}

type IParameterized

type IParameterized interface {
	// SetParameters sets execution parameters.
	//	Parameters:
	//		- ctx context.Context
	//		- parameters *Parameters execution parameters.
	SetParameters(ctx context.Context, parameters *Parameters)
}

IParameterized interface for components that require execution parameters.

type Parameters

type Parameters struct {
	data.AnyValueMap
}

Parameters contains map with execution parameters. In general, this map may contain non-serializable values. And in contrast with other maps, its getters and setters support dot notation and able to access properties in the entire object graph. This class is often use to pass execution and notification arguments, and parameterize classes before execution.

func NewEmptyParameters

func NewEmptyParameters() *Parameters

NewEmptyParameters creates a new instance of the map and assigns its value. Returns: *Parameters

func NewParameters

func NewParameters(values map[string]any) *Parameters

NewParameters creates a new instance of the map and assigns its value.

Parameters: values map[string]any
Returns: *Parameters

func NewParametersFromConfig

func NewParametersFromConfig(config *config.ConfigParams) *Parameters

NewParametersFromConfig creates new Parameters from ConfigMap object.

see ConfigParams
Parameters: config: *config.ConfigParams a ConfigParams that contain parameters.
Returns: Parameters a new Parameters object.

func NewParametersFromMaps

func NewParametersFromMaps(maps ...map[string]any) *Parameters

NewParametersFromMaps creates a new Parameters by merging two or more maps. Maps defined later in the list override values from previously defined maps.

Parameters: maps ...map[string]any an array of maps to be merged
Returns: *Parameters a newly created Parameters.

func NewParametersFromTuples

func NewParametersFromTuples(tuples ...any) *Parameters

NewParametersFromTuples creates a new Parameters object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs.

see NewParametersFromTuplesArray
Parameters: tuples ...any the tuples to fill a new Parameters object.
Returns: *Parameters a new Parameters object.

func NewParametersFromTuplesArray

func NewParametersFromTuplesArray(tuples []any) *Parameters

NewParametersFromTuplesArray creates a new AnyValueMap from a list of key-value pairs called tuples. The method is similar to fromTuples but tuples are passed as array instead of parameters.

Parameters: tuples []any a list of values where odd elements
	are keys and the following even elements are values
Returns: *Parameters a newly created Parameters.

func NewParametersFromValue

func NewParametersFromValue(value any) *Parameters

NewParametersFromValue creates a new Parameters object filled with key-value pairs from specified object.

Parameters: value any an object with key-value pairs used to initialize a new Parameters.
Returns: *Parameters a new Parameters object.

func (*Parameters) AssignTo

func (c *Parameters) AssignTo(value any)

AssignTo assigns (copies over) properties from the specified value to this map.

Parameters: value any value whose properties shall be copied over.

func (*Parameters) Clone

func (c *Parameters) Clone() any

Clone creates a binary clone of this object.

Returns: any a clone of this object.

func (*Parameters) Contains

func (c *Parameters) Contains(key string) bool

Contains checks if this map contains an element with specified key. The key can be defined using dot notation and allows to recursively access elements of elements.

Parameters: key string a key to be checked
Returns: bool true if this map contains the key or false otherwise.

func (*Parameters) Get

func (c *Parameters) Get(key string) (any, bool)

Get gets a map element specified by its key. The key can be defined using dot notation and allows to recursively access elements of elements.

Parameters:  key string a key of the element to get.
Returns any the value of the map element.

func (*Parameters) GetAsNullableParameters

func (c *Parameters) GetAsNullableParameters(key string) (*Parameters, bool)

GetAsNullableParameters converts map element into an Parameters or returns nil if conversion is not possible.

Parameters: key string a key of element to get.
Returns: *Parameters value of the element or nil if conversion is not supported.

func (*Parameters) GetAsParameters

func (c *Parameters) GetAsParameters(key string) *Parameters

GetAsParameters converts map element into a Parameters or returns empty Parameters if conversion is not possible.

Parameters: key string a key of element to get.
Returns: *Parameters value of the element or empty Parameters if conversion is not supported.

func (*Parameters) GetAsParametersWithDefault

func (c *Parameters) GetAsParametersWithDefault(key string, defaultValue *Parameters) *Parameters

GetAsParametersWithDefault converts map element into a Parameters or returns default value if conversion is not possible.

Parameters:
	- key string a key of element to get.
	- defaultValue *Parameters the default value
Returns: *Parameters value of the element or default value if conversion is not supported.

func (*Parameters) Omit

func (c *Parameters) Omit(paths ...string) *Parameters

Omit selected parameters from this Parameters and returns the rest as a new Parameters object.

Parameters: paths ...string keys to be omitted from copying over to new Parameters.
Returns: *Parameters a new Parameters object.

func (*Parameters) Override

func (c *Parameters) Override(parameters *Parameters, recursive bool) *Parameters

Override overrides parameters with new values from specified Parameters and returns a new Parameters object.

see SetDefaults
Parameters:
	- parameters: Parameters with parameters to override the current values.
	- recursive bool true to perform deep copy, and false for shallow copy. Default: false
Returns: *Parameters a new Parameters object.

func (*Parameters) Pick

func (c *Parameters) Pick(paths ...string) *Parameters

Pick picks select parameters from this Parameters and returns them as a new Parameters object.

Parameters: paths ...string keys to be picked and copied over to new Parameters.
Returns: *Parameters a new Parameters object.

func (*Parameters) Put

func (c *Parameters) Put(key string, value any)

Put puts a new value into map element specified by its key. The key can be defined using dot notation and allows to recursively access elements of elements.

Parameters:
	- key string a key of the element to put.
	- value any a new value for map element.

func (*Parameters) Remove

func (c *Parameters) Remove(key string)

Remove removes a map element specified by its key

Parameters: key string a key of the element to remove.

func (*Parameters) SetDefaults

func (c *Parameters) SetDefaults(defaultParameters *Parameters, recursive bool) *Parameters

SetDefaults set default values from specified Parameters and returns a new Parameters object.

see Override
Parameters:
	- defaultParameters *Parameters Parameters with default parameter values.
	- recursive bool true to perform deep copy, and false for shallow copy. Default: false
Returns: *Parameters a new Parameters object.

Jump to

Keyboard shortcuts

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