CrazyHZM commented on code in PR #14106:
URL: https://github.com/apache/dubbo/pull/14106#discussion_r1604954801
##########
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:
Defining an api as static is not a very good idea; try using instance
objects to manage it.
##########
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
Review Comment:
You can refer to other scopemodelInitializers to manage some singleton
object initialization.
--
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]