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
8 package org.opendaylight.protocol.bgp.rib.impl;
10 import java.util.concurrent.atomic.LongAdder;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Provides util for increment/decrement counters whenever is not null
19 * Otherwise prints an informative warn.
21 public final class CountersUtil {
22 private static final Logger LOG = LoggerFactory.getLogger(CountersUtil.class);
24 private CountersUtil() {
25 throw new UnsupportedOperationException();
29 * Increments counter by 1 if supported, otherwise produce a warn.
31 * @param counter counter
32 * @param tablesKey tablesKey Type
34 static void increment(final @Nullable LongAdder counter, final @NonNull TablesKey tablesKey) {
35 add(counter, tablesKey, 1);
39 * Increments counter by 1 if supported, otherwise produce a warn.
41 * @param counter counter
42 * @param tablesKey tablesKey Type
44 static void decrement(final @Nullable LongAdder counter, final @NonNull TablesKey tablesKey) {
45 add(counter, tablesKey, -1);
49 * Add specified valut to the counter if supported, otherwise produce a warn.
51 * @param counter counter
52 * @param tablesKey tablesKey Type
54 static void add(final @Nullable LongAdder counter, final @NonNull TablesKey tablesKey, final long amount) {
55 if (counter != null) {
58 LOG.warn("Family {} not supported", tablesKey);