Hi Guido,

what you are doing is working with current Akka versions by pure chance. The 
correct solution (that will keep working :-) ) would be to send the Message to 
the getSelf() reference from within fromApp() and then forward to the 
orderPersistor if it exists. Preferably you would make a named subclass of 
FixInitiator that takes an additional ActorRef argument for this purpose 
instead of defining a local class within the Actor—the latter is fraught with 
dangers of the kind we are discussing (e.g. the use of unhandled() looks wrong 
as well).

Regards,

Roland

> 5 jun 2015 kl. 19:28 skrev Guido Medina <[email protected]>:
> 
> Hi,
> 
> I have the following method which creates a FixInitiator which is part of 
> another multi-threaded framework I have no control, the client is started 
> inside an actor which its children are named and located by a generated UUID.
> 
> I have read that passing the context to another thread is not safe but when 
> you look at the Scala code, the context is lazily initialized, if it was 
> initialized already, doesn't that make this code OK?
> 
> The method fromApp(...) is re-actively called back from another thread when a 
> FIX message comes into the system, so far this is working for me without any 
> issues, but maybe it is because I have called context() already for this 
> actor before I reach the anonymous class declaration at the preStart() method?
> 
> Note: The call to super.preStart() is because the actor is inheriting from 
> another Abstract type of actor with some template methods pattern.
>  
>   @Override
>   public void preStart() throws Exception {
>     initiator = new FixInitiator(entity, log, "order") {
>       @Override
>       public void fromApp(Message message, SessionID sessionId) throws 
> FieldNotFound {
>         if (message instanceof ExecutionReport) {
>           final String uuid = message.getString(ClOrdID.FIELD);
>           final Option<ActorRef> orderPersistor = context().child(uuid);
>           if (orderPersistor.isDefined()) {
>             orderPersistor.get().tell(message, noSender());
>           } else {
>             log.error("Order persistor for " + uuid + " doesn't exist or has 
> expired");
>           }
>         } else {
>           unhandled(message);
>         }
>       }
>     };
>     initiator.start();
>     super.preStart();
>   }
> 
> 
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/ <http://akka.io/docs/>
> >>>>>>>>>> Check the FAQ: 
> >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html 
> >>>>>>>>>> <http://doc.akka.io/docs/akka/current/additional/faq.html>
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user 
> >>>>>>>>>> <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] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/akka-user 
> <http://groups.google.com/group/akka-user>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe <http://typesafe.com/> – Reactive apps on the JVM.
twitter: @rolandkuhn
 <http://twitter.com/#!/rolandkuhn>

-- 
>>>>>>>>>>      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 http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to