X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fcommon%2Factor%2FMeteringBehavior.java;h=63958912c48e8832a4c4b144eab84822e1b24b7a;hp=9ff185a61e27d61c335223d8b1150fa3738a41c6;hb=81674d6fd50b419b868d0851062e23f34b34557d;hpb=b5167b9bc04f2792b275cfe0eac78c0f5eb9442d diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/MeteringBehavior.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/MeteringBehavior.java index 9ff185a61e..63958912c4 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/MeteringBehavior.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/common/actor/MeteringBehavior.java @@ -12,34 +12,38 @@ import akka.japi.Procedure; import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.Timer; import com.google.common.base.Preconditions; +import com.google.common.base.Throwables; import org.opendaylight.controller.cluster.reporting.MetricsReporter; /** * Represents behaviour that can be exhibited by actors of type {@link akka.actor.UntypedActor} - *

+ * + *

* This behaviour meters actor's default behaviour. It captures 2 metrics: *

- * * The information is reported to {@link org.opendaylight.controller.cluster.reporting.MetricsReporter} */ public class MeteringBehavior implements Procedure { + public static final String DOMAIN = "org.opendaylight.controller.actor.metric"; + + private static final String MSG_PROCESSING_RATE = "msg-rate"; private final UntypedActor meteredActor; - private final MetricRegistry METRICREGISTRY = MetricsReporter.getInstance().getMetricsRegistry(); - private final String MSG_PROCESSING_RATE = "msg-rate"; + private final MetricRegistry metricRegistry = MetricsReporter.getInstance(DOMAIN).getMetricsRegistry(); private String actorQualifiedName; private Timer msgProcessingTimer; /** + * Constructs an instance. * * @param actor whose behaviour needs to be metered */ - public MeteringBehavior(AbstractUntypedActorWithMetering actor){ + public MeteringBehavior(final AbstractUntypedActorWithMetering actor) { Preconditions.checkArgument(actor != null, "actor must not be null"); this.meteredActor = actor; @@ -48,7 +52,7 @@ public class MeteringBehavior implements Procedure { init(actorName); } - public MeteringBehavior(UntypedActor actor){ + public MeteringBehavior(final UntypedActor actor) { Preconditions.checkArgument(actor != null, "actor must not be null"); this.meteredActor = actor; @@ -56,47 +60,55 @@ public class MeteringBehavior implements Procedure { init(actorName); } - private void init(String actorName){ - actorQualifiedName = new StringBuilder(meteredActor.getSelf().path().parent().toStringWithoutAddress()). - append("/").append(actorName).toString(); + private void init(final String actorName) { + actorQualifiedName = meteredActor.getSelf().path().parent().toStringWithoutAddress() + + "/" + actorName; final String msgProcessingTime = MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE); - msgProcessingTimer = METRICREGISTRY.timer(msgProcessingTime); + msgProcessingTimer = metricRegistry.timer(msgProcessingTime); } /** * Uses 2 timers to measure message processing rate. One for overall message processing rate and * another to measure rate by message type. The timers are re-used if they were previously created. - *

+ * + *

* {@link com.codahale.metrics.MetricRegistry} maintains a reservoir for different timers where * collected timings are kept. It exposes various metrics for each timer based on collected * data. Eg: count of messages, 99, 95, 50... percentiles, max, mean etc. - *

+ * + *

* These metrics are exposed as JMX bean. * * @see * http://dropwizard.github.io/metrics/manual/core/#timers * - * @param message - * @throws Exception + * @param message the message to process + * @throws Exception on message failure */ + @SuppressWarnings("checkstyle:IllegalCatch") @Override - public void apply(Object message) throws Exception { + public void apply(final Object message) throws Exception { final String messageType = message.getClass().getSimpleName(); final String msgProcessingTimeByMsgType = MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE, messageType); - final Timer msgProcessingTimerByMsgType = METRICREGISTRY.timer(msgProcessingTimeByMsgType); + final Timer msgProcessingTimerByMsgType = metricRegistry.timer(msgProcessingTimeByMsgType); //start timers final Timer.Context context = msgProcessingTimer.time(); final Timer.Context contextByMsgType = msgProcessingTimerByMsgType.time(); - meteredActor.onReceive(message); - - //stop timers - contextByMsgType.stop(); - context.stop(); + try { + meteredActor.onReceive(message); + } catch (Throwable e) { + Throwables.propagateIfPossible(e, Exception.class); + throw new RuntimeException(e); + } finally { + //stop timers + contextByMsgType.stop(); + context.stop(); + } } }