Struct fbp::fbp_node_context::FBPNodeContext[][src]

pub struct FBPNodeContext {
    pub output_vec: ThreadSafeType<HashMap<String, Vec<Box<FBPNodeContext>>>>,
    pub is_configured: AsyncState,
    pub is_running: AsyncState,
    pub node_completion: AsyncState,
    // some fields omitted
}
Expand description

FBP Node Context

The fields in this struct are all of the required data for a Flow Based Programming node.

Fields

output_vec: ThreadSafeType<HashMap<String, Vec<Box<FBPNodeContext>>>>is_configured: AsyncStateis_running: AsyncStatenode_completion: AsyncState

Implementations

Create a new FBPNodeContext

Return the name of this FBPNodeContext

Return the UUID associated with the FBPNodeContext

All FBPNodeContexts and by extension all FBP Nodes have a unique identifier. This is used to add and remove specific instances of an FBP node from various groups.

Return the Receiver for this FBPNodeContext

This is the input queue for an FBP Node

Return the Sender for this FBPNodeContext

This is the output sender for an FBP Node

Returns true if the node’s thread is running and processing messages

Basic usage:

use fbp::fbp_node_context::*;

// NOTE:  An FBPNodeContext is usally NOT created as a standalone struct.  It is used as
// part of an FBP node as is outlined in the example in the NodeNetworkItem documentation.  
// The following example is just to show how the FBPNodeContext struct works.

let my_node_context = FBPNodeContext::new("ExampleContext");
if my_node_context.node_is_running() {
    println!("The node is running");
} else {
    println!("The node is NOT running");
}

Set if an NodeContext is running or not

This method should only be called by the FBP system and not called directly

Wait for a node to be running

This will block the caller until the node is running

Basic usage:

use fbp::fbp_node_context::*;

let my_node_context = FBPNodeContext::new("ExampleContext");

async fn test_wait(a_context: &FBPNodeContext) {
    a_context.wait_for_node_to_be_running().await;
}

Check to see if a node has stopped processing

This will return true if the node has stopped processing

Basic usage:

use fbp::fbp_node_context::*;

let my_node_context = FBPNodeContext::new("ExampleContext");
if my_node_context.node_has_completed() {
    println!("The node has stopped running");
} else {
    println!("The node is still running");
}

Set if the FBPNodeContext has stopped running its thread.

This method should not be called outside of the FBP control software

Wait for a node to stop running

This will block the caller until the node has stopped running

Basic usage:

use fbp::fbp_node_context::*;

let my_node_context = FBPNodeContext::new("ExampleContext");

async fn test_wait(a_context: &FBPNodeContext) {
    a_context.wait_for_node_to_complete().await;
}

Returns if a node is fully configured

This will return true if the node is fully configured

Basic usage:

use fbp::fbp_node_context::*;

let my_node_context = FBPNodeContext::new("ExampleContext");
if my_node_context.node_is_configured() {
    println!("The node is fully configured");
} else {
    println!("The node needs to be configured");
}

Set if a node has all of its configuration data in place.

This should be implemented by an FBP node when it requires configuration. The easiest way to do this is to add an accessor for the required field and when it is set, call this method to signal that the node has all of its configurations in place and can start running

Wait for a node to be configured

This will block the caller until the node is fully configured

Basic usage:

use fbp::fbp_node_context::*;

let my_node_context = FBPNodeContext::new("ExampleContext");

async fn test_wait(a_context: &FBPNodeContext) {
    a_context.wait_for_node_to_be_configured().await;
}

Returns if the node has suspended processing

This will return true if the node has been suspended

Basic usage:

use fbp::fbp_node_context::*;

let my_node_context = FBPNodeContext::new("ExampleContext");
if my_node_context.node_is_suspended() {
    println!("The node has been suspended");
} else {
    println!("The node is NOT suspended");
}

Set if this FBPCondeContext is suspended

This method should only be called by the FBP system and not called directly

Add an FBPContext to receive the output of this node

This will create a Receiver Context and then add that context to the nodes output_vec field

Basic usage:

use fbp::fbp_node_context::*;

let mut my_node_context = FBPNodeContext::new("ExampleContext");
let mut my_downstream_context = FBPNodeContext::new("DownStreamContext");

// The Key parameter allows for grouping receiving nodes into groups.  This could be used
// to send only certain types of output to certain groups.  Typically None is passed which
// specifies that the node should receive ALL output from a node.
my_node_context.add_receiver(&mut my_downstream_context, None);

Remove an FBPContext from the list of nodes to receive the output from

This will find the receiver FBPNodeContext in the output_vec field of the node and will remove it from receiving the output of this node.

Basic usage:

use fbp::fbp_node_context::*;

let mut my_node_context = FBPNodeContext::new("ExampleContext");
let mut my_downstream_context = FBPNodeContext::new("DownStreamContext");
// The Key parameter allows for removing a receiving context from the output_vec that was
// previously placed into an output group.  Typically this is set to None which just removes
// the context entirely
 my_node_context.remove_receiver(&mut my_downstream_context, None);

Returns the number of nodes that have registered to receive the output of this node.

This will return the number of nodes that have asked to receive the output from this context. If the key option is set, then it will only count those contexts that have registered with the group. If the key option is set to None, then all receivers will be counted

Basic usage:

use fbp::fbp_node_context::*;

let my_node_context = FBPNodeContext::new("ExampleContext");
let num_receivers = my_node_context.get_num_items_for_receiver_vec(None);

Post an IIDMessage to the input queue of a context.

This will post a message to the input queue of this context. Messages posted to the input queue are dealt with in a First In, First Out (FIFO) manner

Basic usage:

use fbp::fbp_node_context::*;
use fbp::fbp_iidmessage::*;

let a_msg = IIDMessage::new(MessageType::Data, Some("This is a payload".to_string()));
let my_node_context = FBPNodeContext::new("ExampleContext");
my_node_context.post_msg(a_msg);

Post an IIDMessage to a specific set of receiver nodes

This will post a message to the group of receivers that were added with a specific key when calling add_receiver. The message will only be sent to those receivers that were added with the key

/// Basic usage:


use fbp::fbp_node_context::*;
use fbp::fbp_iidmessage::*;

let mut my_node_context = FBPNodeContext::new("ExampleContext");
let mut group_a =  FBPNodeContext::new("GroupA");
let mut group_b =  FBPNodeContext::new("GroupB");
my_node_context.add_receiver(&mut group_a, Some("GroupA".to_string()));
my_node_context.add_receiver(&mut group_b, Some("GroupB".to_string()));

let group_a_msg = IIDMessage::new(MessageType::Data, Some("A GroupA msg".to_string()));
let group_b_msg = IIDMessage::new(MessageType::Data, Some("A GroupB msg".to_string()));

// This code would most likely be in the trait implementation  of
// process_message(self: &mut Self, msg: IIDMessage) -> std::result::Result<IIDMessage, NodeError>;
// method.  This assumes that a node will create two different types of IIDMessages.  One
// for GroupA and one for GroupB.

my_node_context.post_msg_to_group(group_a_msg, Some("GroupA".to_string()));
my_node_context.post_msg_to_group(group_b_msg, Some("GroupB".to_string()));

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.