org.jsmpp.session
Class SMPPSession

java.lang.Object
  extended by org.jsmpp.session.AbstractSession
      extended by org.jsmpp.session.SMPPSession
All Implemented Interfaces:
ClientSession, Session

public class SMPPSession
extends AbstractSession
implements ClientSession

This is an object that used to communicate with SMPP Server or SMSC. It hide all un-needed SMPP operation that might harm if the user code use it such as :

All SMPP operation (request-response) is blocking, for an example: SUBMIT_SM will be blocked until SUBMIT_SM_RESP received or timeout. This looks like synchronous communication, but the SMPPClient implementation give ability to the asynchronous way by executing the SUBMIT_SM operation parallel on a different thread. The very simple implementation by using Thread pool, ExecutorService will do. To receive the incoming message such as DELIVER_SM or DATA_SM will be managed by internal thread. User code only have to set listener MessageReceiverListener.

Author:
uudashr

Nested Class Summary
private  class SMPPSession.BoundSessionStateListener
          Session state listener for internal class use.
private  class SMPPSession.PDUReaderWorker
          Worker to read the PDU.
private  class SMPPSession.ResponseHandlerImpl
           
 
Nested classes/interfaces inherited from class org.jsmpp.session.AbstractSession
AbstractSession.EnquireLinkSender
 
Field Summary
private  Connection conn
           
private  ConnectionFactory connFactory
           
private  java.io.DataInputStream in
           
private static org.slf4j.Logger logger
           
private  MessageReceiverListener messageReceiverListener
           
private  java.io.OutputStream out
           
private  PDUReader pduReader
           
private  SMPPSession.PDUReaderWorker pduReaderWorker
           
private  ResponseHandler responseHandler
           
private  SMPPSessionContext sessionContext
           
private  SMPPSession.BoundSessionStateListener sessionStateListener
           
 
Fields inherited from class org.jsmpp.session.AbstractSession
enquireLinkSender
 
Constructor Summary
SMPPSession()
          Default constructor of SMPPSession.
SMPPSession(PDUSender pduSender, PDUReader pduReader, ConnectionFactory connFactory)
           
SMPPSession(java.lang.String host, int port, BindParameter bindParam)
           
SMPPSession(java.lang.String host, int port, BindParameter bindParam, PDUSender pduSender, PDUReader pduReader, ConnectionFactory connFactory)
           
 
Method Summary
 void cancelShortMessage(java.lang.String serviceType, java.lang.String messageId, TypeOfNumber sourceAddrTon, NumberingPlanIndicator sourceAddrNpi, java.lang.String sourceAddr, TypeOfNumber destAddrTon, NumberingPlanIndicator destAddrNpi, java.lang.String destinationAddress)
          Cancel the previous submitted short message.
 void close()
          Forced close connection without sending UNBIND command to Message Center.
 java.lang.String connectAndBind(java.lang.String host, int port, BindParameter bindParam)
          Open connection and bind immediately.
 java.lang.String connectAndBind(java.lang.String host, int port, BindParameter bindParam, long timeout)
          Open connection and bind immediately.
 void connectAndBind(java.lang.String host, int port, BindType bindType, java.lang.String systemId, java.lang.String password, java.lang.String systemType, TypeOfNumber addrTon, NumberingPlanIndicator addrNpi, java.lang.String addressRange)
          Open connection and bind immediately.
 void connectAndBind(java.lang.String host, int port, BindType bindType, java.lang.String systemId, java.lang.String password, java.lang.String systemType, TypeOfNumber addrTon, NumberingPlanIndicator addrNpi, java.lang.String addressRange, long timeout)
          Open connection and bind immediately with specified timeout.
protected  Connection connection()
           
protected  void finalize()
           
private  void fireAcceptAlertNotification(AlertNotification alertNotification)
           
private  void fireAcceptDeliverSm(DeliverSm deliverSm)
           
 MessageReceiverListener getMessageReceiverListener()
          Get the current message receiver listener that is currently registered for this smpp session.
protected  GenericMessageReceiverListener messageReceiverListener()
           
 QuerySmResult queryShortMessage(java.lang.String messageId, TypeOfNumber sourceAddrTon, NumberingPlanIndicator sourceAddrNpi, java.lang.String sourceAddr)
          Query previous submitted short message based on it's message_id and message_id.
 void replaceShortMessage(java.lang.String messageId, TypeOfNumber sourceAddrTon, NumberingPlanIndicator sourceAddrNpi, java.lang.String sourceAddr, java.lang.String scheduleDeliveryTime, java.lang.String validityPeriod, RegisteredDelivery registeredDelivery, byte smDefaultMsgId, byte[] shortMessage)
          Replace the previous submitted short message.
private  java.lang.String sendBind(BindType bindType, java.lang.String systemId, java.lang.String password, java.lang.String systemType, InterfaceVersion interfaceVersion, TypeOfNumber addrTon, NumberingPlanIndicator addrNpi, java.lang.String addressRange, long timeout)
          Sending bind.
protected  AbstractSessionContext sessionContext()
           
 void setMessageReceiverListener(MessageReceiverListener messageReceiverListener)
          Sets a message receiver listener for this smpp session.
 SubmitMultiResult submitMultiple(java.lang.String serviceType, TypeOfNumber sourceAddrTon, NumberingPlanIndicator sourceAddrNpi, java.lang.String sourceAddr, Address[] destinationAddresses, ESMClass esmClass, byte protocolId, byte priorityFlag, java.lang.String scheduleDeliveryTime, java.lang.String validityPeriod, RegisteredDelivery registeredDelivery, ReplaceIfPresentFlag replaceIfPresentFlag, DataCoding dataCoding, byte smDefaultMsgId, byte[] shortMessage, OptionalParameter... optionalParameters)
          Submit short message to multiple destination address.
 java.lang.String submitShortMessage(java.lang.String serviceType, TypeOfNumber sourceAddrTon, NumberingPlanIndicator sourceAddrNpi, java.lang.String sourceAddr, TypeOfNumber destAddrTon, NumberingPlanIndicator destAddrNpi, java.lang.String destinationAddr, ESMClass esmClass, byte protocolId, byte priorityFlag, java.lang.String scheduleDeliveryTime, java.lang.String validityPeriod, RegisteredDelivery registeredDelivery, byte replaceIfPresentFlag, DataCoding dataCoding, byte smDefaultMsgId, byte[] shortMessage, OptionalParameter... optionalParameters)
          Submit a short message to specified destination address.
 
Methods inherited from class org.jsmpp.session.AbstractSession
addSessionStateListener, dataShortMessage, ensureReceivable, ensureTransmittable, ensureTransmittable, executeSendCommand, fireAcceptDataSm, getEnquireLinkTimer, getLastActivityTimestamp, getPduProcessorDegree, getSessionId, getSessionState, getTransactionTimer, isReadPdu, pduSender, removePendingResponse, removeSessionStateListener, sendEnquireLink, sequence, setEnquireLinkTimer, setPduProcessorDegree, setTransactionTimer, unbindAndClose
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jsmpp.session.Session
addSessionStateListener, dataShortMessage, getEnquireLinkTimer, getLastActivityTimestamp, getSessionId, getSessionState, getTransactionTimer, removeSessionStateListener, setEnquireLinkTimer, setTransactionTimer, unbindAndClose
 

Field Detail

logger

private static final org.slf4j.Logger logger

pduReader

private final PDUReader pduReader

connFactory

private final ConnectionFactory connFactory

conn

private Connection conn

in

private java.io.DataInputStream in

out

private java.io.OutputStream out

pduReaderWorker

private SMPPSession.PDUReaderWorker pduReaderWorker

responseHandler

private final ResponseHandler responseHandler

messageReceiverListener

private MessageReceiverListener messageReceiverListener

sessionStateListener

private SMPPSession.BoundSessionStateListener sessionStateListener

sessionContext

private SMPPSessionContext sessionContext
Constructor Detail

SMPPSession

public SMPPSession()
Default constructor of SMPPSession. The next action might be connect and bind to a destination message center.

See Also:
connectAndBind(String, int, BindType, String, String, String, TypeOfNumber, NumberingPlanIndicator, String)

SMPPSession

public SMPPSession(PDUSender pduSender,
                   PDUReader pduReader,
                   ConnectionFactory connFactory)

SMPPSession

public SMPPSession(java.lang.String host,
                   int port,
                   BindParameter bindParam,
                   PDUSender pduSender,
                   PDUReader pduReader,
                   ConnectionFactory connFactory)
            throws java.io.IOException
Throws:
java.io.IOException

SMPPSession

public SMPPSession(java.lang.String host,
                   int port,
                   BindParameter bindParam)
            throws java.io.IOException
Throws:
java.io.IOException
Method Detail

connectAndBind

public void connectAndBind(java.lang.String host,
                           int port,
                           BindType bindType,
                           java.lang.String systemId,
                           java.lang.String password,
                           java.lang.String systemType,
                           TypeOfNumber addrTon,
                           NumberingPlanIndicator addrNpi,
                           java.lang.String addressRange)
                    throws java.io.IOException
Open connection and bind immediately.

Specified by:
connectAndBind in interface ClientSession
Parameters:
host - is the SMSC host address.
port - is the SMSC listen port.
bindType - is the bind type.
systemId - is the system id.
password - is the password.
systemType - is the system type.
addrTon - is the address TON.
addrNpi - is the address NPI.
addressRange - is the address range.
Throws:
java.io.IOException - if there is an IO error found.

connectAndBind

public void connectAndBind(java.lang.String host,
                           int port,
                           BindType bindType,
                           java.lang.String systemId,
                           java.lang.String password,
                           java.lang.String systemType,
                           TypeOfNumber addrTon,
                           NumberingPlanIndicator addrNpi,
                           java.lang.String addressRange,
                           long timeout)
                    throws java.io.IOException
Open connection and bind immediately with specified timeout. The default timeout is 1 minutes.

Specified by:
connectAndBind in interface ClientSession
Parameters:
host - is the SMSC host address.
port - is the SMSC listen port.
bindType - is the bind type.
systemId - is the system id.
password - is the password.
systemType - is the system type.
addrTon - is the address TON.
addrNpi - is the address NPI.
addressRange - is the address range.
timeout - is the timeout.
Throws:
java.io.IOException - if there is an IO error found.

connectAndBind

public java.lang.String connectAndBind(java.lang.String host,
                                       int port,
                                       BindParameter bindParam)
                                throws java.io.IOException
Open connection and bind immediately.

Specified by:
connectAndBind in interface ClientSession
Parameters:
host - is the SMSC host address.
port - is the SMSC listen port.
bindParam - is the bind parameters.
Returns:
the SMSC system id.
Throws:
java.io.IOException - if there is an IO error found.

connectAndBind

public java.lang.String connectAndBind(java.lang.String host,
                                       int port,
                                       BindParameter bindParam,
                                       long timeout)
                                throws java.io.IOException
Open connection and bind immediately.

Specified by:
connectAndBind in interface ClientSession
Parameters:
host - is the SMSC host address.
port - is the SMSC listen port.
bindParam - is the bind parameters.
timeout - is the timeout.
Returns:
the SMSC system id.
Throws:
java.io.IOException - if there is an IO error found.

sendBind

private java.lang.String sendBind(BindType bindType,
                                  java.lang.String systemId,
                                  java.lang.String password,
                                  java.lang.String systemType,
                                  InterfaceVersion interfaceVersion,
                                  TypeOfNumber addrTon,
                                  NumberingPlanIndicator addrNpi,
                                  java.lang.String addressRange,
                                  long timeout)
                           throws PDUException,
                                  ResponseTimeoutException,
                                  InvalidResponseException,
                                  NegativeResponseException,
                                  java.io.IOException
Sending bind.

Parameters:
bindType - is the bind type.
systemId - is the system id.
password - is the password.
systemTypeis - the system type.
interfaceVersion - is the interface version.
addrTon - is the address TON.
addrNpi - is the address NPI.
addressRange - is the address range.
timeout - is the max time waiting for bind response.
Returns:
SMSC system id.
Throws:
PDUException - if we enter invalid bind parameter(s).
ResponseTimeoutException - if there is no valid response after defined millisecond.
InvalidResponseException - if there is invalid response found.
NegativeResponseException - if we receive negative response.
java.io.IOException - if there is an IO error occur.

submitShortMessage

public java.lang.String submitShortMessage(java.lang.String serviceType,
                                           TypeOfNumber sourceAddrTon,
                                           NumberingPlanIndicator sourceAddrNpi,
                                           java.lang.String sourceAddr,
                                           TypeOfNumber destAddrTon,
                                           NumberingPlanIndicator destAddrNpi,
                                           java.lang.String destinationAddr,
                                           ESMClass esmClass,
                                           byte protocolId,
                                           byte priorityFlag,
                                           java.lang.String scheduleDeliveryTime,
                                           java.lang.String validityPeriod,
                                           RegisteredDelivery registeredDelivery,
                                           byte replaceIfPresentFlag,
                                           DataCoding dataCoding,
                                           byte smDefaultMsgId,
                                           byte[] shortMessage,
                                           OptionalParameter... optionalParameters)
                                    throws PDUException,
                                           ResponseTimeoutException,
                                           InvalidResponseException,
                                           NegativeResponseException,
                                           java.io.IOException
Description copied from interface: ClientSession
Submit a short message to specified destination address. This method will blocks until response received or timeout reached. This method simplify operations of sending SUBMIT_SM command and receiving the SUBMIT_SM_RESP.

Specified by:
submitShortMessage in interface ClientSession
Parameters:
serviceType - is the service_type.
sourceAddrTon - is the source_addr_ton.
sourceAddrNpi - is the source_addr_npi.
sourceAddr - is the source_addr.
destAddrTon - is the dest_addr_ton.
destAddrNpi - is the dest_addr_npi.
destinationAddr - is the destination_addr.
esmClass - is the esm_class.
protocolId - is the protocol_id.
priorityFlag - is the priority_flag.
scheduleDeliveryTime - is the schedule_delivery_time.
validityPeriod - is the validity_period.
registeredDelivery - is the registered_delivery.
replaceIfPresentFlag - is the replace_if_present_flag.
dataCoding - is the data_coding.
smDefaultMsgId - is the sm_default_msg_id.
shortMessage - is the short_message.
optionalParameters - is the optional parameters.
Returns:
the message_id to identified the submitted short message for later use (delivery receipt, QUERY_SM, CANCEL_SM, REPLACE_SM).
Throws:
PDUException - if there is invalid PDU parameter found..
ResponseTimeoutException - if timeout has been reach.
InvalidResponseException - if response is invalid.
NegativeResponseException - if negative response received.
java.io.IOException - if there is an I/O error found.

submitMultiple

public SubmitMultiResult submitMultiple(java.lang.String serviceType,
                                        TypeOfNumber sourceAddrTon,
                                        NumberingPlanIndicator sourceAddrNpi,
                                        java.lang.String sourceAddr,
                                        Address[] destinationAddresses,
                                        ESMClass esmClass,
                                        byte protocolId,
                                        byte priorityFlag,
                                        java.lang.String scheduleDeliveryTime,
                                        java.lang.String validityPeriod,
                                        RegisteredDelivery registeredDelivery,
                                        ReplaceIfPresentFlag replaceIfPresentFlag,
                                        DataCoding dataCoding,
                                        byte smDefaultMsgId,
                                        byte[] shortMessage,
                                        OptionalParameter... optionalParameters)
                                 throws PDUException,
                                        ResponseTimeoutException,
                                        InvalidResponseException,
                                        NegativeResponseException,
                                        java.io.IOException
Description copied from interface: ClientSession
Submit short message to multiple destination address. It's similar to submit short message, but it sending to multiple address. This method will blocks until response received or timeout reached. This method is simplify operations of sending SUBMIT_MULTI and receiving SUBMIT_MULTI_RESP.

Specified by:
submitMultiple in interface ClientSession
Parameters:
serviceType - is the service_type.
sourceAddrTon - is the source_addr_ton.
sourceAddrNpi - is the source_addr_npi.
sourceAddr - is the source_addr.
destinationAddresses - is the destination addresses.
esmClass - is the esm_class.
protocolId - is the protocol_id.
priorityFlag - is the priority_flag.
scheduleDeliveryTime - is the schedule_delivery_time.
validityPeriod - is the validity_period.
registeredDelivery - is the registered_delivery.
replaceIfPresentFlag - is the replace_if_present_flag.
dataCoding - is the data_coding.
smDefaultMsgId - is the sm_default_msg_id.
shortMessage - is the short_message.
optionalParameters - is the optional parameters.
Returns:
the message_id and the un-success deliveries.
Throws:
PDUException - if there is invalid PDU parameter found.
ResponseTimeoutException - if timeout has been reach.
InvalidResponseException - if response is invalid.
NegativeResponseException - if negative response received.
java.io.IOException - if there is an I/O error found.

queryShortMessage

public QuerySmResult queryShortMessage(java.lang.String messageId,
                                       TypeOfNumber sourceAddrTon,
                                       NumberingPlanIndicator sourceAddrNpi,
                                       java.lang.String sourceAddr)
                                throws PDUException,
                                       ResponseTimeoutException,
                                       InvalidResponseException,
                                       NegativeResponseException,
                                       java.io.IOException
Description copied from interface: ClientSession
Query previous submitted short message based on it's message_id and message_id. This method will blocks until response received or timeout reached. This method is simplify operations of sending QUERY_SM and receiving QUERY_SM_RESP.

Specified by:
queryShortMessage in interface ClientSession
Parameters:
messageId - is the message_id.
sourceAddrTon - is the source_addr_ton.
sourceAddrNpi - is the source_addr_npi.
sourceAddr - is the source_addr.
Returns:
the result of query short message.
Throws:
PDUException - if there is invalid PDU parameter found.
ResponseTimeoutException - if timeout has been reach.
InvalidResponseException - if response is invalid.
NegativeResponseException - if negative response received.
java.io.IOException - if there is an I/O error found.

replaceShortMessage

public void replaceShortMessage(java.lang.String messageId,
                                TypeOfNumber sourceAddrTon,
                                NumberingPlanIndicator sourceAddrNpi,
                                java.lang.String sourceAddr,
                                java.lang.String scheduleDeliveryTime,
                                java.lang.String validityPeriod,
                                RegisteredDelivery registeredDelivery,
                                byte smDefaultMsgId,
                                byte[] shortMessage)
                         throws PDUException,
                                ResponseTimeoutException,
                                InvalidResponseException,
                                NegativeResponseException,
                                java.io.IOException
Description copied from interface: ClientSession
Replace the previous submitted short message. This method will blocks until response received or timeout reached. This method is simplify operations of sending REPLACE_SM and receiving REPLACE_SM_RESP.

Specified by:
replaceShortMessage in interface ClientSession
Parameters:
messageId - is the message_id.
sourceAddrTon - is the source_addr_ton.
sourceAddrNpi - is the source_addr_npi.
sourceAddr - is the source_addr.
scheduleDeliveryTime - is the schedule_delivery_time.
validityPeriod - is the validity_period.
registeredDelivery - is the registered_delivery.
smDefaultMsgId - is the sm_default_msg_id.
shortMessage - is the short_message.
Throws:
PDUException - if there is invalid PDU parameter found.
ResponseTimeoutException - if timeout has been reach.
InvalidResponseException - if response is invalid.
NegativeResponseException - if negative response received.
java.io.IOException - if there is an I/O error found.

cancelShortMessage

public void cancelShortMessage(java.lang.String serviceType,
                               java.lang.String messageId,
                               TypeOfNumber sourceAddrTon,
                               NumberingPlanIndicator sourceAddrNpi,
                               java.lang.String sourceAddr,
                               TypeOfNumber destAddrTon,
                               NumberingPlanIndicator destAddrNpi,
                               java.lang.String destinationAddress)
                        throws PDUException,
                               ResponseTimeoutException,
                               InvalidResponseException,
                               NegativeResponseException,
                               java.io.IOException
Description copied from interface: ClientSession
Cancel the previous submitted short message. This method will blocks until response received or timeout reached. This method is simplify operations of sending CANCEL_SM and receiving CANCEL_SM_RESP.

Specified by:
cancelShortMessage in interface ClientSession
Parameters:
serviceType - is the service_type.
messageId - is the message_id.
sourceAddrTon - is the source_addr_ton.
sourceAddrNpi - is the source_addr_npi.
sourceAddr - is the source_addr.
destAddrTon - is the dest_addr_ton.
destAddrNpi - is the dest_addr_npi.
destinationAddress - is destination_address.
Throws:
PDUException - if there is invalid PDU parameter found.
ResponseTimeoutException - if timeout has been reach.
InvalidResponseException - if response is invalid.
NegativeResponseException - if negative response received.
java.io.IOException - if there is an I/O error found.

getMessageReceiverListener

public MessageReceiverListener getMessageReceiverListener()
Description copied from interface: ClientSession
Get the current message receiver listener that is currently registered for this smpp session.

Specified by:
getMessageReceiverListener in interface ClientSession
Returns:
The current message receiver listener

setMessageReceiverListener

public void setMessageReceiverListener(MessageReceiverListener messageReceiverListener)
Description copied from interface: ClientSession
Sets a message receiver listener for this smpp session.

Specified by:
setMessageReceiverListener in interface ClientSession
Parameters:
messageReceiverListener - is the new listener

connection

protected Connection connection()
Specified by:
connection in class AbstractSession

sessionContext

protected AbstractSessionContext sessionContext()
Specified by:
sessionContext in class AbstractSession

messageReceiverListener

protected GenericMessageReceiverListener messageReceiverListener()
Specified by:
messageReceiverListener in class AbstractSession

close

public void close()
Description copied from interface: Session
Forced close connection without sending UNBIND command to Message Center.

Specified by:
close in interface Session
Overrides:
close in class AbstractSession

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

fireAcceptDeliverSm

private void fireAcceptDeliverSm(DeliverSm deliverSm)
                          throws ProcessRequestException
Throws:
ProcessRequestException

fireAcceptAlertNotification

private void fireAcceptAlertNotification(AlertNotification alertNotification)