jflanigan
Mar 2nd, 2010, 04:44 PM
I am in the process of implementing a basic socket listener service. This listener will accept connections on a server socket, read a message from the InputStream of the 'accept' socket, process the message through a series of channels, and eventually write a response to the OutputStream of the same socket. Content of the channels aside, this will behave more or less like a echo server.
I am considering several approaches and would appreciate any feedback.
Option 1) Implement listener as a standalone component (i.e. not associated with a channel). The listener would read the incoming message and then pass it through a gateway. The response would eventually be returned through the gateway. The integration layer would deal only with Strings and/or byte[]'s and have no direct relationship with the socket.
Option 2) Leverage the socket support which is planned for 2.0: http://forum.springsource.org/showthread.php?t=80814. I looked through the code on trunk for this and I see how it would be used to either send or receive messages. However, I don't see a clear way to return a response to any of the various implementations of AbstractInternetProtocolReceivingChannelAdapter. Am I missing something, or does this fall outside the intended usage?
Option 3) Provide a method in the listener to use as the MessageSource of SourcePollingChannel (i.e. <inbound-channel-adapter>), and provide a separate method which would be invoked by a <service-activator> to send the reply back to the original socket. Since the listener will handle multiple connections, a Map or something similar would be used to ensure that the response is sent to the correct socket. This seems rather messy, and might just indicate that I am missing something in option 2.
From here, option 1 seems like the most straightforward way to accomplish this.
Thanks!
I am considering several approaches and would appreciate any feedback.
Option 1) Implement listener as a standalone component (i.e. not associated with a channel). The listener would read the incoming message and then pass it through a gateway. The response would eventually be returned through the gateway. The integration layer would deal only with Strings and/or byte[]'s and have no direct relationship with the socket.
Option 2) Leverage the socket support which is planned for 2.0: http://forum.springsource.org/showthread.php?t=80814. I looked through the code on trunk for this and I see how it would be used to either send or receive messages. However, I don't see a clear way to return a response to any of the various implementations of AbstractInternetProtocolReceivingChannelAdapter. Am I missing something, or does this fall outside the intended usage?
Option 3) Provide a method in the listener to use as the MessageSource of SourcePollingChannel (i.e. <inbound-channel-adapter>), and provide a separate method which would be invoked by a <service-activator> to send the reply back to the original socket. Since the listener will handle multiple connections, a Map or something similar would be used to ensure that the response is sent to the correct socket. This seems rather messy, and might just indicate that I am missing something in option 2.
From here, option 1 seems like the most straightforward way to accomplish this.
Thanks!