2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.bgp.rib.impl;
11 import java.util.concurrent.atomic.LongAdder;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.ZeroBasedCounter32;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.rib.TablesKey;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * Provides util for increment/decrement counters whenever is not null
21 * Otherwise prints an informative warn.
23 public final class CountersUtil {
24 private static final Logger LOG = LoggerFactory.getLogger(CountersUtil.class);
26 private CountersUtil() {
27 throw new UnsupportedOperationException();
31 * Increments counter by 1 if supported, otherwise produce a warn
33 * @param counter counter
34 * @param tablesKey tablesKey Type
36 static void increment(@Nullable final LongAdder counter, @Nonnull TablesKey tablesKey) {
37 if (counter != null) {
41 LOG.warn("Family {} not supported", tablesKey);
45 * Increments counter by 1 if supported, otherwise produce a warn
46 * @param counter counter
47 * @param tablesKey tablesKey Type
49 static void decrement(@Nullable final LongAdder counter, @Nonnull TablesKey tablesKey) {
50 if (counter != null) {
54 LOG.warn("Family {} not supported", tablesKey);
57 public static ZeroBasedCounter32 toZeroBasedCounter32(final LongAdder longAdder){
58 return new ZeroBasedCounter32(longAdder.longValue());