org.mobicents.protocols.smpp.net
Class AbstractStreamLink

java.lang.Object
  extended by org.mobicents.protocols.smpp.net.AbstractStreamLink
All Implemented Interfaces:
SmscLink
Direct Known Subclasses:
ObjectLink, TcpLink

public abstract class AbstractStreamLink
extends Object
implements SmscLink

Abstract base implementation of the SmscLink interface that operates on java.io streams.

This class implements basic read and write functionality that can be re-used by other implementations.

Concrete implementations of this class must call both setInputStream(InputStream) and setOutputStream(OutputStream) during the SmscLink.connect() operation in order to set up instances of this class properly.

Version:
$Id: AbstractStreamLink.java 457 2009-01-15 17:37:42Z orank $
Author:
amit bhayani, orank

Constructor Summary
AbstractStreamLink()
          Create a new unconnected SmscLink.
 
Method Summary
 int available()
          Get the number of bytes currently available on the input stream.
 void disconnect()
          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.
 SMPPPacket read()
          Read the next SMPP packet from the SMSC.
 void setAutoFlush(boolean flush)
          Set the auto flush behaviour of this link.
protected  void setInputStream(InputStream inputStream)
           
protected  void setOutputStream(OutputStream outputStream)
           
 void setSnoopStreams(OutputStream snoopIn, OutputStream snoopOut)
          Set the snooper streams.
 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
 
Methods inherited from interface org.mobicents.protocols.smpp.net.SmscLink
connect, getTimeout, isConnected, isTimeoutSupported, setTimeout
 

Constructor Detail

AbstractStreamLink

public AbstractStreamLink()
Create a new unconnected SmscLink.

Method Detail

disconnect

public void disconnect()
                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 Session.unbind()) before closing the underlying network link. The connection may be reestablished using #open.

Specified by:
disconnect in interface SmscLink
Throws:
IOException - If an exception occurs while closing the connection.

write

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

Specified by:
write in interface SmscLink
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.

Specified by:
flush in interface SmscLink
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 SMPPPacket read()
                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.

Specified by:
read in interface SmscLink
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.


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).

setInputStream

protected void setInputStream(InputStream inputStream)

setOutputStream

protected void setOutputStream(OutputStream outputStream)


Copyright © 2011 Mobicents. All Rights Reserved.