KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > agentx > AgentXSession


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentX - AgentXSession.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## This program is free software; you can redistribute it and/or modify
8   _## it under the terms of the GNU General Public License version 2 as
9   _## published by the Free Software Foundation.
10   _##
11   _## This program is distributed in the hope that it will be useful,
12   _## but WITHOUT ANY WARRANTY; without even the implied warranty of
13   _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   _## GNU General Public License for more details.
15   _##
16   _## You should have received a copy of the GNU General Public License
17   _## along with this program; if not, write to the Free Software
18   _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19   _## MA 02110-1301 USA
20   _##
21   _##########################################################################*/

22
23 package org.snmp4j.agent.agentx;
24
25 import java.io.Serializable JavaDoc;
26 import java.nio.ByteOrder JavaDoc;
27 import java.util.List JavaDoc;
28
29 public class AgentXSession implements Serializable JavaDoc {
30
31   private int sessionID;
32   private ByteOrder JavaDoc byteOrder;
33   private byte timeout = AgentXProtocol.DEFAULT_TIMEOUT_SECONDS;
34   private volatile int consecutiveTimeouts;
35   private AgentXPeer peer;
36   private List JavaDoc agentCaps;
37   private volatile boolean closed;
38
39   public AgentXSession(int sessionID) {
40     this.sessionID = sessionID;
41     this.consecutiveTimeouts = 0;
42   }
43
44   public List JavaDoc getAgentCaps() {
45     return agentCaps;
46   }
47
48   public ByteOrder JavaDoc getByteOrder() {
49     return byteOrder;
50   }
51
52   public AgentXPeer getPeer() {
53     return peer;
54   }
55
56   public int getSessionID() {
57     return sessionID;
58   }
59
60   public byte getTimeout() {
61     return timeout;
62   }
63
64   public void clearConsecutiveTimeouts() {
65     consecutiveTimeouts = 0;
66   }
67
68   public synchronized void incConsecutiveTimeouts() {
69     consecutiveTimeouts++;
70   }
71
72   public int getConsecutiveTimeouts() {
73     return consecutiveTimeouts;
74   }
75
76   public boolean isClosed() {
77     return closed;
78   }
79
80   public void setAgentCaps(List JavaDoc agentCaps) {
81     this.agentCaps = agentCaps;
82   }
83
84   public void setByteOrder(ByteOrder JavaDoc byteOrder) {
85     this.byteOrder = byteOrder;
86   }
87
88   public void setPeer(AgentXPeer peer) {
89     this.peer = peer;
90   }
91
92   public void setSessionID(int sessionID) {
93     this.sessionID = sessionID;
94   }
95
96   public void setTimeout(byte timeout) {
97     this.timeout = timeout;
98   }
99
100   public void setClosed(boolean closed) {
101     this.closed = closed;
102   }
103
104   public AgentXTarget createAgentXTarget() {
105     AgentXTarget target =
106         new AgentXTarget(getPeer().getAddress(),
107                          getTimeout()*1000);
108     return target;
109   }
110
111   public boolean equals(Object JavaDoc obj) {
112     if (obj instanceof AgentXSession) {
113       return ((AgentXSession)obj).sessionID == sessionID;
114     }
115     return false;
116   }
117
118   public int hashCode() {
119     return sessionID;
120   }
121
122   public String JavaDoc toString() {
123     return getClass().getName()+"[peer="+peer+",sessionID="+sessionID+
124         ",byteOrder="+byteOrder+",timeout="+timeout+
125         ",consecutiveTimeouts="+consecutiveTimeouts+
126         ",agentCaps="+agentCaps+",closed="+closed+"]";
127   }
128
129 }
130
Popular Tags