1 /* 2 * @(#)file SnmpRequestCounter.java 3 * @(#)author Sun Microsystems, Inc. 4 * @(#)version 1.4 5 * @(#)date 08/02/09 6 * 7 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 8 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. 9 * 10 */ 11 // Copyright (c) 1995-96 by Cisco Systems, Inc. 12 13 package com.sun.jmx.snmp.daemon; 14 15 16 /** 17 * A static instance of this class is usually created. It contains a 18 * counter that is incremented every time it is accessed. For example, 19 * this class can be used in <CODE>SnmpSession</CODE> to generate a request 20 * identifier that is used to identify a message in a client-server session. 21 * The class wraps around when it reaches the maximum positive value, 2^31 - 1. 22 */ 23 24 final class SnmpRequestCounter { 25 /** 26 * A counter with value between 1...2^31-1. 27 */ 28 int reqid = 0 ; 29 30 public SnmpRequestCounter() {} 31 32 /** 33 * Returns the next request identifier. 34 * @return next request identifier. The value wraps to 1 if it reaches negative value. 35 */ 36 public synchronized int getNewId() { 37 if (++reqid < 0) 38 reqid = 1 ; 39 return reqid ; 40 } 41 } 42