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

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.
 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()
           
 MessageReceiverListener getMessageReceiverListener()
           
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.
protected  AbstractSessionContext sessionContext()
           
 void setMessageReceiverListener(MessageReceiverListener messageReceiverListener)
           
 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, close, dataShortMessage, executeSendCommand, fireAcceptDataSm, getEnquireLinkTimer, getLastActivityTimestamp, getPduProcessorDegree, getSessionId, getSessionState, getTransactionTimer, 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, close, dataShortMessage, getEnquireLinkTimer, getLastActivityTimestamp, getSessionId, getSessionState, getTransactionTimer, removeSessionStateListener, setEnquireLinkTimer, setTransactionTimer, unbindAndClose
 

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.

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.

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.

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.

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.

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

setMessageReceiverListener

public void setMessageReceiverListener(MessageReceiverListener messageReceiverListener)

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

finalize

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