PageRenderTime 36ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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
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
  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. package org.mobicents.protocols.smpp.event;
  23. import org.mobicents.protocols.smpp.Session;
  24. import org.mobicents.protocols.smpp.SessionState;
  25. /**
  26. * Event generated by the receiver thread exiting. This event will be generated
  27. * when the receiver thread terminates either normally or abnormally due to an
  28. * exception. In the former case, isException will return false. In the latter,
  29. * isException will return true and the Throwable object that was the cause of
  30. * the thread's termination can be accessed using {@link #getException}. If an
  31. * application receives this event, it can be assumed that the connection to the
  32. * SMSC is invalid. That is, the network-specific connection will have to be
  33. * reestablished before binding to the SMSC is again possible. It is up to the
  34. * application to do any necessary clean up to the old network connection.
  35. *
  36. * @version $Id: ReceiverExitEvent.java 452 2009-01-15 16:56:36Z orank $
  37. */
  38. public class ReceiverExitEvent extends SMPPEvent {
  39. /**
  40. * Recevier exit reason of "unknown".
  41. */
  42. public static final int UNKNOWN = 0;
  43. /**
  44. * Receiver exited because bind timed out.
  45. */
  46. public static final int BIND_TIMEOUT = 1;
  47. /**
  48. * Receiver exited due to an exception.
  49. */
  50. public static final int EXCEPTION = 2;
  51. /** The exception that caused thread termination. */
  52. private Throwable exception;
  53. /** The state the Connection was in when the thread exited. */
  54. private SessionState connectionState;
  55. /**
  56. * The reason for the exit.
  57. */
  58. private int reason = UNKNOWN;
  59. /**
  60. * Create a new ReceiverExitEvent. Events created with this constructor will
  61. * signify a normal receiver thread termination with no errors.
  62. *
  63. * @param source
  64. * the source Connection of this event.
  65. */
  66. public ReceiverExitEvent(Session source) {
  67. super(RECEIVER_EXIT, source);
  68. }
  69. /**
  70. * Create a new ReceiverExitEvent. If <code>t</code> is not null, the
  71. * newly created event will represent an abnormal termination of the
  72. * receiver thread. If <code>t</code> is null, this constructor has the
  73. * same effect as {@link #ReceiverExitEvent(Session)}.
  74. *
  75. * @param source
  76. * the source Connection of this event.
  77. * @param t
  78. * the exception which caused termination (may be null).
  79. */
  80. public ReceiverExitEvent(Session source, Throwable t) {
  81. super(RECEIVER_EXIT, source);
  82. setException(t);
  83. }
  84. /**
  85. * Create a new ReceiverExitEvent. If <code>t</code> is not null, the
  86. * newly created event will represent an abnormal termination of the
  87. * receiver thread. If <code>t</code> is null, this constructor has the
  88. * same effect as {@link #ReceiverExitEvent(Session)}.
  89. *
  90. * @param source
  91. * the source Connection of this event.
  92. * @param t
  93. * the exception which caused termination (may be null).
  94. * @param state
  95. * the state the Connection was in when termination occurred.
  96. * @see com.adenki.smpp.SessionState
  97. */
  98. public ReceiverExitEvent(Session source, Throwable t, SessionState state) {
  99. super(RECEIVER_EXIT, source);
  100. setException(t);
  101. this.connectionState = state;
  102. }
  103. /**
  104. * Test if this event represents an abnormal termination.
  105. *
  106. * @return true if this event represents abnormal termination due to an
  107. * exception, false if it represents normal termination.
  108. * @deprecated use {#link #getReason}
  109. */
  110. public boolean isException() {
  111. return exception != null;
  112. }
  113. /**
  114. * Get the exception that caused termination.
  115. *
  116. * @return the exception, or null if this event represents normal
  117. * termination.
  118. */
  119. public Throwable getException() {
  120. return exception;
  121. }
  122. public void setException(Throwable t) {
  123. this.exception = t;
  124. if (t != null) {
  125. this.reason = EXCEPTION;
  126. }
  127. }
  128. /**
  129. * Get the state the Connection was in when termination occurred.
  130. * @return the state of the connection.
  131. */
  132. public SessionState getState() {
  133. return connectionState;
  134. }
  135. /**
  136. * Get the reason for the exit event.
  137. *
  138. * @return Returns the reason.
  139. */
  140. public int getReason() {
  141. return reason;
  142. }
  143. /**
  144. * Set the reason for the exit event. Should be one of the enumeration
  145. * values defined in this class.
  146. *
  147. * @param reason
  148. * The reason to set.
  149. */
  150. public void setReason(int reason) {
  151. this.reason = reason;
  152. }
  153. }