1 // NAME 2 // $RCSfile: TimeWindowNode.java,v $ 3 // DESCRIPTION 4 // [given below in javadoc format] 5 // DELTA 6 // $Revision: 3.10 $ 7 // CREATED 8 // $Date: 2006/01/17 17:43:54 $ 9 // COPYRIGHT 10 // Westhawk Ltd 11 // TO DO 12 // 13 14 /* 15 * Copyright (C) 2000 - 2006 by Westhawk Ltd 16 * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a> 17 * 18 * Permission to use, copy, modify, and distribute this software 19 * for any purpose and without fee is hereby granted, provided 20 * that the above copyright notices appear in all copies and that 21 * both the copyright notice and this permission notice appear in 22 * supporting documentation. 23 * This software is provided "as is" without express or implied 24 * warranty. 25 */ 26 package uk.co.westhawk.snmp.stack; 27 28 /*- 29 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲ 30 * SNMP Java Client 31 * ჻჻჻჻჻჻ 32 * Copyright 2023 MetricsHub, Westhawk 33 * ჻჻჻჻჻჻ 34 * This program is free software: you can redistribute it and/or modify 35 * it under the terms of the GNU Lesser General Public License as 36 * published by the Free Software Foundation, either version 3 of the 37 * License, or (at your option) any later version. 38 * 39 * This program is distributed in the hope that it will be useful, 40 * but WITHOUT ANY WARRANTY; without even the implied warranty of 41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 42 * GNU General Lesser Public License for more details. 43 * 44 * You should have received a copy of the GNU General Lesser Public 45 * License along with this program. If not, see 46 * <http://www.gnu.org/licenses/lgpl-3.0.html>. 47 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱ 48 */ 49 50 /** 51 * Node that contains the timeline information of one SNMP Engine ID. 52 * This entry has to be filled in via Discovery. 53 * The node will serve as entry in a lookup table. 54 * 55 * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a> 56 * @version $Revision: 3.10 $ $Date: 2006/01/17 17:43:54 $ 57 */ 58 class TimeWindowNode { 59 private static final String version_id = "@(#)$Id: TimeWindowNode.java,v 3.10 2006/01/17 17:43:54 birgit Exp $ Copyright Westhawk Ltd"; 60 61 public final static int maxTime = 2147483647; // 2^31 -1 62 63 private String snmpEngineId; 64 65 private int snmpEngineBoots = 0; 66 private int snmpEngineTime = 0; 67 private int latestReceivedEngineTime = 0; 68 69 /** 70 * Constructor. 71 * 72 * @param engId The engine ID 73 */ 74 public TimeWindowNode(String engId) { 75 this(engId, 0, 0); 76 } 77 78 /** 79 * Constructor. 80 * 81 * @param engId The engine ID 82 * @param boots The engine boots 83 * @param time The engine time 84 */ 85 public TimeWindowNode(String engId, int boots, int time) { 86 snmpEngineId = engId; 87 snmpEngineBoots = boots; 88 snmpEngineTime = time; 89 latestReceivedEngineTime = time; 90 } 91 92 /** 93 * Returns the snmp engine ID. 94 * 95 * @return the snmp engine ID 96 */ 97 public String getSnmpEngineId() { 98 return snmpEngineId; 99 } 100 101 /** 102 * Sets the SNMP engine boots 103 * 104 * @param newSnmpEngineBoots The SNMP engine boots 105 */ 106 public void setSnmpEngineBoots(int newSnmpEngineBoots) { 107 snmpEngineBoots = newSnmpEngineBoots; 108 } 109 110 /** 111 * Returns the SNMP engine boots 112 * 113 * @return The SNMP engine boots 114 */ 115 public int getSnmpEngineBoots() { 116 return snmpEngineBoots; 117 } 118 119 /** 120 * Sets the SNMP engine time. It also sets the latest received engine 121 * time. 122 * 123 * @param newSnmpEngineTime The SNMP engine time 124 */ 125 public void setSnmpEngineTime(int newSnmpEngineTime) { 126 snmpEngineTime = newSnmpEngineTime; 127 latestReceivedEngineTime = newSnmpEngineTime; 128 } 129 130 /** 131 * Returns the (estimated) SNMP engine time 132 * 133 * @return The SNMP engine time 134 */ 135 public int getSnmpEngineTime() { 136 return snmpEngineTime; 137 } 138 139 /** 140 * Increments the engine time. This mechanisme maintains the loosely 141 * time synchronisation. 142 */ 143 public synchronized void incrementSnmpEngineTime(int incr) { 144 snmpEngineTime += incr; 145 if (snmpEngineTime > maxTime) { 146 snmpEngineBoots++; 147 snmpEngineTime -= maxTime; 148 } 149 } 150 151 /** 152 * Returns the latest received engine time for an engine ID 153 * 154 * @return The latest received engine time 155 */ 156 public int getLatestReceivedEngineTime() { 157 return latestReceivedEngineTime; 158 } 159 160 /** 161 * Returns a string representation of the object. 162 * 163 * @return The string 164 */ 165 public String toString() { 166 StringBuffer buffer = new StringBuffer(this.getClass().getName()); 167 buffer.append("["); 168 buffer.append("engineId=").append(snmpEngineId); 169 buffer.append(", engineBoots=").append(snmpEngineBoots); 170 buffer.append(", engineTime=").append(snmpEngineTime); 171 buffer.append(", latestReceivedEngineTime=").append(latestReceivedEngineTime); 172 buffer.append("]"); 173 return buffer.toString(); 174 } 175 176 }