org.mobicents.protocols.smpp.net
Class ObjectLink

java.lang.Object
  extended by org.mobicents.protocols.smpp.net.AbstractStreamLink
      extended by org.mobicents.protocols.smpp.net.ObjectLink
All Implemented Interfaces:
SmscLink

public class ObjectLink
extends AbstractStreamLink

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 457 2009-01-15 17:37:42Z 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.
 void connect()
          Initiate the connection to the SMSC.
 void disconnect()
          Close the connection to the SMSC.
protected  InputStream getInputStream()
           
protected  OutputStream getOutputStream()
           
 int getTimeout()
          Get the current timeout for the underlying link.
 boolean isConnected()
          Determine if the underlying link is connected to the SMSC.
 boolean isTimeoutSupported()
          Determine if this SMSC link supports read timeouts.
 byte[] read(byte[] buf)
           
 void setTimeout(int timeout)
          Set the read timeout for the underlying link.
 void write(SMPPPacket pak, boolean withOptional)
          Send a packet to the SMSC.
 
Methods inherited from class org.mobicents.protocols.smpp.net.AbstractStreamLink
available, flush, getAutoFlush, read, setAutoFlush, setInputStream, setOutputStream, setSnoopStreams
 
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

isConnected

public boolean isConnected()
Description copied from interface: SmscLink
Determine if the underlying link is connected to the SMSC.

Returns:
true if connected, false otherwise.

isTimeoutSupported

public boolean isTimeoutSupported()
Description copied from interface: SmscLink
Determine if this SMSC link supports read timeouts.

Returns:
true if the implementation supports read timeouts, false if not.

getTimeout

public int getTimeout()
Description copied from interface: SmscLink
Get the current timeout for the underlying link. If read timeouts are not supported, calls to this method should throw a UnsupportedOperationException.

Returns:
The current timeout, specified in milliseconds.
See Also:
SmscLink.setTimeout(int)

setTimeout

public void setTimeout(int timeout)
Description copied from interface: SmscLink
Set the read timeout for the underlying link. If a blocked read takes longer than the specified timeout, then a ReadTimeoutException should be thrown. Supporting read timeouts is optional for SmscLink implementations. If it is not supported, calls to this method must throw an UnsupportedOperationException. A timeout value of 0 deactivates timeouts - reads will block forever.

Parameters:
timeout - The new timeout value, specified in milliseconds.

write

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

Specified by:
write in interface SmscLink
Overrides:
write in class AbstractStreamLink
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

read

public byte[] read(byte[] buf)
            throws IOException
Throws:
IOException

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.

connect

public void connect()
             throws IOException
Description copied from interface: SmscLink
Initiate the connection to the SMSC. If this link is already connected, this method should do nothing.

Throws:
IOException

disconnect

public void disconnect()
                throws IOException
Description copied from class: AbstractStreamLink
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
Overrides:
disconnect in class AbstractStreamLink
Throws:
IOException

getOutputStream

protected OutputStream getOutputStream()
                                throws IOException
Throws:
IOException

getInputStream

protected InputStream getInputStream()
                              throws IOException
Throws:
IOException


Copyright © 2011 Mobicents. All Rights Reserved.