Isn't that *"pure chance"* the fact that I'm calling context() before that 
declaration *-at the constructor of the outer class-* and as a side effect 
the context is already initialized?, What if I extract the context as a 
final variable before the anonymous declaration?
Wouldn't that eliminate the pure chance to an already initialized context?

The reason for me doing that is because I want to maximize my parallelism 
and message delivery intermediaries by just passing the message to an actor 
that should exist, the self() actor I want to do only what it is meant to 
do,
which is why my actors are using SingleConsumerOnlyMailbox.

On Friday, June 5, 2015 at 6:28:39 PM UTC+1, Guido Medina wrote:
>
> 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/
>>>>>>>>>>      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 akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
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