I'm just starting out with NIO and I'm not quite sure I understand the architecture completely.
I'm writing a dummy SMTP server to be used in testing and developing programs that work with email. I get the idea of a pipeline of channel handlers, for processing a single event. I even get how channel handlers are supposed to be stateless, just working on the data that's coming in on the event they're handed. But I'm a bit confused about where in this whole system the persistent state is supposed to live.
For instance, an SMTP session might look like:
Client: connects to server
Server: "I'm a server, and I'm in the CONNECT state"
Client: "Hi, server, I'm Joe Client."
Server: "Hi, Joe, I'm ready to hear more from you."
Client: "Let's authenticate"
Server: "Sure thing. I am now in the AUTHENTICATE state"
Client: "Have some credentials."
Server: "Awesome. I am now in the COMMAND state"
Client: "Let's authenticate"
Server: "Nope, we did that already."
I get how a ChannelHandler
on the server could see an incoming string of AUTH base64gobbledegook
and figure out a response, but how can it know that such an event has already come through on this session?
I've seen some examples and simple tutorials that keep track of channels by the originating address, but what about a situation where there are multiple clients at the same address? For example, two different scripts running test suites, each of which might connect to the server? Originating IP address isn't granular enough.
So, is there something like a dictionary hanging around where I can say, "Please give me the stored state object for the current connection?"