org.mobicents.protocols.smpp.util
Class SyncWrapper

java.lang.Object
  extended by org.mobicents.protocols.smpp.util.SyncWrapper
All Implemented Interfaces:
SessionObserver

public class SyncWrapper
extends Object
implements SessionObserver

Connection observer which mimics synchronous communications. This observer provides methods which block the caller until the desired response packet is available to be returned.

Version:
$Id: SyncWrapper.java 457 2009-01-15 17:37:42Z orank $

Constructor Summary
SyncWrapper(Session connection)
           
 
Method Summary
 BindResp bind(Bind bindRequest)
          Bind to the SMSC.
 BindResp bind(SessionType type, String systemID, String password, String systemType)
          Bind to the SMSC.
 BindResp bind(SessionType type, String systemID, String password, String systemType, int typeOfNumber, int numberPlanIndicator, String addressRange)
          Bind to the SMSC.
 long getPacketTimeout()
          Get the current packet timeout setting.
 void interruptAllBlocked()
          Notify any threads that are currently blocked waiting on a response packet to give up waiting on the response and return.
 boolean isPacketAvailable()
          Check if there are any packets available to be read.
 void packetReceived(Session source, SMPPPacket packet)
          Called when a new SMPP packet has been received from the SMSC.
 SMPPPacket readNextPacket(boolean block)
          Read the next packet from the connection.
 SMPPPacket sendPacket(SMPPPacket packet)
          Send a packet to the SMSC and wait for its response.
 void setPacketTimeout(long packetTimeout)
          Set the timeout, in milliseconds, to block waiting for a packet.
 UnbindResp unbind()
          Unbind from the SMSC and wait for the unbind response packet.
 void update(Session source, SMPPEvent event)
          Called for all events other than packet reception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyncWrapper

public SyncWrapper(Session connection)
Method Detail

bind

public BindResp bind(SessionType type,
                     String systemID,
                     String password,
                     String systemType)
              throws IOException
Bind to the SMSC.

Parameters:
type - The type of connection to bind as (transmitter, receiver or transceiver).
systemID - The system ID of this connection.
password - The password of this connection.
systemType - The system Type for this connection.
Returns:
The bind response packet received from the SMSC.
Throws:
IOException - If an error occurs when trying to send the bind request packet to the SMSC.
ReadTimeoutException - If the bind timeout expires before the response is received from the SMSC.

bind

public BindResp bind(SessionType type,
                     String systemID,
                     String password,
                     String systemType,
                     int typeOfNumber,
                     int numberPlanIndicator,
                     String addressRange)
              throws IOException
Bind to the SMSC.

Parameters:
type - The type of connection to bind as (transmitter, receiver or transceiver).
systemID - The system ID of this connection.
password - The password of this connection.
systemType - The system Type for this connection.
typeOfNumber - TON to bind as.
numberPlanIndicator - NPI to bind as.
addressRange - Address range to bind as.
Returns:
The bind response packet received from the SMSC.
Throws:
IOException - If an error occurs when trying to send the bind request packet to the SMSC.
ReadTimeoutException - If the bind timeout expires before the response is received from the SMSC.

bind

public BindResp bind(Bind bindRequest)
              throws IOException
Bind to the SMSC.

Parameters:
bindRequest - The bind request packet to send.
Returns:
The bind response packet received from the SMSC.
Throws:
IOException - If an error occurs when trying to send the bind packet to the SMSC.
ReadTimeoutException - If the bind timeout expires before the response is received from the SMSC.

unbind

public UnbindResp unbind()
                  throws IOException
Unbind from the SMSC and wait for the unbind response packet.

Returns:
The unbind response packet received from the SMSC.
Throws:
IOException - If an error occurs when trying to send the unbind packet to the SMSC.
ReadTimeoutException - If the packetTimeout expires before the response is received from the SMSC.

sendPacket

public SMPPPacket sendPacket(SMPPPacket packet)
                      throws IOException
Send a packet to the SMSC and wait for its response.

Parameters:
packet - The request packet to send to the SMSC.
Returns:
The response packet received from the SMSC. This may be null if the call timed out waiting on the packet, or if the thread was instructed to give up the wait.
Throws:
IOException - If there was a problem writing to, or reading from, the connection.
ReadTimeoutException - If the packetTimeout expires before the response is received from the SMSC.

packetReceived

public void packetReceived(Session source,
                           SMPPPacket packet)
Description copied from interface: SessionObserver
Called when a new SMPP packet has been received from the SMSC. This method is called by the API framework whenever an SMPP packet has been read and decoded from the network connection to the SMSC. Identification of the packet type can be achieved by calling SMPPPacket.getCommandId().

Specified by:
packetReceived in interface SessionObserver
Parameters:
source - the Connection which received the packet.
packet - the SMPP packet received.

update

public void update(Session source,
                   SMPPEvent event)
Description copied from interface: SessionObserver
Called for all events other than packet reception. This method is called for all events generated by the API framework except that of a packet received. The SessionObserver.packetReceived(org.mobicents.protocols.smpp.Session, org.mobicents.protocols.smpp.message.SMPPPacket)method is called in that case. The update method is mostly used for control events, such as signifying the exit of the receiver thread or notifying of error conditions.

Specified by:
update in interface SessionObserver
Parameters:
source - the Connection which received the packet.
event - the SMPP event type.
See Also:
com.adenki.smpp.event.SMPPEvent#getType

isPacketAvailable

public boolean isPacketAvailable()
Check if there are any packets available to be read.

Returns:
true if readNextPacket(boolean) will return a packet without blocking, false if it would block waiting on a packet.

readNextPacket

public SMPPPacket readNextPacket(boolean block)
                          throws IOException
Read the next packet from the connection.

Parameters:
block - true to block waiting on the next packet to arrive, false to return whether or not a packet was available. Note that calling this method will not return a response packet to the calling thread if there is already another thread blocked waiting on that response. That is, if thread 1 called sendPacket and is waiting on a response and then thread 2 calls this method, when the response packet arrives, thread 1 will be given the response and thread 2 will continue to block in this method until the next packet arrives. However, if thread 1 stops waiting for some reason (for example, it times out waiting for its response), then thread 2 will receive the response packet.
Returns:
The next packet from the SMSC, or null if no packet was available and the caller requested non-blocking operation.
Throws:
IOException - If there was a problem communicating with the connection.

getPacketTimeout

public long getPacketTimeout()
Get the current packet timeout setting.

Returns:
The packet timeout setting.
See Also:
setPacketTimeout(long)

setPacketTimeout

public void setPacketTimeout(long packetTimeout)
Set the timeout, in milliseconds, to block waiting for a packet. The default is 0, meaning wait forever for the packet.

Parameters:
packetTimeout -

interruptAllBlocked

public void interruptAllBlocked()
Notify any threads that are currently blocked waiting on a response packet to give up waiting on the response and return.



Copyright © 2011 Mobicents. All Rights Reserved.