KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > agentx > master > AgentXMasterEvent


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentX - AgentXMasterEvent.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.master;
24
25 import java.util.EventObject JavaDoc;
26 import org.snmp4j.agent.agentx.AgentXProtocol;
27
28 /**
29  * The <code>AgentXMasterEvent</code> object describes an event that has been
30  * triggered on behalf of a sub-agent to master agent connection/session.
31  * <p>
32  * When the type of the event is vetoable (i.e. the event can be used to
33  * cancel an action), its type has to be an integer value less than zero.
34  * If the type is greater than zero, the event is fired for information only
35  * and changing the veto reason has no effect.
36  *
37  * @author Frank Fock
38  * @version 1.0
39  */

40 public class AgentXMasterEvent extends EventObject JavaDoc {
41
42   public static final int SESSION_TO_ADD = -3;
43   public static final int REGISTRATION_TO_ADD = -5;
44
45   public static final int PEER_ADDED = 1;
46   public static final int PEER_REMOVED = 2;
47   public static final int SESSION_ADDED = 3;
48   public static final int SESSION_REMOVED = 4;
49   public static final int REGISTRATION_ADDED = 5;
50   public static final int REGISTRATION_REMOVED = 6;
51
52   private int type;
53   private Object JavaDoc changedObject;
54   private int vetoReason = AgentXProtocol.AGENTX_SUCCESS;
55
56   /**
57    * Creates an new master agent event.
58    * @param source
59    * the command processor that fired the event.
60    * @param type
61    * the event type (less than zero if vetoable, greater than zero if not).
62    * @param changedObject
63    * an optional reference to the changed object, which might be an
64    * AgentXPeer, AgentXSession, or AgentXRegistration instance for example.
65    */

66   public AgentXMasterEvent(Object JavaDoc source, int type, Object JavaDoc changedObject) {
67     super(source);
68     this.type = type;
69     this.changedObject = changedObject;
70   }
71
72   /**
73    * Returns the event type.
74    * @return
75    * if less than zero, this event can be canceled by setting an appropriate
76    * veto reason. If greater than zero, this event is for information only.
77    */

78   public int getType() {
79     return type;
80   }
81
82   /**
83    * Returns the changed object (or the object to be changed).
84    * @return
85    * an AgentXPeer, AgentXSession, or AgentXRegistration instance for
86    * example.
87    */

88   public Object JavaDoc getChangedObject() {
89     return changedObject;
90   }
91
92   /**
93    * Returns the veto reason. A value other than zero
94    * (={@link AgentXProtocol#AGENTX_SUCCESS}) indicates that a vetoable event
95    * should be canceled.
96    * @return
97    * an AgentX REASON code as defined by {@link AgentXProtocol}.
98    */

99   public int getVetoReason() {
100     return vetoReason;
101   }
102
103   public String JavaDoc toString() {
104     return getClass().getName()+
105         "[type="+type+",changedObject="+changedObject+
106         ",vetoReason="+vetoReason+"]";
107   }
108
109   /**
110    * Sets the AgentX reason (see {@link AgentXProtocol}) other than
111    * {@link AgentXProtocol#AGENTX_SUCCESS} why the action caused this event
112    * should be rejected and undone.
113    *
114    * @param vetoReason
115    * an AgentX reason code.
116    */

117   public void setVetoReason(int vetoReason) {
118     this.vetoReason = vetoReason;
119   }
120 }
121
Popular Tags