walklown commented on code in PR #14106: URL: https://github.com/apache/dubbo/pull/14106#discussion_r1605952297
########## dubbo-common/src/main/java/org/apache/dubbo/common/event/DubboApplicationMulticasterRegistry.java: ########## @@ -14,26 +14,52 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.metrics; +package org.apache.dubbo.common.event; -import org.apache.dubbo.common.beans.factory.ScopeBeanFactory; -import org.apache.dubbo.metrics.event.MetricsDispatcher; import org.apache.dubbo.rpc.model.ApplicationModel; import org.apache.dubbo.rpc.model.FrameworkModel; import org.apache.dubbo.rpc.model.ModuleModel; +import org.apache.dubbo.rpc.model.ScopeModelDestroyListener; import org.apache.dubbo.rpc.model.ScopeModelInitializer; -public class MetricsScopeModelInitializer implements ScopeModelInitializer { +import java.util.concurrent.ConcurrentHashMap; + +/** + * Initialize {@link DubboLifecycleEventMulticaster} for {@link ApplicationModel} + * + * @see DubboEventBus + * @see DubboLifecycleEventMulticaster + * @since 3.3.0 + */ +public class DubboApplicationMulticasterRegistry + implements ScopeModelInitializer, ScopeModelDestroyListener<ApplicationModel> { + + private static final ConcurrentHashMap<ApplicationModel, DubboLifecycleEventMulticaster> multicasterMap = + new ConcurrentHashMap<>(); @Override public void initializeFrameworkModel(FrameworkModel frameworkModel) {} @Override public void initializeApplicationModel(ApplicationModel applicationModel) { - ScopeBeanFactory beanFactory = applicationModel.getBeanFactory(); - beanFactory.registerBean(MetricsDispatcher.class); + multicasterMap.computeIfAbsent(applicationModel, t -> new DefaultDubboEventMulticaster()); + applicationModel.addDestroyListener(this); } @Override public void initializeModuleModel(ModuleModel moduleModel) {} + + @Override + public void onDestroy(ApplicationModel scopeModel) { + multicasterMap.remove(scopeModel); + } + + @Override + public boolean isProtocol() { + return true; + } + + public static DubboLifecycleEventMulticaster getMulticaster(ApplicationModel applicationModel) { Review Comment: Accepted and submitted, please confirm whether it is good. -- 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: notifications-unsubscr...@dubbo.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org For additional commands, e-mail: notifications-h...@dubbo.apache.org