2 * Copyright (c) 2014, 2015 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.netconf.sal.connect.util;
11 import com.google.common.base.Preconditions;
12 import com.google.common.base.Strings;
13 import java.util.concurrent.atomic.AtomicInteger;
15 public class MessageCounter {
16 final AtomicInteger messageId = new AtomicInteger(0);
18 private static final String MESSAGE_ID_BLUEPRINT = "%s-%s";
20 public String getNewMessageId(final String prefix) {
21 Preconditions.checkArgument(!Strings.isNullOrEmpty(prefix), "Null or empty prefix");
22 return String.format(MESSAGE_ID_BLUEPRINT, prefix, getNewMessageId());
25 public String getNewMessageId() {
26 return Integer.toString(messageId.getAndIncrement());