Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to initializes the components in source code #784

Closed
shenjing023 opened this issue Jul 21, 2024 · 2 comments
Closed

How to initializes the components in source code #784

shenjing023 opened this issue Jul 21, 2024 · 2 comments

Comments

@shenjing023
Copy link

I want to study the source code of Weaver. When using weaver multi deploy, it calls the function startMain to initialize the components.

func (d *deployer) startMain() error {
	return d.activateComponent(&protos.ActivateComponentRequest{
		Component: runtime.Main,
	})
}

However, I couldn't find the code that actually initializes the components, something like this:

for _,v:=range d.groups{
   d.ActivateComponent()
}

I would like to know where the code that initializes the components is called.

@rgrandl
Copy link
Collaborator

rgrandl commented Jul 23, 2024

The main component is usually started by the deployer. However,the activations of all the other components are done by the weavelets.

E.g.,

// Implementation of the main component. Has references to `Component1` and `Component2`.
type main struct {
  weaver.Implements[weaver.Main]
  c1 weaver.Ref[Component1]
  c2 weaver.Ref[Component2]

...

// Implementation of the `Component1`. Has references to `Component1` and `Component2`.
type component1Impl struct {
  weaver.Implements[Component1]
  c3 weaver.Ref[Component3]
}

The callgraph is as follows:

main ---> Component 1 ---> Component 3
        |
        ---> Component2

The multi deployer will start component main which under the hood will run 2 weavelets that will run main. When a main weavelet starts, it will activate components that he has references to; in this case main will activate component Component1 and Component2.

Once weavelets for Component1 are started, the weavelets for Component1 will activate Component3.

Other deployers work in a similar way.

@rgrandl
Copy link
Collaborator

rgrandl commented Jul 23, 2024

Feel free to reopen if you have more questions.

@rgrandl rgrandl closed this as completed Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants