logic

package
v0.0.0-...-9fe2f5c Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: LGPL-3.0 Imports: 12 Imported by: 0

README

package logic // import "github.com/hellgate75/general_structures/logic"

FUNCTIONS

Work in progress

TYPES

Work in progress

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BUSINESSOBJECT_BUS_TIMEOUT time.Duration = 30 * time.Second
View Source
var CONSUMERS_MAX_WAITING_TIMEOUT time.Duration = 5 * time.Minute
View Source
var CONSUMERS_SUSPEND_TIMEOUT time.Duration = 10 * time.Second

Functions

func ConvertBusinessObject

func ConvertBusinessObject(o BusinessObject, itf interface{}) error

Convert a Bussiness Object into a provided structure, in case it is suitable for the logic.BusinessObject Parameters:

o (logic.BusinessObject) Reference Business Object
itf (interface{}) Pointer to structure

Returns:

error Any error that occurs during the computation or nil

func GetCallerFunction

func GetCallerFunction() runtime.Frame

Get Current Function Caller runtime.Frame Returns:

runtime.Frame Selected frame or deafult <function name: unknown> fake frame

func GetCallerFunctionBeforeCurrent

func GetCallerFunctionBeforeCurrent(framesBefore int) runtime.Frame

Get Current Function Caller runtime.Frame before provided back iterations, starting with 1 as caller Parameters:

framesBefore (int) Number of previous callers iterations to verify

Returns:

runtime.Frame Selected frame or deafult <function name: unknown> fake frame

func GetCurrentFunction

func GetCurrentFunction() runtime.Frame

Get Current Function runtime.Frame Returns:

runtime.Frame Selected frame or deafult <function name: unknown> fake frame

func InitLogger

func InitLogger()

Initialize package logger if not started

Types

type BOChannel

type BOChannel chan BusinessObject

Business Objects channel that is used to send/receive messages, data, instructions

type BusinessConsumer

type BusinessConsumer interface {
	// Method that retrieve consumer label for logging purposes
	// Returns:
	//    string Consumer descriptive label
	Label() string
	// Method that retrieve consumer unique Identifier
	// Returns:
	//    logic.UUID Unique Consumer Identifier
	Id() UUID
	// Method that accepts a Business Object
	// Parameters:
	//    bo (logic.BusinessObject) Object to be consumed
	// Returns:
	//    bool Acceptance state
	Accept(bo BusinessObject) bool
	// Retrieve state if a consumer is ready to accept B.O.s
	// Returns:
	//    bool Acceptance ready state
	IsReady() bool
}

Interface that describes receiver features

type BusinessObject

type BusinessObject interface {
	ExportableObject
	// Get the Map that describes the component fields/value
	// Returns:
	//    logic.ValueMap Map that contains business object field names and values
	GetValuesMap() ValuesMap
	// Get the Key array
	// Returns:
	//    logic.Keys Business object field name array
	GetKeys() Keys
	// Get the Business Object Type
	// Returns:
	//    reflect.Type Business object field type
	GetType() reflect.Type
	// Get the Number of Fields, saved into the Business Objetc
	// Returns:
	//    int Number of Fields
	Size() int
}

Componponent that describe data that can be sent / received to / from the Bus

func ConvertStructure

func ConvertStructure(itf interface{}) (BusinessObject, error)

Convert a structure to a Business Object (logic.BusinessObject) or for any other type will be saved in "Val" field Parameters:

itf (interface{}) Input component/structure

Returns:

(logic.BusinessObject Object containing the input fields or the 'Val' field in case of non strcuture input element,
 error Any error that occurs during the computation or nil)

func NewBusinessObject

func NewBusinessObject(boMap ValuesMap, boType reflect.Type) BusinessObject

Create a Business Object from elements (Business Obect Map and Type) Parameters:

boMap (logic.ValuesMap) Map of object fields (name, and value entries)
boType (reflect.Type) Type related to the original type

Returns:

logic.BusinessObject Outcome Business Object

type ESBTransactionElement

type ESBTransactionElement struct {
	Id             UUID
	Consumer       *BusinessConsumer
	BusinessObject *BusinessObject
	Nextelement    *ESBTransactionElement
}

Define Single Transaction Operation

type ESBTransactionInformationEntry

type ESBTransactionInformationEntry struct {
	EntryPoint ESBTransactionPoint
	NextEntry  *ESBTransactionInformationEntry
	Created    time.Time
	Updated    time.Time
	Paused     bool
	Errors     types.List
}

Information about Transaction and hierarchy

type ESBTransactionManager

type ESBTransactionManager interface {
	ExportableObject
	// Creates and starts a New Empty Transaction
	// Returns:
	//    logic.UUID New Transaction Id
	NewTransaction() UUID
	// Starts a paused Transaction by logic.UUID
	// Parameters:
	//    transactionId (logic.UUID) Existing or New Trasaction Id
	// Returns:
	//    error Any error that occurs during the computation or nil
	Start(transactionId UUID) error
	// Pauses a Transaction by logic.UUID, any cancellation/finalization activities will be denied
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    error Any error that occurs during the computation or nil
	Pause(transactionId UUID) error
	// Verify if a Transaction is started (if existing) by logic.UUID
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    bool Transaction running state or false if not exists
	IsStarted(transactionId UUID) bool
	// Verify if a Transaction exists by logic.UUID
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    bool Transaction existance state
	Exists(transactionId UUID) bool
	// Adds an element to a Transaction by logic.UUID
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	//    element (logic.ESBTransactionElement) Element to be added to the transaction as next step
	// Returns:
	//    (logic.UUID Transaction Working Point Save Unique Identifier,
	//     bool Transaction element insert state)
	AddElement(transactionId UUID, element ESBTransactionElement) (UUID, bool)
	// Save Working point of a Transaction by logic.UUID, it can resetted by Rollback command
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    (logic.UUID Transaction Working Point Save Unique Identifier,
	//     error Any error that occurs during the computation or nil)
	SavePoint(transactionId UUID) (UUID, error)
	// Remove all trasaction elements since last save point or since the beginning if no working point has been saved
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    error Any error that occurs during the computation or nil
	Rollback(transactionId UUID) error
	// Remove all trasaction elements since given save point logic.UUID or nothing if savepoint doesn't exist
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Identifier
	//    savePointId (logic.UUID) Saved Working Point Unique Identifier
	// Returns:
	//    error Any error that occurs during the computation or nil
	RollbackTo(transactionId UUID, savePointId UUID) error
	// Apply all transactions commands in all savepoints since the beginning, removing all transaction history, in case of success
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    error Any error that occurs during the computation or nil
	Commit(transactionId UUID) error
	// Removing all transaction history and any saved working points
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    error Any error that occurs during the computation or nil
	Delete(transactionId UUID) error
	// Retrive sequence of transaction information, and any saved working point
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    *logic.ESBTransactionInformationEntry Pointer to entry (root) Transaction Point
	GetInformation(transactionId UUID) *ESBTransactionInformationEntry
	// Retrive list of transaction history, and for any saved working point
	// Parameters:
	//    transactionId (logic.UUID) Existing Trasaction Id
	// Returns:
	//    types.List List conaining all history entries (logic.TransactionHistoryEntry)
	GetHistory(transactionId UUID) types.List
}

Describes behavior of Transaction Manager. This component manage and hold serveral Transactions and Save points, giving an easy access to transaction commands. It's used by the logic.ServiceBus to manage transaction according to implememtation policies.

func NewESBTransactionManager

func NewESBTransactionManager(bus ServiceBus) ESBTransactionManager

Create New Service Bus Transaction Manager Parameters:

bus (logic.ServiceBus) Service Bus instance

Returns:

logic.ESBTransactionManager Service Bus Transaction Manager instance

type ESBTransactionPoint

type ESBTransactionPoint struct {
	Id             UUID
	RootElement    *ESBTransactionElement
	CurrentElement *ESBTransactionElement
	NextPoint      *ESBTransactionPoint
	PreviousPoint  *ESBTransactionPoint
	// contains filtered or unexported fields
}

Defines transaction point, it is a save point into the transaction. It's used to maintain an order in the transaction execution sequence. It keep trace of entry logic.ESBTransactionElement and current one, holding information about next execution point.

type ExportableObject

type ExportableObject interface {
	// Export Data into the flow
	// Parameters:
	//    flows.Flow Input Stream
	// Returns:
	//    errors Any error that occurs during the computation or nil
	Export(f io.Writer) error
	// Import Data from the flow
	// Parameters:
	//    flows.Flow Output Stream
	// Returns:
	//    errors Any error that occurs during the computation or nil
	Import(f io.Reader) error
}

Describes a component that can be exported/imported to/from streams

type Keys

type Keys []string

Array that contains key list

type ServiceBus

type ServiceBus interface {
	// Offers a business object only at first available consumer
	// Parameters:
	//    bo (logic.BusinessObject) Object to be consumed
	// Retruns:
	//    error Any error that occurs during the computation or nil
	OfferFirst(bo BusinessObject) error
	// Offers first communication channel
	// Retruns:
	//    *BOChannel Pointer to Business Object Channel
	OfferFirstChannel() *BOChannel
	// Offers a business object to any available consumer, and retrieve to not available accordingly to consumer strategy implementation
	// Parameters:
	//    bo (logic.BusinessObject) Object to be consumed
	// Retruns:
	//    error Any error that occurs during the computation or nil
	Offer(bo BusinessObject) error
	// Offers all communication channel
	// Retruns:
	//    *BOChannel Pointer to Business Object Channel
	OfferChannel() *BOChannel
	// Register a new Consumer into the Service Bus
	// Parameters:
	//    consumer (logic.BusinessConsumer) Consumer to be registered
	// Retruns:
	//    bool Registration success state
	RegisterConsumer(consumer BusinessConsumer) bool
	// Remove an evistingConsumer from the Service Bus
	// Parameters:
	//    consumer (logic.BusinessConsumer) Consumer to be removed
	// Retruns:
	//    bool Removal success state
	RemoveConsumer(consumer BusinessConsumer) bool
	// Remove an evistingConsumer from the Service Bus
	// Parameters:
	//    id (UUID) Unique identifier of consumer to be removed
	// Retruns:
	//    bool Removal success state
	RemoveConsumerById(id UUID) bool
	// contains filtered or unexported methods
}

Describes Element that mask the connection with consumers and provides multiple consume strategies : Consumed by Only First, Consumed by All. Any Consumer can be registered on the Service Bus, and automatically will dispatch Business Object through first available or all consumers, when ready. Persistency strategy will depend on the Service Buss Implementation.

type TransactionHistoryEntry

type TransactionHistoryEntry struct {
	Id          UUID
	Date        time.Time
	Operation   TransactionOperation
	Description string
}

Transaction History item, containing information about events heppened on the Transaction life and his saved working points, retaining infomration about deleted elements or save points

type TransactionOperation

type TransactionOperation int

Operation type, describes informtion about events on Transactions

const (
	// Describe Transaction creation event
	CREATED TransactionOperation = iota + 1
	// Describe Transaction add element event
	ADD_ELEMENT
	// Describe Transaction remove element event
	REMOVE_ELEMENT
	// Describe Transaction paused event
	PAUSED
	// Describe Transaction resume paused event
	RESUMED
	// Describe Transaction savepoint event
	SAVEDPOINT
	// Describe Transaction rollback event
	ROLLBACKED
	// Describe Transaction commit event
	COMMITTED
	// Describe Transaction deletion event
	DELETED
)

Transacton Operations Enumeration

type UUID

type UUID string

Unique Identifier

func NewUUID

func NewUUID() UUID

type ValuesMap

type ValuesMap map[string]interface{}

Map that represents the data fields (name is the string key, and value is the returned interface)

Jump to

Keyboard shortcuts

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