You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/02/09 01:44:21 UTC

[GitHub] zhengyangyong closed pull request #548: [SCB-326] Using the EventManager directly

zhengyangyong closed pull request #548: [SCB-326] Using the EventManager directly
URL: https://github.com/apache/incubator-servicecomb-java-chassis/pull/548
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
index 5e8743678..dd102161b 100644
--- a/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
+++ b/common/common-rest/src/main/java/org/apache/servicecomb/common/rest/AbstractRestInvocation.java
@@ -39,7 +39,7 @@
 import org.apache.servicecomb.core.definition.MicroserviceMeta;
 import org.apache.servicecomb.core.definition.OperationMeta;
 import org.apache.servicecomb.core.metrics.InvocationStartedEvent;
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.common.utils.JsonUtils;
 import org.apache.servicecomb.foundation.vertx.http.HttpServletRequestEx;
 import org.apache.servicecomb.foundation.vertx.http.HttpServletResponseEx;
@@ -116,7 +116,7 @@ protected void scheduleInvocation() {
 
     InvocationStartedEvent startedEvent = new InvocationStartedEvent(operationMeta.getMicroserviceQualifiedName(),
         InvocationType.PRODUCER, System.nanoTime());
-    EventUtils.triggerEvent(startedEvent);
+    EventManager.post(startedEvent);
 
     operationMeta.getExecutor().execute(() -> {
       synchronized (this.requestEx) {
diff --git a/core/src/main/java/org/apache/servicecomb/core/Invocation.java b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
index 96a84b901..83f0d111d 100644
--- a/core/src/main/java/org/apache/servicecomb/core/Invocation.java
+++ b/core/src/main/java/org/apache/servicecomb/core/Invocation.java
@@ -27,7 +27,7 @@
 import org.apache.servicecomb.core.metrics.InvocationFinishedEvent;
 import org.apache.servicecomb.core.metrics.InvocationStartProcessingEvent;
 import org.apache.servicecomb.core.provider.consumer.ReferenceConfig;
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 import org.apache.servicecomb.swagger.invocation.SwaggerInvocation;
@@ -187,16 +187,15 @@ public String getMicroserviceQualifiedName() {
 
   public void triggerStartProcessingEvent() {
     this.startProcessingTime = System.nanoTime();
-    EventUtils.triggerEvent(new InvocationStartProcessingEvent(
+    EventManager.post(new InvocationStartProcessingEvent(
         operationMeta.getMicroserviceQualifiedName(), this.invocationType, startProcessingTime - startTime));
   }
 
   public void triggerFinishedEvent(int statusCode, boolean success) {
     long finishedTime = System.nanoTime();
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent(operationMeta.getMicroserviceQualifiedName(),
-            this.invocationType, finishedTime - startProcessingTime,
-            finishedTime - startTime, statusCode, success));
+    EventManager.post(new InvocationFinishedEvent(operationMeta.getMicroserviceQualifiedName(),
+        this.invocationType, finishedTime - startProcessingTime,
+        finishedTime - startTime, statusCode, success));
   }
 
   public boolean isSync() {
diff --git a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationFinishedEvent.java b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationFinishedEvent.java
index 4de6154e0..dbcfbde49 100644
--- a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationFinishedEvent.java
+++ b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationFinishedEvent.java
@@ -17,10 +17,9 @@
 
 package org.apache.servicecomb.core.metrics;
 
-import org.apache.servicecomb.foundation.common.event.Event;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 
-public class InvocationFinishedEvent implements Event {
+public class InvocationFinishedEvent {
   private final String operationName;
 
   private final InvocationType invocationType;
diff --git a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartProcessingEvent.java b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartProcessingEvent.java
index dd579e889..64af73f7a 100644
--- a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartProcessingEvent.java
+++ b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartProcessingEvent.java
@@ -17,10 +17,9 @@
 
 package org.apache.servicecomb.core.metrics;
 
-import org.apache.servicecomb.foundation.common.event.Event;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 
-public class InvocationStartProcessingEvent implements Event {
+public class InvocationStartProcessingEvent {
   private final String operationName;
 
   private final InvocationType invocationType;
diff --git a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartedEvent.java b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartedEvent.java
index 4bc4a8fc4..9ce7759a2 100644
--- a/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartedEvent.java
+++ b/core/src/main/java/org/apache/servicecomb/core/metrics/InvocationStartedEvent.java
@@ -17,10 +17,9 @@
 
 package org.apache.servicecomb.core.metrics;
 
-import org.apache.servicecomb.foundation.common.event.Event;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 
-public class InvocationStartedEvent implements Event {
+public class InvocationStartedEvent {
   private final String operationName;
 
   private final InvocationType invocationType;
diff --git a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
index 2504ab00d..d1715cd25 100644
--- a/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
+++ b/core/src/main/java/org/apache/servicecomb/core/provider/consumer/InvokerUtils.java
@@ -21,7 +21,7 @@
 import org.apache.servicecomb.core.definition.SchemaMeta;
 import org.apache.servicecomb.core.invocation.InvocationFactory;
 import org.apache.servicecomb.core.metrics.InvocationStartedEvent;
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.swagger.invocation.AsyncResponse;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 import org.apache.servicecomb.swagger.invocation.Response;
@@ -59,7 +59,7 @@ public static Object syncInvoke(Invocation invocation) throws InvocationExceptio
       return response.getResult();
     }
 
-    throw ExceptionFactory.convertConsumerException((Throwable) response.getResult());
+    throw ExceptionFactory.convertConsumerException(response.getResult());
   }
 
   public static Response innerSyncInvoke(Invocation invocation) {
@@ -118,7 +118,7 @@ public static Object invoke(Invocation invocation) {
 
   private static void triggerStartedEvent(Invocation invocation) {
     long startTime = System.nanoTime();
-    EventUtils.triggerEvent(new InvocationStartedEvent(invocation.getMicroserviceQualifiedName(),
+    EventManager.post(new InvocationStartedEvent(invocation.getMicroserviceQualifiedName(),
         InvocationType.CONSUMER, startTime));
     invocation.setStartTime(startTime);
   }
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/Event.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/Event.java
deleted file mode 100644
index d089f0198..000000000
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/Event.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 org.apache.servicecomb.foundation.common.event;
-
-//Common event interface for event extension
-public interface Event {
-}
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/EventBus.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/EventBus.java
deleted file mode 100644
index 4305acee9..000000000
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/EventBus.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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 org.apache.servicecomb.foundation.common.event;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-public class EventBus {
-  private final Map<Class<? extends Event>, List<EventListener>> allEventListeners = new ConcurrentHashMap<>();
-
-  public void registerEventListener(EventListener eventListener) {
-    List<EventListener> eventListeners = allEventListeners
-        .computeIfAbsent(eventListener.getConcernedEvent(), f -> new CopyOnWriteArrayList<>());
-    eventListeners.add(eventListener);
-  }
-
-  public void unregisterEventListener(EventListener eventListener) {
-    List<EventListener> eventListeners = allEventListeners
-        .computeIfAbsent(eventListener.getConcernedEvent(), f -> new CopyOnWriteArrayList<>());
-    if (eventListeners.contains(eventListener)) {
-      eventListeners.remove(eventListener);
-    }
-  }
-
-  public void triggerEvent(Event event) {
-    List<EventListener> eventListeners = allEventListeners.getOrDefault(event.getClass(), Collections.emptyList());
-    for (EventListener eventListener : eventListeners) {
-      eventListener.process(event);
-    }
-  }
-}
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/EventListener.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/EventListener.java
deleted file mode 100644
index 5f208d6f6..000000000
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/event/EventListener.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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 org.apache.servicecomb.foundation.common.event;
-
-//Common event listener interface,java chassis component can trigger event let high level component perceive data change.
-public interface EventListener {
-
-  //what is type event this listener concerned
-  Class<? extends Event> getConcernedEvent();
-
-  //process event data
-  void process(Event data);
-}
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/EventUtils.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/EventUtils.java
deleted file mode 100644
index 731d8ffa8..000000000
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/EventUtils.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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 org.apache.servicecomb.foundation.common.utils;
-
-import org.apache.servicecomb.foundation.common.event.Event;
-import org.apache.servicecomb.foundation.common.event.EventBus;
-import org.apache.servicecomb.foundation.common.event.EventListener;
-
-public final class EventUtils {
-  private static final EventBus eventBus = new EventBus();
-
-  public static void registerEventListener(EventListener eventListener) {
-    eventBus.registerEventListener(eventListener);
-  }
-
-  public static void unregisterEventListener(EventListener eventListener) {
-    eventBus.unregisterEventListener(eventListener);
-  }
-
-  public static void triggerEvent(Event event) {
-    eventBus.triggerEvent(event);
-  }
-}
diff --git a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/event/TestEventBus.java b/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/event/TestEventBus.java
deleted file mode 100644
index 28b9575c8..000000000
--- a/foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/event/TestEventBus.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 org.apache.servicecomb.foundation.common.event;
-
-import static org.awaitility.Awaitility.await;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class TestEventBus {
-
-  @Test
-  public void test() throws InterruptedException {
-    AtomicBoolean eventReceived = new AtomicBoolean(false);
-
-    EventListener listener = new EventListener() {
-      @Override
-      public Class<? extends Event> getConcernedEvent() {
-        return TestEvent.class;
-      }
-
-      @Override
-      public void process(Event data) {
-        eventReceived.set(true);
-      }
-    };
-
-    EventUtils.registerEventListener(listener);
-    EventUtils.triggerEvent(new TestEvent());
-    await().atMost(1, TimeUnit.SECONDS)
-        .until(eventReceived::get);
-    Assert.assertTrue(eventReceived.get());
-
-    eventReceived.set(false);
-
-    EventUtils.unregisterEventListener(listener);
-    EventUtils.triggerEvent(new TestEvent());
-    Thread.sleep(1000);
-    Assert.assertFalse(eventReceived.get());
-  }
-
-  private class TestEvent implements Event {
-  }
-}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/DefaultEventListenerManager.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/DefaultEventListenerManager.java
index 6dc6df4f4..0ba4412e9 100644
--- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/DefaultEventListenerManager.java
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/DefaultEventListenerManager.java
@@ -17,8 +17,7 @@
 
 package org.apache.servicecomb.metrics.core.event;
 
-import org.apache.servicecomb.foundation.common.event.EventListener;
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.metrics.common.MetricsDimension;
 import org.apache.servicecomb.metrics.core.MetricsConfig;
 import org.apache.servicecomb.metrics.core.event.dimension.StatusConvertorFactory;
@@ -29,7 +28,7 @@
 import com.netflix.config.DynamicPropertyFactory;
 
 @Component
-public class DefaultEventListenerManager implements EventListenerManager {
+public class DefaultEventListenerManager {
 
   @Autowired
   public DefaultEventListenerManager(RegistryMonitor registryMonitor, StatusConvertorFactory convertorFactory) {
@@ -40,14 +39,9 @@ public DefaultEventListenerManager(RegistryMonitor registryMonitor, StatusConver
 
   public DefaultEventListenerManager(RegistryMonitor registryMonitor, StatusConvertorFactory convertorFactory,
       String outputLevel) {
-    this.registerEventListener(new InvocationStartedEventListener(registryMonitor));
-    this.registerEventListener(new InvocationStartProcessingEventListener(registryMonitor));
-    this.registerEventListener(
-        new InvocationFinishedEventListener(registryMonitor, convertorFactory.getConvertor(outputLevel)));
-  }
-
-  @Override
-  public void registerEventListener(EventListener listener) {
-    EventUtils.registerEventListener(listener);
+    EventManager.register(new InvocationStartedEventListener(registryMonitor));
+    EventManager.register(new InvocationStartProcessingEventListener(registryMonitor));
+    EventManager
+        .register(new InvocationFinishedEventListener(registryMonitor, convertorFactory.getConvertor(outputLevel)));
   }
 }
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/EventListenerManager.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/EventListenerManager.java
deleted file mode 100644
index a381b47d3..000000000
--- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/EventListenerManager.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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 org.apache.servicecomb.metrics.core.event;
-
-import org.apache.servicecomb.foundation.common.event.EventListener;
-
-public interface EventListenerManager {
-  void registerEventListener(EventListener listener);
-}
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationFinishedEventListener.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationFinishedEventListener.java
index 5b886b6f0..878e8b7b2 100644
--- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationFinishedEventListener.java
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationFinishedEventListener.java
@@ -18,8 +18,6 @@
 package org.apache.servicecomb.metrics.core.event;
 
 import org.apache.servicecomb.core.metrics.InvocationFinishedEvent;
-import org.apache.servicecomb.foundation.common.event.Event;
-import org.apache.servicecomb.foundation.common.event.EventListener;
 import org.apache.servicecomb.metrics.common.MetricsDimension;
 import org.apache.servicecomb.metrics.core.event.dimension.StatusConvertor;
 import org.apache.servicecomb.metrics.core.monitor.ConsumerInvocationMonitor;
@@ -27,7 +25,9 @@
 import org.apache.servicecomb.metrics.core.monitor.RegistryMonitor;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 
-public class InvocationFinishedEventListener implements EventListener {
+import com.google.common.eventbus.Subscribe;
+
+public class InvocationFinishedEventListener {
   private final RegistryMonitor registryMonitor;
 
   private final StatusConvertor convertor;
@@ -37,14 +37,8 @@ public InvocationFinishedEventListener(RegistryMonitor registryMonitor, StatusCo
     this.convertor = convertor;
   }
 
-  @Override
-  public Class<? extends Event> getConcernedEvent() {
-    return InvocationFinishedEvent.class;
-  }
-
-  @Override
-  public void process(Event data) {
-    InvocationFinishedEvent event = (InvocationFinishedEvent) data;
+  @Subscribe
+  public void process(InvocationFinishedEvent event) {
     String statusDimensionValue = convertor.convert(event.isSuccess(), event.getStatusCode());
     if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
       ProducerInvocationMonitor monitor = registryMonitor.getProducerInvocationMonitor(event.getOperationName());
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
index 3d83b2c0d..f96d1e047 100644
--- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartProcessingEventListener.java
@@ -18,13 +18,13 @@
 package org.apache.servicecomb.metrics.core.event;
 
 import org.apache.servicecomb.core.metrics.InvocationStartProcessingEvent;
-import org.apache.servicecomb.foundation.common.event.Event;
-import org.apache.servicecomb.foundation.common.event.EventListener;
 import org.apache.servicecomb.metrics.core.monitor.ProducerInvocationMonitor;
 import org.apache.servicecomb.metrics.core.monitor.RegistryMonitor;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 
-public class InvocationStartProcessingEventListener implements EventListener {
+import com.google.common.eventbus.Subscribe;
+
+public class InvocationStartProcessingEventListener {
 
   private final RegistryMonitor registryMonitor;
 
@@ -32,14 +32,8 @@ public InvocationStartProcessingEventListener(RegistryMonitor registryMonitor) {
     this.registryMonitor = registryMonitor;
   }
 
-  @Override
-  public Class<? extends Event> getConcernedEvent() {
-    return InvocationStartProcessingEvent.class;
-  }
-
-  @Override
-  public void process(Event data) {
-    InvocationStartProcessingEvent event = (InvocationStartProcessingEvent) data;
+  @Subscribe
+  public void process(InvocationStartProcessingEvent event) {
     if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
       ProducerInvocationMonitor monitor = registryMonitor.getProducerInvocationMonitor(event.getOperationName());
       monitor.getWaitInQueue().increment(-1);
diff --git a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartedEventListener.java b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartedEventListener.java
index c13d17327..5539f1580 100644
--- a/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartedEventListener.java
+++ b/metrics/metrics-core/src/main/java/org/apache/servicecomb/metrics/core/event/InvocationStartedEventListener.java
@@ -18,15 +18,15 @@
 package org.apache.servicecomb.metrics.core.event;
 
 import org.apache.servicecomb.core.metrics.InvocationStartedEvent;
-import org.apache.servicecomb.foundation.common.event.Event;
-import org.apache.servicecomb.foundation.common.event.EventListener;
 import org.apache.servicecomb.metrics.common.MetricsDimension;
 import org.apache.servicecomb.metrics.core.monitor.ConsumerInvocationMonitor;
 import org.apache.servicecomb.metrics.core.monitor.ProducerInvocationMonitor;
 import org.apache.servicecomb.metrics.core.monitor.RegistryMonitor;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 
-public class InvocationStartedEventListener implements EventListener {
+import com.google.common.eventbus.Subscribe;
+
+public class InvocationStartedEventListener {
 
   private final RegistryMonitor registryMonitor;
 
@@ -34,14 +34,8 @@ public InvocationStartedEventListener(RegistryMonitor registryMonitor) {
     this.registryMonitor = registryMonitor;
   }
 
-  @Override
-  public Class<? extends Event> getConcernedEvent() {
-    return InvocationStartedEvent.class;
-  }
-
-  @Override
-  public void process(Event data) {
-    InvocationStartedEvent event = (InvocationStartedEvent) data;
+  @Subscribe
+  public void process(InvocationStartedEvent event) {
     if (InvocationType.PRODUCER.equals(event.getInvocationType())) {
       ProducerInvocationMonitor monitor = registryMonitor.getProducerInvocationMonitor(event.getOperationName());
       monitor.getWaitInQueue().increment();
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java
index db400d191..08bc6601c 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestEventAndRunner.java
@@ -32,7 +32,7 @@
 import org.apache.servicecomb.core.metrics.InvocationFinishedEvent;
 import org.apache.servicecomb.core.metrics.InvocationStartProcessingEvent;
 import org.apache.servicecomb.core.metrics.InvocationStartedEvent;
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.metrics.common.MetricsDimension;
 import org.apache.servicecomb.metrics.common.RegistryMetric;
 import org.apache.servicecomb.metrics.core.custom.DefaultCounterService;
@@ -84,45 +84,42 @@ public void test() throws InterruptedException {
 
     //fun1 is a PRODUCER invocation call 2 time and all is completed
     //two time success
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 200, true));
+    EventManager.post(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 200, true));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(300)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
-            TimeUnit.MILLISECONDS.toNanos(400), TimeUnit.MILLISECONDS.toNanos(700), 500, false));
+    EventManager.post(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
+        TimeUnit.MILLISECONDS.toNanos(400), TimeUnit.MILLISECONDS.toNanos(700), 500, false));
 
     //==========================================================================
 
     //fun3 is a PRODUCER invocation call uncompleted
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun3", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun3", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun3", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(500)));
 
     //==========================================================================
 
     //fun4 is a PRODUCER call only started and no processing start and finished
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun4", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(new InvocationStartedEvent("fun4", InvocationType.PRODUCER, System.nanoTime()));
 
     //==========================================================================
 
     //fun2 is a CONSUMER invocation call once and completed
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun2", InvocationType.CONSUMER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun2", InvocationType.CONSUMER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun2", InvocationType.CONSUMER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun2", InvocationType.CONSUMER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 200, true));
+    EventManager.post(new InvocationFinishedEvent("fun2", InvocationType.CONSUMER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 200, true));
 
     //==========================================================================
 
diff --git a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java
index 844aa0476..a71067cf8 100644
--- a/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java
+++ b/metrics/metrics-core/src/test/java/org/apache/servicecomb/metrics/core/TestStatusDimension.java
@@ -22,7 +22,7 @@
 import org.apache.servicecomb.core.metrics.InvocationFinishedEvent;
 import org.apache.servicecomb.core.metrics.InvocationStartProcessingEvent;
 import org.apache.servicecomb.core.metrics.InvocationStartedEvent;
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.metrics.common.MetricsDimension;
 import org.apache.servicecomb.metrics.common.RegistryMetric;
 import org.apache.servicecomb.metrics.core.custom.DefaultCounterService;
@@ -106,54 +106,48 @@ private RegistryMetric prepare(String outputLevel) throws InterruptedException {
 
     new DefaultEventListenerManager(monitor, new StatusConvertorFactory(), outputLevel);
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 222, true));
+    EventManager.post(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 222, true));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 333, false));
+    EventManager.post(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 333, false));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 444, false));
+    EventManager.post(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 444, false));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 555, false));
+    EventManager.post(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 555, false));
 
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun1", InvocationType.PRODUCER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun1", InvocationType.PRODUCER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 666, false));
+    EventManager.post(new InvocationFinishedEvent("fun1", InvocationType.PRODUCER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 666, false));
 
     //fun2 is a CONSUMER invocation call once and completed
-    EventUtils.triggerEvent(new InvocationStartedEvent("fun2", InvocationType.CONSUMER, System.nanoTime()));
-    EventUtils.triggerEvent(
+    EventManager.post(new InvocationStartedEvent("fun2", InvocationType.CONSUMER, System.nanoTime()));
+    EventManager.post(
         new InvocationStartProcessingEvent("fun2", InvocationType.CONSUMER,
             TimeUnit.MILLISECONDS.toNanos(100)));
-    EventUtils
-        .triggerEvent(new InvocationFinishedEvent("fun2", InvocationType.CONSUMER,
-            TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 200, true));
+    EventManager.post(new InvocationFinishedEvent("fun2", InvocationType.CONSUMER,
+        TimeUnit.MILLISECONDS.toNanos(200), TimeUnit.MILLISECONDS.toNanos(300), 200, true));
 
     //sim lease one window time
     Thread.sleep(1000);
diff --git a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java
index 843c0fe45..d6e0b2a0a 100644
--- a/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java
+++ b/transports/transport-highway/src/main/java/org/apache/servicecomb/transport/highway/HighwayServerInvoke.java
@@ -30,7 +30,7 @@
 import org.apache.servicecomb.core.definition.OperationMeta;
 import org.apache.servicecomb.core.definition.SchemaMeta;
 import org.apache.servicecomb.core.metrics.InvocationStartedEvent;
-import org.apache.servicecomb.foundation.common.utils.EventUtils;
+import org.apache.servicecomb.foundation.common.event.EventManager;
 import org.apache.servicecomb.foundation.vertx.tcp.TcpConnection;
 import org.apache.servicecomb.swagger.invocation.InvocationType;
 import org.apache.servicecomb.swagger.invocation.Response;
@@ -164,7 +164,7 @@ private void sendResponse(Map<String, String> context, Response response) {
   public void execute() {
     InvocationStartedEvent startedEvent = new InvocationStartedEvent(operationMeta.getMicroserviceQualifiedName(),
         InvocationType.PRODUCER, System.nanoTime());
-    EventUtils.triggerEvent(startedEvent);
+    EventManager.post(startedEvent);
     operationMeta.getExecutor().execute(() -> runInExecutor(startedEvent));
   }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services