twitter-archive / cloudhopper-smpp

Efficient, scalable, and flexible Java implementation of the Short Messaging Peer to Peer Protocol (SMPP)
Other
381 stars 357 forks source link

Low-level PDU listener #57

Closed t3hk0d3 closed 10 years ago

t3hk0d3 commented 10 years ago

I've met task where i have to send enquire link request only after specified time from any last PDU received. There is only way with overriding DefaultSMPPSession and DefaultSMPPClient, hooking up to firePduReceived method, because SmppSessionHandler misses PDU's sent through WindowFuture.

So i came with solution for low-level hooks for PDU being received or sent. Bonus is you can discard received/sent PDU from further processing/dispatching.

For example this would be handy if you have your own PDU processing pipeline.

stela commented 10 years ago

I like the idea :-)

In order to log all PDUs sent and received in a a custom format I did something similar (without cloudhopper-smpp modifications), through overriding DefaultSmppClient.createSession() and adding a Netty handler after the "smppSessionPduDecoder".

PDUs received are "Pdu" class instances, while PDUs sent are seen as ChannelBuffer instances. The ChannelBuffer instances then have to be transcoded back to a Pdu to be parsed, not very elegant but it works.

Wouldn't it be more clean to delegate DefaultSmppSession's netty channel writing out to a separate class doing just that, with a single method to write a Pdu? The delegate should be possible to replace/extend. Reading is currently done by SmppSessionWrapper (a Netty ChannelHandler) which notifies of incoming PDUs and closed channels. SmppSessionWrapper is nice, but creation is hardcoded by "new SmppSessionWrapper()" in various difficult to override places, would be better if instances could be injected or were retrieved from an injectable factory to allow for customization.

t3hk0d3 commented 10 years ago

@stela Hooking up into Netty's pipelines is imho kinda bad idea. It ruins abstraction.

jjlauer commented 10 years ago

This is a useful feature for sure. I appreciate the quality of the implementation you provided.

This would be great to promote in the demos as well -- could you submit another pull request that adds/modifies one of the demos to show how you can log/discard, etc?