X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fcommon%2Factor%2FMeteringBehavior.java;h=36c35be30a4cc1c4438af53f7c2a558f4ad99ca8;hb=refs%2Fchanges%2F86%2F46686%2F3;hp=d67d413d0963fff464503391002a3e6d3af15bee;hpb=b5b204bafd8ee18692fc023cb2eae6e123369340;p=controller.git 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 d67d413d09..36c35be30a 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,6 +12,7 @@ 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; /** @@ -26,25 +27,42 @@ import org.opendaylight.controller.cluster.reporting.MetricsReporter; * 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 final UntypedActor meteredActor; - private final MetricRegistry METRICREGISTRY = MetricsReporter.getInstance().getMetricsRegistry(); + private final MetricRegistry METRICREGISTRY = MetricsReporter.getInstance(DOMAIN).getMetricsRegistry(); private final String MSG_PROCESSING_RATE = "msg-rate"; - private String actorName; + private String actorQualifiedName; private Timer msgProcessingTimer; /** * * @param actor whose behaviour needs to be metered */ - public MeteringBehavior(UntypedActor actor){ + public MeteringBehavior(final AbstractUntypedActorWithMetering actor) { Preconditions.checkArgument(actor != null, "actor must not be null"); + this.meteredActor = actor; + + String actorName = actor.getActorNameOverride() != null ? actor.getActorNameOverride() + : actor.getSelf().path().name(); + init(actorName); + } + public MeteringBehavior(final UntypedActor actor) { + Preconditions.checkArgument(actor != null, "actor must not be null"); this.meteredActor = actor; - actorName = meteredActor.getSelf().path().toStringWithoutAddress(); - final String msgProcessingTime = MetricRegistry.name(actorName, MSG_PROCESSING_RATE); + + String actorName = actor.getSelf().path().name(); + init(actorName); + } + + private void init(final String actorName) { + actorQualifiedName = new StringBuilder(meteredActor.getSelf().path().parent().toStringWithoutAddress()). + append("/").append(actorName).toString(); + + final String msgProcessingTime = MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE); msgProcessingTimer = METRICREGISTRY.timer(msgProcessingTime); } @@ -65,11 +83,11 @@ public class MeteringBehavior implements Procedure { * @throws Exception */ @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(actorName, MSG_PROCESSING_RATE, messageType); + MetricRegistry.name(actorQualifiedName, MSG_PROCESSING_RATE, messageType); final Timer msgProcessingTimerByMsgType = METRICREGISTRY.timer(msgProcessingTimeByMsgType); @@ -77,7 +95,12 @@ public class MeteringBehavior implements Procedure { final Timer.Context context = msgProcessingTimer.time(); final Timer.Context contextByMsgType = msgProcessingTimerByMsgType.time(); - meteredActor.onReceive(message); + try { + meteredActor.onReceive(message); + } catch (Throwable t) { + Throwables.propagateIfPossible(t, Exception.class); + throw Throwables.propagate(t); + } //stop timers contextByMsgType.stop();