/protocols/smpp/src/main/java/org/mobicents/protocols/smpp/net/SmscLink.java

http://mobicents.googlecode.com/ · Java · 120 lines · 14 code · 12 blank · 94 comment · 0 complexity · b280c0dff01afa61efd44d32b792d8a2 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. package org.mobicents.protocols.smpp.net;
  23. import java.io.IOException;
  24. import org.mobicents.protocols.smpp.message.SMPPPacket;
  25. /**
  26. * Interface for the network link to an SMSC.
  27. * @version $Id: SmscLink.java 457 2009-01-15 17:37:42Z orank $
  28. */
  29. public interface SmscLink {
  30. /**
  31. * Initiate the connection to the SMSC. If this link is already connected,
  32. * this method should do nothing.
  33. * @throws IOException
  34. */
  35. void connect() throws IOException;
  36. /**
  37. * Disconnect from the SMSC. If this link is already closed,
  38. * this method should do nothing.
  39. * @throws IOException
  40. */
  41. void disconnect() throws IOException;
  42. /**
  43. * Determine if the underlying link is connected to the SMSC.
  44. * @return <code>true</code> if connected, <code>false</code> otherwise.
  45. */
  46. boolean isConnected();
  47. /**
  48. * Send an SMPP packet to the SMSC.
  49. * @param packet The packet to send.
  50. * @param withOptionalParams <code>true</code> to send the packet&apos;s
  51. * optional parameters during the write, <code>false</code> to omit the
  52. * optional parameters.
  53. * @throws IOException
  54. */
  55. void write(SMPPPacket packet, boolean withOptionalParams) throws IOException;
  56. /**
  57. * If the underlying link implements some form of output buffering, then
  58. * this method should flush the buffer. If the link does not do any form
  59. * of buffering, this method should do nothing.
  60. * @throws IOException
  61. */
  62. void flush() throws IOException;
  63. /**
  64. * Read the next SMPP packet from the underlying link. This method should
  65. * block until it has fully read all of the bytes for the next packet,
  66. * barring any time out. The byte array supplied to the method call will
  67. * be used to store the packet&apos;s bytes, and that same array will be
  68. * returned. However, if the buffer is not large enough to hold the
  69. * packet, a <b>new</b> byte array will be created, the packet stored in it
  70. * and this new array will be returned.
  71. * @param buffer A byte array to use to store the packet data.
  72. * @return <code>buffer</code> will be returned if it is large enough to
  73. * hold all of the packet&apos;s data, otherwise a new array is created
  74. * and returned with the packet data.
  75. * @throws IOException
  76. * @throws ReadTimeoutException
  77. */
  78. SMPPPacket read() throws IOException;
  79. /**
  80. * Get the current timeout for the underlying link. If read timeouts
  81. * are not supported, calls to this method should throw a
  82. * {@link org.mobicents.protocols.smpp.UnsupportedOperationException}.
  83. * @return The current timeout, specified in milliseconds.
  84. * @throws org.mobicents.protocols.smpp.UnsupportedOperationException If read timeouts
  85. * are not supported.
  86. * @see #setTimeout(int)
  87. */
  88. int getTimeout();
  89. /**
  90. * Set the read timeout for the underlying link. If a blocked read takes
  91. * longer than the specified <code>timeout</code>, then a
  92. * {@link ReadTimeoutException} should be thrown. Supporting read timeouts
  93. * is optional for SmscLink implementations. If it is not supported,
  94. * calls to this method must throw an
  95. * {@link org.mobicents.protocols.smpp.UnsupportedOperationException}. A timeout value
  96. * of <code>0</code> deactivates timeouts - reads will block forever.
  97. * @param timeout The new timeout value, specified in milliseconds.
  98. * @throws org.mobicents.protocols.smpp.UnsupportedOperationException If read timeouts
  99. * are not supported.
  100. */
  101. void setTimeout(int timeout);
  102. /**
  103. * Determine if this SMSC link supports read timeouts.
  104. * @return <code>true</code> if the implementation supports read timeouts,
  105. * <code>false</code> if not.
  106. */
  107. boolean isTimeoutSupported();
  108. }