KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > security > UsmTimeEntry


1 /*_############################################################################
2   _##
3   _## SNMP4J - UsmTimeEntry.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21 package org.snmp4j.security;
22
23 import java.io.Serializable JavaDoc;
24 import org.snmp4j.smi.OctetString;
25
26 /**
27  * The <code>UsmTimeEntry</code> class represents time synchronization
28  * information associated with an engine ID.
29  *
30  * @author Frank Fock
31  * @version 1.0
32  */

33 public class UsmTimeEntry implements Serializable JavaDoc {
34
35   private static final long serialVersionUID = -8064483016765127449L;
36
37   private OctetString engineID;
38   private int engineBoots;
39   private int timeDiff;
40   private int latestReceivedTime;
41
42
43   /**
44    * Creates a time entry with engine ID, engine boots and time.
45    *
46    * @param engineID
47    * the engine ID for which time synchronization information is created.
48    * @param engineBoots
49    * the number of engine boots of the engine.
50    * @param engineTime
51    * the time in seconds elapsed since the last reboot of the engine.
52    */

53   public UsmTimeEntry(OctetString engineID, int engineBoots, int engineTime) {
54     this.engineID = engineID;
55     this.engineBoots = engineBoots;
56     setEngineTime(engineTime);
57   }
58
59   public OctetString getEngineID() {
60     return engineID;
61   }
62
63   public int getEngineBoots() {
64     return engineBoots;
65   }
66
67   public void setEngineBoots(int engineBoots) {
68     this.engineBoots = engineBoots;
69   }
70
71   public int getTimeDiff() {
72     return timeDiff;
73   }
74
75   public void setTimeDiff(int timeDiff) {
76     this.timeDiff = timeDiff;
77   }
78
79   /**
80    * Gets the time when a message has been received last from the associated
81    * SNMP engine.
82    * @return
83    * the engine time in seconds.
84    */

85   public int getLatestReceivedTime() {
86     return latestReceivedTime;
87   }
88
89   /**
90    * Sets the time when a message has been received last from the associated
91    * SNMP engine.
92    * @param latestReceivedTime
93    * the engine time in seconds.
94    */

95   public void setLatestReceivedTime(int latestReceivedTime) {
96     this.latestReceivedTime = latestReceivedTime;
97   }
98
99   /**
100    * Sets the engine time which also sets the last received engine time
101    * to the supplied value.
102    * @param engineTime
103    * the time in seconds elapsed since the last reboot of the engine.
104    */

105   public void setEngineTime(int engineTime) {
106     this.latestReceivedTime = engineTime;
107     this.timeDiff = engineTime - (int)(System.currentTimeMillis()/1000);
108   }
109 }
110
Popular Tags