PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/event/ReceiverExitEvent.java

http://mobicents.googlecode.com/
Java | 171 lines | 44 code | 18 blank | 109 comment | 3 complexity | a894dc4b3789b3f80d9a70a12e2192d3 MD5 | raw file
  1/*
  2 * JBoss, Home of Professional Open Source
  3 * Copyright 2011, Red Hat, Inc. and individual contributors
  4 * by the @authors tag. See the copyright.txt in the distribution for a
  5 * full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.mobicents.protocols.smpp.event;
 24
 25import org.mobicents.protocols.smpp.Session;
 26import org.mobicents.protocols.smpp.SessionState;
 27
 28/**
 29 * Event generated by the receiver thread exiting. This event will be generated
 30 * when the receiver thread terminates either normally or abnormally due to an
 31 * exception. In the former case, isException will return false. In the latter,
 32 * isException will return true and the Throwable object that was the cause of
 33 * the thread's termination can be accessed using {@link #getException}. If an
 34 * application receives this event, it can be assumed that the connection to the
 35 * SMSC is invalid. That is, the network-specific connection will have to be
 36 * reestablished before binding to the SMSC is again possible. It is up to the
 37 * application to do any necessary clean up to the old network connection.
 38 * 
 39 * @version $Id: ReceiverExitEvent.java 452 2009-01-15 16:56:36Z orank $
 40 */
 41public class ReceiverExitEvent extends SMPPEvent {
 42    /**
 43     * Recevier exit reason of "unknown".
 44     */
 45    public static final int UNKNOWN = 0;
 46
 47    /**
 48     * Receiver exited because bind timed out.
 49     */
 50    public static final int BIND_TIMEOUT = 1;
 51
 52    /**
 53     * Receiver exited due to an exception.
 54     */
 55    public static final int EXCEPTION = 2;
 56
 57    /** The exception that caused thread termination. */
 58    private Throwable exception;
 59
 60    /** The state the Connection was in when the thread exited. */
 61    private SessionState connectionState;
 62
 63    /**
 64     * The reason for the exit.
 65     */
 66    private int reason = UNKNOWN;
 67
 68    /**
 69     * Create a new ReceiverExitEvent. Events created with this constructor will
 70     * signify a normal receiver thread termination with no errors.
 71     * 
 72     * @param source
 73     *            the source Connection of this event.
 74     */
 75    public ReceiverExitEvent(Session source) {
 76        super(RECEIVER_EXIT, source);
 77    }
 78
 79    /**
 80     * Create a new ReceiverExitEvent. If <code>t</code> is not null, the
 81     * newly created event will represent an abnormal termination of the
 82     * receiver thread. If <code>t</code> is null, this constructor has the
 83     * same effect as {@link #ReceiverExitEvent(Session)}.
 84     * 
 85     * @param source
 86     *            the source Connection of this event.
 87     * @param t
 88     *            the exception which caused termination (may be null).
 89     */
 90    public ReceiverExitEvent(Session source, Throwable t) {
 91        super(RECEIVER_EXIT, source);
 92        setException(t);
 93    }
 94
 95    /**
 96     * Create a new ReceiverExitEvent. If <code>t</code> is not null, the
 97     * newly created event will represent an abnormal termination of the
 98     * receiver thread. If <code>t</code> is null, this constructor has the
 99     * same effect as {@link #ReceiverExitEvent(Session)}.
100     * 
101     * @param source
102     *            the source Connection of this event.
103     * @param t
104     *            the exception which caused termination (may be null).
105     * @param state
106     *            the state the Connection was in when termination occurred.
107     * @see com.adenki.smpp.SessionState
108     */
109    public ReceiverExitEvent(Session source, Throwable t, SessionState state) {
110        super(RECEIVER_EXIT, source);
111        setException(t);
112        this.connectionState = state;
113    }
114
115    /**
116     * Test if this event represents an abnormal termination.
117     * 
118     * @return true if this event represents abnormal termination due to an
119     *         exception, false if it represents normal termination.
120     * @deprecated use {#link #getReason}
121     */
122    public boolean isException() {
123        return exception != null;
124    }
125
126    /**
127     * Get the exception that caused termination.
128     * 
129     * @return the exception, or null if this event represents normal
130     *         termination.
131     */
132    public Throwable getException() {
133        return exception;
134    }
135
136    public void setException(Throwable t) {
137        this.exception = t;
138        if (t != null) {
139            this.reason = EXCEPTION;
140        }
141    }
142
143    /**
144     * Get the state the Connection was in when termination occurred.
145     * @return the state of the connection.
146     */
147    public SessionState getState() {
148        return connectionState;
149    }
150
151    /**
152     * Get the reason for the exit event.
153     * 
154     * @return Returns the reason.
155     */
156    public int getReason() {
157        return reason;
158    }
159
160    /**
161     * Set the reason for the exit event. Should be one of the enumeration
162     * values defined in this class.
163     * 
164     * @param reason
165     *            The reason to set.
166     */
167    public void setReason(int reason) {
168        this.reason = reason;
169    }
170}
171