koi_net.components.pipeline

Classes

KnowledgePipeline(log, cache, ...)

class koi_net.components.pipeline.KnowledgePipeline(log, cache, request_handler, event_queue, graph)[source]

Bases: object

Parameters:
cache: Cache
call_handler_chain(handler_type, kobj)[source]

Calls handlers of provided type, chaining their inputs and outputs together.

The knowledge object provided when this function is called will be passed to the first handler. A handler may return one of three types: - KnowledgeObject - to modify the knowledge object for the next handler in the chain - None - to keep the same knowledge object for the next handler in the chain - STOP_CHAIN - to stop the handler chain and immediately exit the processing pipeline

Handlers will only be called in the chain if their handler and RID type match that of the inputted knowledge object.

Return type:

KnowledgeObject | StopChain

Parameters:
event_queue: EventQueue
graph: NetworkGraph
knowledge_handlers: list[KnowledgeHandler]
log: Logger
process(kobj)[source]

Sends knowledge object through knowledge processing pipeline.

Handler chains are called in between major events in the pipeline, indicated by their handler type. Each handler type is guaranteed to have access to certain knowledge, and may affect a subsequent action in the pipeline. The five handler types are as follows: - RID - provided RID; if event type is FORGET, this handler decides whether to delete the knowledge from the cache by setting the normalized event type to FORGET, otherwise this handler decides whether to validate the manifest (and fetch it if not provided). After processing, if event type is FORGET, the manifest and contents will be retrieved from the local cache, and indicate the last state of the knowledge before it was deleted. - Manifest - provided RID, manifest; decides whether to validate the bundle (and fetch it if not provided). - Bundle - provided RID, manifest, contents (bundle); decides whether to write knowledge to the cache by setting the normalized event type to NEW or UPDATE. - Network - provided RID, manifest, contents (bundle); decides which nodes (if any) to broadcast an event about this knowledge to. - Final - provided RID, manifests, contents (bundle); final action taken after network broadcast.

The pipeline may be stopped by any point by a single handler returning the STOP_CHAIN sentinel. In that case, the process will exit immediately. Further handlers of that type and later handler chains will not be called.

Parameters:

kobj (KnowledgeObject)

register_handler(handler)[source]
Parameters:

handler (KnowledgeHandler)

request_handler: RequestHandler