com.davesag.smpp
Class AbstractSMPPCommander

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.davesag.smpp.AbstractSMPPCommander
All Implemented Interfaces:
ie.omk.smpp.event.ConnectionObserver, Runnable, SMPPCommander

public abstract class AbstractSMPPCommander
extends Thread
implements ie.omk.smpp.event.ConnectionObserver, SMPPCommander

A base for your implimentation of a SMPPCommander.

NOTE: this implimentation is currently very simple and only runs against a simulator. I have not added any but the most basic of event handling and could possibly extend ie.omk.smpp.event.SMPPEventAdapter and fill in the methods accordingly. But for now this works and I see no reason why it shouldn't work against an actual service. I may need to refine the error handling slightly.


Nested Class Summary
 class AbstractSMPPCommander.CloseHook
          this thread is attached to the system as a system shutdownHook.
 
Nested classes inherited from class com.davesag.smpp.SMPPCommander
SMPPCommander.Factory
 
Field Summary
protected  ie.omk.smpp.Connection theConnection
          The connection to the SMPP server
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractSMPPCommander()
           
 
Method Summary
protected  void bind()
          bind the connection once it has been connected.
protected abstract  void cleanup()
          Application specific post-command processing cleanup.
protected  void connect()
          Connect to the SMPP server.
 ie.omk.smpp.Connection getConnection()
          accessor for the connection to the SMPP server.
protected abstract  void logCommand(Command command, Response response)
          Application specific command logging.
protected abstract  void logCommandFormatException(CommandFormatException cfex, ErrorResponse response)
          Application specific command logging of invalid commands.
protected  void logPacket(ie.omk.smpp.message.SMPPPacket packet, String direction)
          log the packet details.
 void packetReceived(ie.omk.smpp.Connection conn, ie.omk.smpp.message.SMPPPacket pack)
          Connection Observer method that is called when a packet is sent to us.
protected  ie.omk.smpp.message.SubmitSM processRequest(ie.omk.smpp.message.SMPPPacket request)
          Process the request using the CommandFactory class you specify with the property sms.command.factory in smpp_commander.properties.
 void run()
          keep us connected to the SMPP server.
protected  ie.omk.smpp.message.SubmitSM submitResponse(Response response)
          prepare the response as a submission to the SMPP server.
 void update(ie.omk.smpp.Connection conn, ie.omk.smpp.event.SMPPEvent ev)
          Connection Observer method that handles any events other than incoming requests.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.davesag.smpp.SMPPCommander
start
 

Field Detail

theConnection

protected ie.omk.smpp.Connection theConnection
The connection to the SMPP server

Constructor Detail

AbstractSMPPCommander

public AbstractSMPPCommander()
Method Detail

logCommand

protected abstract void logCommand(Command command,
                                   Response response)
Application specific command logging. You must override this to supply implimentation specific command logging.

Parameters:
command - The command to log.
response - The response to log.

logCommandFormatException

protected abstract void logCommandFormatException(CommandFormatException cfex,
                                                  ErrorResponse response)
Application specific command logging of invalid commands. You must override this to supply implimentation specific command logging.

Parameters:
cfex - The exception carrying details of the invalid command.
response - The error response.

cleanup

protected abstract void cleanup()
Application specific post-command processing cleanup. You must override this to supply implimentation specific cleanup.


run

public void run()
keep us connected to the SMPP server.

Specified by:
run in interface Runnable

update

public void update(ie.omk.smpp.Connection conn,
                   ie.omk.smpp.event.SMPPEvent ev)
Connection Observer method that handles any events other than incoming requests.

Specified by:
update in interface ie.omk.smpp.event.ConnectionObserver
Parameters:
conn - The connection to the SMPP server.
ev - The event.

packetReceived

public void packetReceived(ie.omk.smpp.Connection conn,
                           ie.omk.smpp.message.SMPPPacket pack)
Connection Observer method that is called when a packet is sent to us.

Specified by:
packetReceived in interface ie.omk.smpp.event.ConnectionObserver
Parameters:
conn - The connection to the SMPP server
pack - The packet of data sent.

getConnection

public ie.omk.smpp.Connection getConnection()
accessor for the connection to the SMPP server.

Specified by:
getConnection in interface SMPPCommander
Returns:
a connection to the SMPP server.

connect

protected void connect()
Connect to the SMPP server.


bind

protected void bind()
bind the connection once it has been connected. will retry indefinately. called from connect().


processRequest

protected ie.omk.smpp.message.SubmitSM processRequest(ie.omk.smpp.message.SMPPPacket request)
                                               throws ie.omk.smpp.BadCommandIDException
Process the request using the CommandFactory class you specify with the property sms.command.factory in smpp_commander.properties. The processing follows the following lifecycle.
  1. we create a command object using the supplied command factory.
  2. if it's not valid we generate an error response, else
  3. we perform the command and thus obtain a response.
  4. we log the command and response.
  5. If the command string received is junk then we catch a CommandFormatException and log the excpetion and response.
  6. finally we submit the response and cleanup.

Parameters:
request - The incoming SMPP packet.
Returns:
the response to send back to the SMPP server.
Throws:
ie.omk.smpp.BadCommandIDException - if the command in the request was crap.

submitResponse

protected ie.omk.smpp.message.SubmitSM submitResponse(Response response)
                                               throws ie.omk.smpp.BadCommandIDException
prepare the response as a submission to the SMPP server.

Parameters:
response - The response to submit.
Returns:
the packaged up response to the SMPP server.
Throws:
ie.omk.smpp.BadCommandIDException

logPacket

protected void logPacket(ie.omk.smpp.message.SMPPPacket packet,
                         String direction)
log the packet details.

Parameters:
packet - The SMPP packet to log
direction - One of IN or OUT.


SMPP Commander API version 20 Jan 2005. (C) 2004 Dave Sag.