/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/event/ReceiverExitEvent.java
Java | 171 lines | 44 code | 18 blank | 109 comment | 3 complexity | a894dc4b3789b3f80d9a70a12e2192d3 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
- /*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
- package org.mobicents.protocols.smpp.event;
- import org.mobicents.protocols.smpp.Session;
- import org.mobicents.protocols.smpp.SessionState;
- /**
- * Event generated by the receiver thread exiting. This event will be generated
- * when the receiver thread terminates either normally or abnormally due to an
- * exception. In the former case, isException will return false. In the latter,
- * isException will return true and the Throwable object that was the cause of
- * the thread's termination can be accessed using {@link #getException}. If an
- * application receives this event, it can be assumed that the connection to the
- * SMSC is invalid. That is, the network-specific connection will have to be
- * reestablished before binding to the SMSC is again possible. It is up to the
- * application to do any necessary clean up to the old network connection.
- *
- * @version $Id: ReceiverExitEvent.java 452 2009-01-15 16:56:36Z orank $
- */
- public class ReceiverExitEvent extends SMPPEvent {
- /**
- * Recevier exit reason of "unknown".
- */
- public static final int UNKNOWN = 0;
- /**
- * Receiver exited because bind timed out.
- */
- public static final int BIND_TIMEOUT = 1;
- /**
- * Receiver exited due to an exception.
- */
- public static final int EXCEPTION = 2;
- /** The exception that caused thread termination. */
- private Throwable exception;
- /** The state the Connection was in when the thread exited. */
- private SessionState connectionState;
- /**
- * The reason for the exit.
- */
- private int reason = UNKNOWN;
- /**
- * Create a new ReceiverExitEvent. Events created with this constructor will
- * signify a normal receiver thread termination with no errors.
- *
- * @param source
- * the source Connection of this event.
- */
- public ReceiverExitEvent(Session source) {
- super(RECEIVER_EXIT, source);
- }
- /**
- * Create a new ReceiverExitEvent. If <code>t</code> is not null, the
- * newly created event will represent an abnormal termination of the
- * receiver thread. If <code>t</code> is null, this constructor has the
- * same effect as {@link #ReceiverExitEvent(Session)}.
- *
- * @param source
- * the source Connection of this event.
- * @param t
- * the exception which caused termination (may be null).
- */
- public ReceiverExitEvent(Session source, Throwable t) {
- super(RECEIVER_EXIT, source);
- setException(t);
- }
- /**
- * Create a new ReceiverExitEvent. If <code>t</code> is not null, the
- * newly created event will represent an abnormal termination of the
- * receiver thread. If <code>t</code> is null, this constructor has the
- * same effect as {@link #ReceiverExitEvent(Session)}.
- *
- * @param source
- * the source Connection of this event.
- * @param t
- * the exception which caused termination (may be null).
- * @param state
- * the state the Connection was in when termination occurred.
- * @see com.adenki.smpp.SessionState
- */
- public ReceiverExitEvent(Session source, Throwable t, SessionState state) {
- super(RECEIVER_EXIT, source);
- setException(t);
- this.connectionState = state;
- }
- /**
- * Test if this event represents an abnormal termination.
- *
- * @return true if this event represents abnormal termination due to an
- * exception, false if it represents normal termination.
- * @deprecated use {#link #getReason}
- */
- public boolean isException() {
- return exception != null;
- }
- /**
- * Get the exception that caused termination.
- *
- * @return the exception, or null if this event represents normal
- * termination.
- */
- public Throwable getException() {
- return exception;
- }
- public void setException(Throwable t) {
- this.exception = t;
- if (t != null) {
- this.reason = EXCEPTION;
- }
- }
- /**
- * Get the state the Connection was in when termination occurred.
- * @return the state of the connection.
- */
- public SessionState getState() {
- return connectionState;
- }
- /**
- * Get the reason for the exit event.
- *
- * @return Returns the reason.
- */
- public int getReason() {
- return reason;
- }
- /**
- * Set the reason for the exit event. Should be one of the enumeration
- * values defined in this class.
- *
- * @param reason
- * The reason to set.
- */
- public void setReason(int reason) {
- this.reason = reason;
- }
- }