001: /*_############################################################################
002: _##
003: _## SNMP4J - TransportStateEvent.java
004: _##
005: _## Copyright (C) 2003-2008 Frank Fock and Jochen Katz (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.transport;
022:
023: import java.io.*;
024: import java.util.*;
025:
026: import org.snmp4j.smi.*;
027:
028: /**
029: * The <code>TransportStateEvent</code> describes a state change for
030: * a transport connection. Optionally, connection establishment can be
031: * cancelled.
032: *
033: * @author Frank Fock
034: * @version 1.8
035: * @since 1.7
036: */
037: public class TransportStateEvent extends EventObject {
038:
039: private static final long serialVersionUID = 6440139076579035559L;
040:
041: public static final int STATE_UNKNOWN = 0;
042: public static final int STATE_CONNECTED = 1;
043: public static final int STATE_DISCONNECTED_REMOTELY = 2;
044: public static final int STATE_DISCONNECTED_TIMEOUT = 3;
045: public static final int STATE_CLOSED = 4;
046:
047: private int newState;
048: private Address peerAddress;
049: private IOException causingException;
050:
051: private boolean cancelled = false;
052:
053: public TransportStateEvent(Object source, Address peerAddress,
054: int newState, IOException causingException) {
055: super (source);
056: this .newState = newState;
057: this .peerAddress = peerAddress;
058: this .causingException = causingException;
059: }
060:
061: public IOException getCausingException() {
062: return causingException;
063: }
064:
065: public int getNewState() {
066: return newState;
067: }
068:
069: public Address getPeerAddress() {
070: return peerAddress;
071: }
072:
073: /**
074: * Indicates whether this event has been canceled. Only
075: * {@link #STATE_CONNECTED} events can be canceled.
076: * @return
077: * <code>true</code> if the event has been canceled.
078: * @since 1.8
079: */
080: public boolean isCancelled() {
081: return cancelled;
082: }
083:
084: public String toString() {
085: return TransportStateEvent.class.getName() + "[source="
086: + source + ",peerAddress=" + peerAddress + ",newState="
087: + newState + ",cancelled=" + cancelled
088: + ",causingException=" + causingException + "]";
089: }
090:
091: /**
092: * Sets the canceled state of the transport event. Only
093: * {@link #STATE_CONNECTED} events can be canceled.
094: * @param cancelled
095: * <code>true</code> if the event should be canceled, i.e. a connection
096: * attempt should be rejected.
097: * @since 1.8
098: */
099: public void setCancelled(boolean cancelled) {
100: this.cancelled = cancelled;
101: }
102: }
|