robocanic commented on code in PR #1314:
URL: https://github.com/apache/dubbo-admin/pull/1314#discussion_r2301142154


##########
pkg/core/engine/component.go:
##########
@@ -1,38 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package engine
 
 import (
+       "fmt"
        "math"
 
+       "github.com/apache/dubbo-admin/pkg/core/controller"
+       "github.com/apache/dubbo-admin/pkg/core/events"
+       "github.com/apache/dubbo-admin/pkg/core/logger"
+       coremodel "github.com/apache/dubbo-admin/pkg/core/resource/model"
        "github.com/apache/dubbo-admin/pkg/core/runtime"
+       "github.com/apache/dubbo-admin/pkg/core/store"
 )
 
+func init() {
+       runtime.RegisterComponent(newEngineComponent())
+}
+
 type Component interface {
        runtime.Component
-       ResourceEngine() ResourceEngine
+       ResourceEngine
 }
 
-var _ Component = &BaseResourceEngineComponent{}
+var _ Component = &engineComponent{}
 
-type BaseResourceEngineComponent struct{}
+type engineComponent struct {
+       name      string
+       informers []controller.Informer
+}
 
-func (b BaseResourceEngineComponent) Type() runtime.ComponentType {
+func newEngineComponent() Component {
+       return &engineComponent{
+               informers: make([]controller.Informer, 0),
+       }
+}
+func (b *engineComponent) Type() runtime.ComponentType {
        return runtime.ResourceEngine
 }
 
-func (b BaseResourceEngineComponent) Order() int {
+func (b *engineComponent) Order() int {
        return math.MaxInt
 }
 
-func (b BaseResourceEngineComponent) Init(runtime.BuilderContext) error {
-       panic("Init() must be implemented by concrete 
BaseResourceEngineComponent")
-
-}
-
-func (b BaseResourceEngineComponent) Start(runtime.Runtime, <-chan struct{}) 
error {
-       panic("Start() must be implemented by concrete 
BaseResourceEngineComponent")
+func (b *engineComponent) Init(ctx runtime.BuilderContext) error {
+       cfg := ctx.Config().Engine
+       factory, err := FactoryRegistry().GetListWatcherFactory(cfg.Type)
+       if err != nil {
+               return err
+       }
+       lwList, err := factory.NewListWatchers(cfg)
+       if err != nil {
+               return err
+       }
+       for _, lw := range lwList {
+               eventBusComponent, err := 
ctx.GetActivatedComponent(runtime.EventBus)
+               if err != nil {
+                       return err
+               }
+               emitter, ok := eventBusComponent.(events.Emitter)
+               if !ok {
+                       return fmt.Errorf("type assertion failed, event bus 
component in runtime is not an Emitter")
+               }
+               storeComponent, err := 
ctx.GetActivatedComponent(runtime.ResourceStore)
+               if err != nil {
+                       return err
+               }
+               resourceStore, ok := storeComponent.(store.ResourceStore)
+               if !ok {
+                       return fmt.Errorf("type assertion failed, resource 
store component in runtime is not a ResourceStore")

Review Comment:
   It's a good suggestion, there will be more similar usage in the future, will 
extract a function in the next pr.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to