TcpClient where store protocol conversation state

78 views
Skip to first unread message

jszczepa...@gmail.com

unread,
Sep 4, 2013, 4:18:39 PM9/4/13
to akka...@googlegroups.com
Hi,
I am writing simple TCP server using akka (2.2 and new IO), I am starting with akka so excuse me if I am asking some obvious things. I have a small problem where to store the conversation state with individual client connected to server. Every conversation changes its state independently from each client. Given the example:
I have the following questions: 

1. Am I wright that conversation state (related to state of the session communication with specific client according to the custom protocol) should be stored in SimplisticHandler.class if not then where?
2. I am using the following snipped:
(...)
 init = TcpPipelineHandler.withLogger(log, sequence(sequence(sequence(
                    new StringByteStringAdapter("utf-8"),
                    new DelimiterFraming(1024, ByteString.fromString("\n"), true)),
                    new TcpReadWriteAdapter()),
                    new BackpressureBuffer(1000, 10000, 1000000)));
(...)
Should I keep this init object exclusiveliy for each session (SimplisticHandler actor instance)? 

PS. Akka is cool :)

Thanks,
Jarek

Björn Antonsson

unread,
Sep 5, 2013, 8:32:11 AM9/5/13
to Akka User List
Hi Jarek,

On Wednesday, 4 September 2013 at 22:18, jszczepa...@gmail.com wrote:

Hi,
I am writing simple TCP server using akka (2.2 and new IO), I am starting with akka so excuse me if I am asking some obvious things. I have a small problem where to store the conversation state with individual client connected to server. Every conversation changes its state independently from each client. Given the example:
I have the following questions: 

1. Am I wright that conversation state (related to state of the session communication with specific client according to the custom protocol) should be stored in SimplisticHandler.class if not then where?

You are right that the conversation state should be in the "handler" actor.
 
2. I am using the following snipped:
(...)
 init = TcpPipelineHandler.withLogger(log, sequence(sequence(sequence(
                    new StringByteStringAdapter("utf-8"),
                    new DelimiterFraming(1024, ByteString.fromString("\n"), true)),
                    new TcpReadWriteAdapter()),
                    new BackpressureBuffer(1000, 10000, 1000000)));
(...)
Should I keep this init object exclusiveliy for each session (SimplisticHandler actor instance)? 


Yes, right again. You should create a new TcpPipelineHandler.Init for each "handler" actor.
 
B/

PS. Akka is cool :)

Thanks,
Jarek

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.

-- 
Björn Antonsson
Typesafe – Reactive Apps on the JVM
twitter: @bantonsson

jszczepa...@gmail.com

unread,
Sep 5, 2013, 2:00:49 PM9/5/13
to akka...@googlegroups.com
Thank you for answer, 
how then should I understand the example "Usage Example: TcpPipelineHandler and SSL" from:
there is one field on the server class (which I believe is in one instance per whole process):
Init<WithinActorContext, String, String> init

and every time there is new client then the class field init (Init<...>) is filled with new TcpPipelineHandler instance. This handler is passed to newly created Handler class (one per listener). During the lifecycle of the server class this will hold only the "newly created" TcpPipelineHandler? Why it is not a local variable but instance variable (with onReceive method scope) access to class field is from slower heap and not stack I believe so this is defintely not because of some perfomance benefit?
Thanks in advance,
Jarek

Björn Antonsson

unread,
Sep 5, 2013, 2:59:55 PM9/5/13
to Akka User List
Hi Jarek,
You are right that it's an instance field and that it's overwritten on every new connect with the newly created init. The example is somewhat contrived since it sets the server actor as the handler for the SSL connection, and then uses the same init variable later to unwrap the message from the pipeline. There could have been multiple connects in between which would overwrite init. The example should be a bit more real with a separate handler.

I've created a ticket to fix the documentation here:

If you think you could contribute a fix yourself, you are more than welcome. Just follow these guidelines:

B/

jszczepa...@gmail.com

unread,
Sep 8, 2013, 2:57:08 PM9/8/13
to akka...@googlegroups.com
Ok, I will try to do this little contribution to the doc :),

Regards,
Jarek

Björn Antonsson

unread,
Sep 9, 2013, 3:58:35 AM9/9/13
to akka...@googlegroups.com
Thanks Jarek,

Best of luck. Looking forward to the pull request.

B/

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages