Hi Adam,

You cannot reuse the Builder instance, you can reuse the result from the
.build() call though. The builder has mutable state inside so it is not
meant to be reused.

-Endre

On Mon, Jun 1, 2015 at 11:45 AM, Adam Daines <[email protected]> wrote:

> Hi,
>
> I have been making use of the ReceiveBuilder for a short amount of time to
> control the receive logic for my actors.  I was storing an instance of the
> ReceiveBuilder in a variable and then passing it into a method to attach
> some further "match" clauses before building it and the actor "becoming
> it". This all worked perfectly fine and any received messages were handled
> correctly.
>
> However, if the above process occurred and then was triggered again with a
> different instance of the ReceiveBuilder (stored in a separate variable) it
> would change to the receive logic defined in the second variable but then
> be unable to change back to the original variables logic. I.e. it appears
> that the original ReceiveBuilder variable cannot be reused.
>
> We have worked around this issue currently by simply making a getter
> method that provides a new instance of the ReceiveBuilder each time it is
> required but would like some clarity as to the reasoning why the original
> approach did not work.
>
> Simple example : At the end of "changeReceiveLogic" running it would be
> expected that the example actor would be able to handle
> LoadingMessage.class and run processLoadingMessage but it does not.
>
>
>     private UnitPFBuilder<Object> RECEIVE_WHEN_LOADING
>             = ReceiveBuilder
>             .match(LoadingMessage.class, this::processLoadingMessage);
>
>     private UnitPFBuilder<Object> RECEIVE_WHEN_READY
>             = ReceiveBuilder
>             .match(ReadyMessage.class, this::processReadyMessage);
>
>     private void completeReceiveBuilderAndBecome(final
> UnitPFBuilder<Object> receiveLogic) {
>            getContext().become(receiveLogic
>                 .match(GenericMessage.class, this::processGenericMessage)
>                 .build());
>     }
>
>     private void changeReceiveLogic(){
>           completeReceiveBuilderAndBecome(RECEIVE_WHEN_LOADING);
>           completeReceiveBuilderAndBecome(RECEIVE_WHEN_READY);
>           completeReceiveBuilderAndBecome(RECEIVE_WHEN_LOADING);
>     }
>
> Thanks,
>
> Adam
>
>  --
> >>>>>>>>>> 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.
>



-- 
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

-- 
>>>>>>>>>>      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