public class MayReuseSessionStrategy extends BaseSessionHandlingStrategy implements ErrorHandler
When sending the first message, a new session is created. Later, when sending
the next message, if the session is still alive, this session is reused. As
the connection is not actively maintained, the session may be killed by the
server. Therefore to check if the session is still alive, an
EnquireLink
request is sent. If a response is received from the
server, then the session is still alive and the message can be sent using the
same session. If a failure response or no response is received after some
time from the server, then a new session must be created.
To check if the session is still alive, the EnquireLink
request is
sent just before sending the real message. In order to prevent sending an
EnquireLink
request before every message, the date
of the last sent message or EnquireLink
is kept. This date is
compared to a delay to ensure that no EnquireLink
is sent during this
delay.
clientSupplier, configuration, currentClient, currentSession, logger, retry, smppSessionHandlerSupplier
Constructor and Description |
---|
MayReuseSessionStrategy(ExtendedSmppSessionConfiguration configuration,
SmppClientSupplier clientSupplier,
SmppSessionHandlerSupplier smppSessionHandlerSupplier,
RetryExecutor retry,
ErrorAnalyzer errorAnalyzer) |
Modifier and Type | Method and Description |
---|---|
void |
clean()
Clean all the opened resources before destruction.
|
protected com.cloudhopper.smpp.SmppSession |
connect(com.cloudhopper.smpp.SmppClient client)
Connect the client to the SMSC using a
SmppClient.bind(com.cloudhopper.smpp.SmppSessionConfiguration, com.cloudhopper.smpp.SmppSessionHandler)
request. |
com.cloudhopper.smpp.SmppSession |
getSession()
The client needs a session to be able to send the message.
|
void |
handleFailure(Throwable e)
Handle an error.
|
void |
messageNotSent(Sms sms,
SmppException e)
Fired when the message couldn't be sent due to an error.
|
void |
messageProcessed(Sms sms)
Fired when a message has been processed i.e.
|
void |
messageSent(Sms sms)
Fired when a message has been sent successfully.
|
destroyClient, destroySession, initClient, initSession
public MayReuseSessionStrategy(ExtendedSmppSessionConfiguration configuration, SmppClientSupplier clientSupplier, SmppSessionHandlerSupplier smppSessionHandlerSupplier, RetryExecutor retry, ErrorAnalyzer errorAnalyzer)
public com.cloudhopper.smpp.SmppSession getSession() throws SmppException
SessionHandlingStrategy
Either create a new session or use an existing one.
getSession
in interface SessionHandlingStrategy
SmppException
- when the session can't be created (connection failure)public void messageSent(Sms sms) throws MessageException
SessionHandlingStrategy
messageSent
in interface SessionHandlingStrategy
sms
- the sent SMSMessageException
- when something happens during handling of message successpublic void messageNotSent(Sms sms, SmppException e) throws MessageException
SessionHandlingStrategy
messageNotSent
in interface SessionHandlingStrategy
sms
- the SMS that couldn't be sente
- the raied error while sendingMessageException
- when something happens during handling of message errorpublic void handleFailure(Throwable e)
ErrorHandler
handleFailure
in interface ErrorHandler
e
- the error to handlepublic void messageProcessed(Sms sms)
SessionHandlingStrategy
This method is always called after SessionHandlingStrategy.messageSent(Sms)
and
SessionHandlingStrategy.messageNotSent(Sms, SmppException)
.
No exception should be thrown because this is used to end the process.
messageProcessed
in interface SessionHandlingStrategy
sms
- the sent SMSpublic void clean()
Cleanable
Generally, this method is called only once per instance. But there may exist some cases where the method is called several times.
The implementation should ensure that if the method is called several times, the first time cleans the resources and the other calls doesn't do anything.
protected com.cloudhopper.smpp.SmppSession connect(com.cloudhopper.smpp.SmppClient client) throws SmppException
BaseSessionHandlingStrategy
SmppClient.bind(com.cloudhopper.smpp.SmppSessionConfiguration, com.cloudhopper.smpp.SmppSessionHandler)
request.
The configured retry strategy is used to send the bind request to the server i.e. several attempts may be done.
connect
in class BaseSessionHandlingStrategy
client
- the client used to send to bind commandSmppException
- when the session couldn't be boundCopyright © 2021. All rights reserved.