ie.omk.smpp.net
Class SmscLink

java.lang.Object
  extended by ie.omk.smpp.net.SmscLink
Direct Known Subclasses:
ObjectLink, StreamLink, TcpLink

public abstract class SmscLink
extends Object

Abstract super class of all classes that implement a network link to the SMSC. This class uses buffered input and output internally for reading and writing to whatever input/output streams the concrete implementation provides it. Sending and receiving are guarded against multiple-thread access. That is, if more than one thread attempts to write packets to the link, they will not get "mixed" in the output stream. Likewise on read, only one thread will receive an incoming packet.

Version:
$Id: SmscLink.java 487 2010-10-15 20:06:10Z orank $
Author:
Oran Kelly

Constructor Summary
SmscLink()
          Create a new unconnected SmscLink.
 
Method Summary
 int available()
          Get the number of bytes currently available on the input stream.
 void close()
          Close the connection to the SMSC.
 void flush()
          Flush the output stream of the SMSC link.
 boolean getAutoFlush()
          Get the auto flush behaviour of this link.
protected abstract  InputStream getInputStream()
          Get the input stream of the virtual circuit.
protected abstract  OutputStream getOutputStream()
          Get the output stream of the virtual circuit.
 int getTimeout()
          Get the value for read timeout.
protected abstract  void implClose()
          Implementation-specific link close.
protected abstract  void implOpen()
          Implementation-specific link open.
abstract  boolean isConnected()
          Check whether or not the connection to the SMSC is open.
 void open()
          Open the connection to the SMSC.
 byte[] read(byte[] array)
          Read the next SMPP packet from the SMSC.
 void setAutoFlush(boolean flush)
          Set the auto flush behaviour of this link.
 void setSnoopStreams(OutputStream snoopIn, OutputStream snoopOut)
          Set the snooper streams.
 void setTimeout(int timeout)
          Set the value for read timeout.
 void setTimeout(long timeout)
          Deprecated. Use setTimeout(int)
 void write(SMPPPacket pak, boolean withOptional)
          Send a packet to the SMSC.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SmscLink

public SmscLink()
Create a new unconnected SmscLink.

Method Detail

open

public final void open()
                throws IOException
Open the connection to the SMSC. Calling this method will cause the network link to the SMSC to be established. Once this method returns an application may bind to the SMSC to begin it's SMPP session.

Throws:
IOException - If an exception occurs while opening the connection.

implOpen

protected abstract void implOpen()
                          throws IOException
Implementation-specific link open. This method will be called by the open() method. This method is responsible for establishing the underlying network connection to the remote SMSC system. For example, The TCP/IP implementation would create and connect a new java.io.Socket to the SMSC host.

Throws:
IOException - If an exception occurs while opening the connection.

close

public final void close()
                 throws IOException
Close the connection to the SMSC. Calling this method will close the network link to the remote SMSC system. Applications should be unbound from the SMPP link (using Connection.unbind()) before closing the underlying network link. The connection may be reestablished using open().

Throws:
IOException - If an exception occurs while closing the connection.

implClose

protected abstract void implClose()
                           throws IOException
Implementation-specific link close. This method is called by the close()method after ensuring no further writes or reads can occur. Note that any threads that are writing, reading or blocked on either the readLock or writeLock at the moment this method is called will still execute. Only further reads or writes will be disallowed. An implementation should completely close the underlying network link to the remote SMSC system but it should not free any resources that will preclude the open()method from reconnecting.

Throws:
IOException - if an exception occurs during close.
See Also:
getInputStream(), getOutputStream(), close()

write

public void write(SMPPPacket pak,
                  boolean withOptional)
           throws IOException
Send a packet to the SMSC.

Parameters:
pak - the SMPP packet to send.
withOptional - true to send the optional parameters over the link too, false to only send the mandatory parameters.
Throws:
IOException - if an exception occurs during writing or if the connection is not open.

flush

public void flush()
           throws IOException
Flush the output stream of the SMSC link.

Throws:
IOException - If an exception occurs while flushing the output stream.

getAutoFlush

public boolean getAutoFlush()
Get the auto flush behaviour of this link. The default behaviour is defined in the smppapi properties file. If no properties are found at runtime, the default behaviour is set to true.

See Also:
setAutoFlush(boolean), APIConfig

setAutoFlush

public void setAutoFlush(boolean flush)
Set the auto flush behaviour of this link. If set to true, the link will flush the output stream after every packet written. In high-load environments this may be undesirable.

See Also:
getAutoFlush()

read

public byte[] read(byte[] array)
            throws IOException
Read the next SMPP packet from the SMSC. This method will block until a full packet can be read from the SMSC. The caller should pass in a byte array to read the packet into. If the passed in byte array is too small, a new one will be allocated and returned to the caller.

Parameters:
array - a byte array buffer to read the packet into.
Returns:
the handle to the passed in buffer or the reallocated one.
Throws:
EOFException - If the end of stream is reached before a full packet can be read.
IOException - If an exception occurs when reading the packet from the input stream.

available

public final int available()
Get the number of bytes currently available on the input stream.


getOutputStream

protected abstract OutputStream getOutputStream()
                                         throws IOException
Get the output stream of the virtual circuit.

Throws:
IOException - If the output stream cannot be retrieved or the connection is not open.

getInputStream

protected abstract InputStream getInputStream()
                                       throws IOException
Get the input stream of the virtual circuit.

Throws:
IOException - If the input stream cannot be retrieved or the connection is not open.

isConnected

public abstract boolean isConnected()
Check whether or not the connection to the SMSC is open.


setTimeout

public void setTimeout(long timeout)
Deprecated. Use setTimeout(int)

Set the value for read timeout. A link implementation may support timing out on blocking read operations. This method may be used to set such a timeout. If the implementation does not support timeouts, it must throw an UnsuppertedOperationException.

Parameters:
timeout - the timeout value in milliseconds.
Throws:
UnsupportedOperationException - if the implementation does not support timeouts.

setTimeout

public void setTimeout(int timeout)
Set the value for read timeout. A link implementation may support timing out on blocking read operations. This method may be used to set such a timeout. If the implementation does not support timeouts, it must throw an UnsuppertedOperationException.

Parameters:
timeout - the timeout value in milliseconds.
Throws:
UnsupportedOperationException - if the implementation does not support timeouts.

getTimeout

public int getTimeout()
Get the value for read timeout.

Returns:
the current value for read timeout.
Throws:
UnsupportedOperationException - if the implementation does not support timeouts.
See Also:
setTimeout(long)

setSnoopStreams

public void setSnoopStreams(OutputStream snoopIn,
                            OutputStream snoopOut)
Set the snooper streams. The snooper streams will receive every byte that is either received or sent using this class. This functionality is intended as a debugging aid for SMPP developers. It will be up to the application using the API to provide valid output streams for the data to be written to. Either or both of the streams may be set to null, which in effect turns off snooping.

Parameters:
snoopIn - stream to receive incoming bytes from the SMSC (may be null).
snoopOut - stream to receive outgoing bytes to the SMSC (may be null).


Copyright © 2011 smppapi at Sourceforge. All Rights Reserved.