2124b24faf29ac92859b50834c8cbbe654a84bc3
[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 /**
11  * Actor with its behaviour metered. Metering is enabled by configuration.
12  */
13 public abstract class AbstractUntypedActorWithMetering extends AbstractUntypedActor {
14
15     //this is used in the metric name. Some transient actors do not have defined names
16     private String actorNameOverride;
17
18     public AbstractUntypedActorWithMetering() {
19         if (isMetricsCaptureEnabled()) {
20             getContext().become(new MeteringBehavior(this));
21         }
22     }
23
24     public AbstractUntypedActorWithMetering(String actorNameOverride) {
25         this.actorNameOverride = actorNameOverride;
26         if (isMetricsCaptureEnabled()) {
27             getContext().become(new MeteringBehavior(this));
28         }
29     }
30
31     private boolean isMetricsCaptureEnabled() {
32         CommonConfig config = new CommonConfig(getContext().system().settings().config());
33         return config.isMetricCaptureEnabled();
34     }
35
36     public String getActorNameOverride() {
37         return actorNameOverride;
38     }
39 }