Hello,
I’m a complete newbie in Scala and Akka, and now trying to implement some
project which involves usage of a third-party Java library.
The Java API includes creation of some objects and at some point starting
to listen for events from them. So, without using Akka and Actors, the
code(in Java) would look like:
EndPoint myEndpoint = EndPont.BuildNewOne(myPipeLine);
myEndpoint.addListener(new EventListener<EPEvent>() {
@Override
public void onEvent(EPEvent event) {
handleEvent(event, session);
}
});
Now using Scala and Akka Actors, I have something like:
class EndpointProcessor extends Actor{
…..
override def receive: Receive = {
case m:EndPointCreated =>
val myEndPoint = m.endPoint
myEndPoint.addListener(new EventListener[EPEvent]{
override def onEvent(event:EPEvent)={
handleEvent(event, session)
}
}
……
However, this literal translation looks very scary: naturally, the event
producer knows nothing about my life with Akka and Actors, and actually I
need to bridge it somehow to my world. But I don’t understand how to do it.
I could try to save self()(or some other event processor’s ActorRef) in the
listener object and send the event to this ActorRef(replacing handleEvent
call by "eventProcessor ! EventArrival(event)", but... does it make any
sense outside of our execution context? If it was about static event
subscription, I could create my event-processing Actor right on start, on
the top level, using the main ActorSystem, then store the ActorRef, and
this(probably) would work.
But now I'm inside my EndpointProcessor Actor. Well, I could do the same
using context.system. However, this looks ugly and I prefer
EventProcessorActor to be a child of EndpointProcessor — but then, again,
I’m not sure whether it is OK to store ActorRef inside non-actor
EventListener object — and probably it is not, because of third-party
calling thread for onEvent().
On the other hand, the task(subscribe on the fly to third-party events
outside of Akka) looks pretty standard, and I’m probably just inventing a
wheel due to my own ignorance. I’ve tried to search in Akka docs, but
couldn't find something relevant, or maybe just missed it. Should I check
Streams more thoroughly?
Please advise or point me to some proper RTFM subsection.
TIA
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.