ie.omk.smpp.net
Class ObjectLink

java.lang.Object
  extended by ie.omk.smpp.net.SmscLink
      extended by ie.omk.smpp.net.ObjectLink

public class ObjectLink
extends SmscLink

Link implementation which returns packets which have previously been added to it. This implementation is useful for testing applications by first setting up the link by adding packets to it which is will later return when used by a Connection object. For example:

 ObjectLink ol = new ObjectLink();
 
 // Naturally, better test code will set up the packet fields before using
 // them.
 ol.add(new BindReceiverResp());
 ol.add(new DeliverSM());
 ol.add(new DeliverSM());
 ol.add(new DeliverSM());
 
 Connection conn = new Connection(ol);
 conn.bind(id, pass, type);
 
This class will always return the packets in the order they are added. If the next packet in line is a response packet, it will wait until a request has been sent before reporting a packet is available to the Connection. If it is a request packet, it will be made available immediately to the Connection.

Version:
$Id: ObjectLink.java 303 2006-08-10 20:45:21Z orank $

Constructor Summary
ObjectLink()
          Create a new empty ObjectLink.
 
Method Summary
 void add(SMPPPacket pak)
           
 void addDelay(long milliseconds)
          Add a millisecond delay to the stream.
protected  InputStream getInputStream()
          Get the input stream of the virtual circuit.
protected  OutputStream getOutputStream()
          Get the output stream of the virtual circuit.
protected  void implClose()
          Implementation-specific link close.
protected  void implOpen()
          Implementation-specific link open.
 boolean isConnected()
          Check whether or not the connection to the SMSC is open.
 byte[] read(byte[] buf)
          Read the next SMPP packet from the SMSC.
 void setSequenceNumberScheme(SequenceNumberScheme seqNumScheme)
          Deprecated. Method does nothing.
 void setTimeout(int timeout)
          Set the value for read timeout.
 void write(SMPPPacket pak, boolean withOptional)
          Send a packet to the SMSC.
 
Methods inherited from class ie.omk.smpp.net.SmscLink
available, close, flush, getAutoFlush, getTimeout, open, setAutoFlush, setSnoopStreams, setTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectLink

public ObjectLink()
Create a new empty ObjectLink.

Method Detail

implOpen

protected void implOpen()
                 throws IOException
Description copied from class: SmscLink
Implementation-specific link open. This method will be called by the SmscLink.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.

Specified by:
implOpen in class SmscLink
Throws:
IOException - If an exception occurs while opening the connection.

implClose

protected void implClose()
                  throws IOException
Description copied from class: SmscLink
Implementation-specific link close. This method is called by the SmscLink.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 SmscLink.open()method from reconnecting.

Specified by:
implClose in class SmscLink
Throws:
IOException - if an exception occurs during close.
See Also:
SmscLink.getInputStream(), SmscLink.getOutputStream(), SmscLink.close()

getOutputStream

protected OutputStream getOutputStream()
                                throws IOException
Description copied from class: SmscLink
Get the output stream of the virtual circuit.

Specified by:
getOutputStream in class SmscLink
Throws:
IOException - If the output stream cannot be retrieved or the connection is not open.

getInputStream

protected InputStream getInputStream()
                              throws IOException
Description copied from class: SmscLink
Get the input stream of the virtual circuit.

Specified by:
getInputStream in class SmscLink
Throws:
IOException - If the input stream cannot be retrieved or the connection is not open.

isConnected

public boolean isConnected()
Description copied from class: SmscLink
Check whether or not the connection to the SMSC is open.

Specified by:
isConnected in class SmscLink

setTimeout

public void setTimeout(int timeout)
Description copied from class: SmscLink
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.

Overrides:
setTimeout in class SmscLink
Parameters:
timeout - the timeout value in milliseconds.

setSequenceNumberScheme

public void setSequenceNumberScheme(SequenceNumberScheme seqNumScheme)
Deprecated. Method does nothing.


write

public void write(SMPPPacket pak,
                  boolean withOptional)
           throws IOException
Description copied from class: SmscLink
Send a packet to the SMSC.

Overrides:
write in class 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.

read

public byte[] read(byte[] buf)
            throws IOException
Description copied from class: SmscLink
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.

Overrides:
read in class SmscLink
Parameters:
buf - 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.

add

public void add(SMPPPacket pak)

addDelay

public void addDelay(long milliseconds)
Add a millisecond delay to the stream. The delay only begins when the read method is called.

Parameters:
milliseconds - Number of milliseconds to delay. Values less than 1 will be ignored.


Copyright © 2011 smppapi at Sourceforge. All Rights Reserved.