KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > transport > TransportStateEvent


1 /*_############################################################################
2   _##
3   _## SNMP4J - TransportStateEvent.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.transport;
22
23 import java.io.*;
24 import java.util.*;
25
26 import org.snmp4j.smi.*;
27
28 /**
29  * The <code>TransportStateEvent</code> describes a state change for
30  * a transport connection. Optionally, connection establishment can be
31  * cancelled.
32  *
33  * @author Frank Fock
34  * @version 1.8
35  * @since 1.7
36  */

37 public class TransportStateEvent extends EventObject {
38
39   private static final long serialVersionUID = 6440139076579035559L;
40
41   public static final int STATE_UNKNOWN = 0;
42   public static final int STATE_CONNECTED = 1;
43   public static final int STATE_DISCONNECTED_REMOTELY = 2;
44   public static final int STATE_DISCONNECTED_TIMEOUT = 3;
45   public static final int STATE_CLOSED = 4;
46
47   private int newState;
48   private Address peerAddress;
49   private IOException causingException;
50
51   private boolean cancelled = false;
52
53   public TransportStateEvent(Object JavaDoc source,
54                              Address peerAddress,
55                              int newState,
56                              IOException causingException) {
57     super(source);
58     this.newState = newState;
59     this.peerAddress = peerAddress;
60     this.causingException = causingException;
61   }
62
63   public IOException getCausingException() {
64     return causingException;
65   }
66
67   public int getNewState() {
68     return newState;
69   }
70
71   public Address getPeerAddress() {
72     return peerAddress;
73   }
74
75   /**
76    * Indicates whether this event has been canceled. Only
77    * {@link #STATE_CONNECTED} events can be canceled.
78    * @return
79    * <code>true</code> if the event has been canceled.
80    * @since 1.8
81    */

82   public boolean isCancelled() {
83     return cancelled;
84   }
85
86   public String JavaDoc toString() {
87     return TransportStateEvent.class.getName()+"[source="+source+
88         ",peerAddress="+peerAddress+
89         ",newState="+newState+
90         ",cancelled="+cancelled+
91         ",causingException="+causingException+"]";
92   }
93
94   /**
95    * Sets the canceled state of the transport event. Only
96    * {@link #STATE_CONNECTED} events can be canceled.
97    * @param cancelled
98    * <code>true</code> if the event should be canceled, i.e. a connection
99    * attempt should be rejected.
100    * @since 1.8
101    */

102   public void setCancelled(boolean cancelled) {
103     this.cancelled = cancelled;
104   }
105 }
106
Popular Tags