pub async fn new(
        instance: &Arc<ComponentInstance>,
        state: &ResolvedInstanceState,
    ) -> ShutdownJob {
        // `dependency_map` represents the dependency relationships between the nodes in this
        // realm (the children, and the parent), as expressed in the component's declaration.
        // This representation must be reconciled with the runtime state of the
        // component. This means mapping children in the declaration with the one
        // or more children that may exist in collections and one or more
        // instances with a matching PartialMoniker that may exist.
        // `dependency_map` maps server => clients (aka provider => consumers, or source => targets)
        let dependency_map = process_component_dependencies(state.decl());
        let mut source_to_targets: HashMap<ParentOrChildMoniker, ShutdownInfo> = HashMap::new();

        for (source, targets) in dependency_map {
            let dependents = get_shutdown_monikers(&targets, state);

            let singleton_source = hashset![source];
            // The shutdown target may be a collection, if so this will expand
            // the collection out into a list of all its members, otherwise it
            // contains a single component.
            let matching_sources: Vec<_> =
                get_shutdown_monikers(&singleton_source, state).into_iter().collect();
            for source in matching_sources {
                let component = match &source {
                    ParentOrChildMoniker::Parent => instance.clone(),
                    ParentOrChildMoniker::ChildMoniker(moniker) => {
                        state.get_child(&moniker).expect("component not found in children").clone()
                    }
                };

                source_to_targets.insert(
                    source.clone(),
                    ShutdownInfo { moniker: source, dependents: dependents.clone(), component },
                );
            }
        }
        // `target_to_sources` is the inverse of `source_to_targets`, and maps a target to all of
        // its dependencies. This inverse mapping gives us a way to do quick lookups when updating
        // `source_to_targets` as we shutdown components in execute().
        let mut target_to_sources: HashMap<ParentOrChildMoniker, Vec<ParentOrChildMoniker>> =
            HashMap::new();
        for provider in source_to_targets.values() {
            // All listed siblings are ones that depend on this child
            // and all those siblings must stop before this one
            for consumer in &provider.dependents {
                // Make or update a map entry for the consumer that points to the
                // list of siblings that offer it capabilities
                target_to_sources
                    .entry(consumer.clone())
                    .or_insert(vec![])
                    .push(provider.moniker.clone());
            }
        }
        let new_job = ShutdownJob { source_to_targets, target_to_sources };
        return new_job;
    }
/// Creates a new ShutdownJob by examining the Component's declaration and
/// runtime state to build up the necessary data structures to stop
/// components in the component in dependency order.
Creates a new ShutdownJob by examining the Component's declaration and
runtime state to build up the necessary data structures to stop
components in the component in dependency order.
Creates a new ShutdownJob by examining the Component ' s declaration and runtime state to build up the necessary data structures to stop components in the component in dependency order .
pub async fn new(
        instance: &Arc<ComponentInstance>,
        state: &ResolvedInstanceState,
    ) -> ShutdownJob {
        // `dependency_map` represents the dependency relationships between the nodes in this
        // realm (the children, and the parent), as expressed in the component's declaration.
        // This representation must be reconciled with the runtime state of the
        // component. This means mapping children in the declaration with the one
        // or more children that may exist in collections and one or more
        // instances with a matching PartialMoniker that may exist.
        // `dependency_map` maps server => clients (aka provider => consumers, or source => targets)
        let dependency_map = process_component_dependencies(state.decl());
        let mut source_to_targets: HashMap<ParentOrChildMoniker, ShutdownInfo> = HashMap::new();
        for (source, targets) in dependency_map {
            let dependents = get_shutdown_monikers(&targets, state);
            let singleton_source = hashset![source];
            // The shutdown target may be a collection, if so this will expand
            // the collection out into a list of all its members, otherwise it
            // contains a single component.
            let matching_sources: Vec<_> =
                get_shutdown_monikers(&singleton_source, state).into_iter().collect();
            for source in matching_sources {
                let component = match &source {
                    ParentOrChildMoniker::Parent => instance.clone(),
                    ParentOrChildMoniker::ChildMoniker(moniker) => {
                        state.get_child(&moniker).expect("component not found in children").clone()
                    }
                };
                source_to_targets.insert(
                    source.clone(),
                    ShutdownInfo { moniker: source, dependents: dependents.clone(), component },
                );
            }
        }
        // `target_to_sources` is the inverse of `source_to_targets`, and maps a target to all of
        // its dependencies. This inverse mapping gives us a way to do quick lookups when updating
        // `source_to_targets` as we shutdown components in execute().
        let mut target_to_sources: HashMap<ParentOrChildMoniker, Vec<ParentOrChildMoniker>> =
            HashMap::new();
        for provider in source_to_targets.values() {
            // All listed siblings are ones that depend on this child
            // and all those siblings must stop before this one
            for consumer in &provider.dependents {
                // Make or update a map entry for the consumer that points to the
                // list of siblings that offer it capabilities
                target_to_sources
                    .entry(consumer.clone())
                    .or_insert(vec![])
                    .push(provider.moniker.clone());
            }
        }
        let new_job = ShutdownJob { source_to_targets, target_to_sources };
        return new_job;
    }
pub async fn new ( instance : & Arc < ComponentInstance > , state : & ResolvedInstanceState , ) -> ShutdownJob { // `dependency_map` represents the dependency relationships between the nodes in this // realm (the children, and the parent), as expressed in the component's declaration. // This representation must be reconciled with the runtime state of the // component. This means mapping children in the declaration with the one // or more children that may exist in collections and one or more // instances with a matching PartialMoniker that may exist. // `dependency_map` maps server => clients (aka provider => consumers, or source => targets) let dependency_map = process_component_dependencies ( state . decl ( ) ) ; let mut source_to_targets : HashMap < ParentOrChildMoniker , ShutdownInfo > = HashMap :: new ( ) ; for ( source , targets ) in dependency_map { let dependents = get_shutdown_monikers ( & targets , state ) ; let singleton_source = hashset ! [ source ] ; // The shutdown target may be a collection, if so this will expand // the collection out into a list of all its members, otherwise it // contains a single component. let matching_sources : Vec < _ > = get_shutdown_monikers ( & singleton_source , state ) . into_iter ( ) . collect ( ) ; for source in matching_sources { let component = match & source { ParentOrChildMoniker :: Parent => instance . clone ( ) , ParentOrChildMoniker :: ChildMoniker ( moniker ) => { state . get_child ( & moniker ) . expect ( " " ) . clone ( ) } } ; source_to_targets . insert ( source . clone ( ) , ShutdownInfo { moniker : source , dependents : dependents . clone ( ) , component } , ) ; } } // `target_to_sources` is the inverse of `source_to_targets`, and maps a target to all of // its dependencies. This inverse mapping gives us a way to do quick lookups when updating // `source_to_targets` as we shutdown components in execute(). let mut target_to_sources : HashMap < ParentOrChildMoniker , Vec < ParentOrChildMoniker > > = HashMap :: new ( ) ; for provider in source_to_targets . values ( ) { // All listed siblings are ones that depend on this child // and all those siblings must stop before this one for consumer in & provider . dependents { // Make or update a map entry for the consumer that points to the // list of siblings that offer it capabilities target_to_sources . entry ( consumer . clone ( ) ) . or_insert ( vec ! [ ] ) . push ( provider . moniker . clone ( ) ) ; } } let new_job = ShutdownJob { source_to_targets , target_to_sources } ; return new_job ; }
Creates a new ShutdownJob by examining the Component's declaration and
runtime state to build up the necessary data structures to stop
components in the component in dependency order.
Creates a new ShutdownJob by examining the Component ' s declaration and runtime state to build up the necessary data structures to stop components in the component in dependency order .
instance
&Arc<ComponentInstance>
state
&ResolvedInstanceState
instance
&Arc<ComponentInstance>
state
&ResolvedInstanceState