0
votes

I am writing a TCP client server program using Scala/Akka. Some of the actors on server side need to process TCP messages coming clients. I have used(copied) code that basically parses the received TCP messages and on reception on a delimiter character the message is sent to someone else.

since more than one actor uses this logic, I had abstracted it in baseTCP actor and inherited other actors from this. I would like to add common code such as handling of Bound/Connected/CommandFailed etc in this base actor. Is this kind of handling ok in Akka? Or is it discouraged? best regards, Vishal

1
When you say inherit, you mean traits or actual extension?Diego Martinoia
I did an actual extension and not using traitvishal
If you are extracting individual capabilities, I suggest (since you are in Scala) to look into traits rather than extensions: they mix nicer (and you can have multiple, which is what you seem to want?)Diego Martinoia

1 Answers

0
votes

Yes that is possible and one example that adhere to what you describe is PersistentActor. http://doc.akka.io/api/akka/2.3.4/#akka.persistence.PersistentActor which is a Subtype of Actor.

On my past company, we abstract more PersistentActor by extending it to have HashMap as state and some defined lifecycle state (like open, close, waitingForAck, termination).