Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / common / actor / AbstractUntypedActorWithMetering.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.common.actor;
9
10 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11
12 /**
13  * Actor with its behaviour metered. Metering is enabled by configuration.
14  */
15 public abstract class AbstractUntypedActorWithMetering extends AbstractUntypedActor {
16     // this is used in the metric name. Some transient actors do not have defined names
17     private String actorNameOverride;
18
19     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Akka class design")
20     public AbstractUntypedActorWithMetering() {
21         if (isMetricsCaptureEnabled()) {
22             getContext().become(new MeteringBehavior(this));
23         }
24     }
25
26     @SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR", justification = "Akka class design")
27     public AbstractUntypedActorWithMetering(final String actorNameOverride) {
28         this.actorNameOverride = actorNameOverride;
29         if (isMetricsCaptureEnabled()) {
30             getContext().become(new MeteringBehavior(this));
31         }
32     }
33
34     private boolean isMetricsCaptureEnabled() {
35         return new CommonConfig(getContext().system().settings().config()).isMetricCaptureEnabled();
36     }
37
38     public String getActorNameOverride() {
39         return actorNameOverride;
40     }
41 }