[akka-user] Accessing Future's onComplete Internal variables
Hi, I wanted to ask if there is any way to map the internal variables to the external java ones. For instance, for the following method String testVar=null; future.onComplete(new OnComplete(){ public void onComplete(Throwable t, Object result){ testVar=(String) result; } }, ec); I have tried the following method to get the results by calling onSuccess future.onComplete(new OnComplete(){ public void onComplete(Throwable t, Object result){ return result; } }, ec); future.onSuccess(new Result(), ec); However I am kept on getting the error (cannot cast the Result class to a partial function ). Cheers -- >> 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.
Re: [akka-user] Accessing Future's onComplete Internal variables
Hi Syd, your code samples are not valid Java (well, the first one could be if testVar would be a field, but that's unsafe instead maybe use `AtomicReference` and `set` it from the completion?). OnComplete has a `void` method so you cannot return from it. Instead of taking things out of the future like this you can either: 1) keep mapping (transfroming the value): future.map(new Function1(){ @Override public Object apply(Object v1) { return null; } }, ec); never getting out of this transformation - this way you can chain all transformations you need. 2) Await on the result of the future (*we discourage this*) as it will block the thread that you're calling await from: Future future = null; Object o = scala.concurrent.Await.result(future, Duration.apply(100, TimeUnit.DAYS)) Hope this helps, happy hakkionmg! On Mon, Nov 17, 2014 at 11:36 AM, Syd Gillani wrote: > Hi, > > I wanted to ask if there is any way to map the internal variables to the > external java ones. For instance, for the following method > > String testVar=null; > > > future.onComplete(new OnComplete(){ > public void onComplete(Throwable t, Object result){ > > testVar=(String) result; > > } > }, ec); > > > I have tried the following method to get the results by calling onSuccess > > future.onComplete(new OnComplete(){ > public void onComplete(Throwable t, Object result){ > >return result; > > } > }, ec); > > > future.onSuccess(new Result(), ec); > > > However I am kept on getting the error (cannot cast the Result class to a > partial function ). Cheers > > > > -- > >> 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. > -- Cheers, Konrad 'ktoso' Malawski hAkker @ Typesafe -- >> 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.
Re: [akka-user] Accessing Future's onComplete Internal variables
Thanks Konrad, The issue with the mapping is that I won't be able to send the results to an external class -- that is exactly my case. I need to send the result of the future to an external class which will perform some other computation and so. I knew about the await method, but as It is described in the documentation (not a preferred approach ), so I was hesitant to use it. Cheers Syd On Monday, 17 November 2014 12:10:16 UTC+1, Konrad Malawski wrote: > > Hi Syd, > your code samples are not valid Java (well, the first one could be if > testVar would be a field, but that's unsafe instead maybe use > `AtomicReference` and `set` it from the completion?). > OnComplete has a `void` method so you cannot return from it. > > Instead of taking things out of the future like this you can either: > 1) keep mapping (transfroming the value): > > future.map(new Function1(){ > @Override public Object apply(Object v1) { > return null; > } > }, ec); > > never getting out of this transformation - this way you can chain all > transformations you need. > > 2) Await on the result of the future (*we discourage this*) as it will > block the thread that you're calling await from: > > Future future = null; > Object o = scala.concurrent.Await.result(future, Duration.apply(100, > TimeUnit.DAYS)) > > > Hope this helps, happy hakkionmg! > > On Mon, Nov 17, 2014 at 11:36 AM, Syd Gillani > wrote: > >> Hi, >> >> I wanted to ask if there is any way to map the internal variables to the >> external java ones. For instance, for the following method >> >> String testVar=null; >> >> >> future.onComplete(new OnComplete(){ >> public void onComplete(Throwable t, Object result){ >> >> testVar=(String) result; >> >> } >> }, ec); >> >> >> I have tried the following method to get the results by calling onSuccess >> >> future.onComplete(new OnComplete(){ >> public void onComplete(Throwable t, Object result){ >> >>return result; >> >> } >> }, ec); >> >> >> future.onSuccess(new Result(), ec); >> >> >> However I am kept on getting the error (cannot cast the Result class to a >> partial function ). Cheers >> >> >> >> -- >> >> 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+...@googlegroups.com . >> To post to this group, send email to akka...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/akka-user. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Cheers, > Konrad 'ktoso' Malawski > hAkker @ Typesafe > > > -- >> 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.
Re: [akka-user] Accessing Future's onComplete Internal variables
Have you looked into our pipeTo pattern? It allows to send the result of a Future to an Actor, without having to block on the result: import static akka.pattern.Patterns.pipe; final ActorRef alice = ???; final Future future = ???; pipe(future, ec).to(alice); Alice can receive the value and do things with it. More info in the docs: http://doc.akka.io/docs/akka/2.3.7/java/untyped-actors.html#Ask__Send-And-Receive-Future -- k On Mon, Nov 17, 2014 at 12:22 PM, Syd Gillani wrote: > Thanks Konrad, > The issue with the mapping is that I won't be able to send the results to > an external class -- that is exactly my case. I need to send the result of > the future to an external class which will perform some other computation > and so. > I knew about the await method, but as It is described in the documentation > (not a preferred approach ), so I was hesitant to use it. Cheers > > Syd > > > > > On Monday, 17 November 2014 12:10:16 UTC+1, Konrad Malawski wrote: >> >> Hi Syd, >> your code samples are not valid Java (well, the first one could be if >> testVar would be a field, but that's unsafe instead maybe use >> `AtomicReference` and `set` it from the completion?). >> OnComplete has a `void` method so you cannot return from it. >> >> Instead of taking things out of the future like this you can either: >> 1) keep mapping (transfroming the value): >> >> future.map(new Function1(){ >> @Override public Object apply(Object v1) { >> return null; >> } >> }, ec); >> >> never getting out of this transformation - this way you can chain all >> transformations you need. >> >> 2) Await on the result of the future (*we discourage this*) as it will >> block the thread that you're calling await from: >> >> Future future = null; >> Object o = scala.concurrent.Await.result(future, Duration.apply(100, >> TimeUnit.DAYS)) >> >> >> Hope this helps, happy hakkionmg! >> >> On Mon, Nov 17, 2014 at 11:36 AM, Syd Gillani >> wrote: >> >>> Hi, >>> >>> I wanted to ask if there is any way to map the internal variables to the >>> external java ones. For instance, for the following method >>> >>> String testVar=null; >>> >>> >>> future.onComplete(new OnComplete(){ >>> public void onComplete(Throwable t, Object result){ >>> >>> testVar=(String) result; >>> >>> } >>> }, ec); >>> >>> >>> I have tried the following method to get the results by calling onSuccess >>> >>> future.onComplete(new OnComplete(){ >>> public void onComplete(Throwable t, Object result){ >>> >>>return result; >>> >>> } >>> }, ec); >>> >>> >>> future.onSuccess(new Result(), ec); >>> >>> >>> However I am kept on getting the error (cannot cast the Result class to >>> a partial function ). Cheers >>> >>> >>> >>> -- >>> >> 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+...@googlegroups.com. >>> To post to this group, send email to akka...@googlegroups.com. >>> Visit this group at http://groups.google.com/group/akka-user. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Cheers, >> Konrad 'ktoso' Malawski >> hAkker @ Typesafe >> >> >> -- > >> 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. > -- Cheers, Konrad 'ktoso' Malawski hAkker @ Typesafe -- >> 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.
Re: [akka-user] Accessing Future's onComplete Internal variables
Alright, but I would like to send the result to an API ( a method in an external class). Is there any way for it. Cheers Syd On Monday, 17 November 2014 12:35:42 UTC+1, Konrad Malawski wrote: > > Have you looked into our pipeTo pattern? It allows to send the result of a > Future to an Actor, without having to block on the result: > > import static akka.pattern.Patterns.pipe; > > > final ActorRef alice = ???; > final Future future = ???; > pipe(future, ec).to(alice); > > > Alice can receive the value and do things with it. > More info in the docs: > http://doc.akka.io/docs/akka/2.3.7/java/untyped-actors.html#Ask__Send-And-Receive-Future > > -- k > > On Mon, Nov 17, 2014 at 12:22 PM, Syd Gillani > wrote: > >> Thanks Konrad, >> The issue with the mapping is that I won't be able to send the results to >> an external class -- that is exactly my case. I need to send the result of >> the future to an external class which will perform some other computation >> and so. >> I knew about the await method, but as It is described in the >> documentation (not a preferred approach ), so I was hesitant to use it. >> Cheers >> >> Syd >> >> >> >> >> On Monday, 17 November 2014 12:10:16 UTC+1, Konrad Malawski wrote: >>> >>> Hi Syd, >>> your code samples are not valid Java (well, the first one could be if >>> testVar would be a field, but that's unsafe instead maybe use >>> `AtomicReference` and `set` it from the completion?). >>> OnComplete has a `void` method so you cannot return from it. >>> >>> Instead of taking things out of the future like this you can either: >>> 1) keep mapping (transfroming the value): >>> >>> future.map(new Function1(){ >>> @Override public Object apply(Object v1) { >>> return null; >>> } >>> }, ec); >>> >>> never getting out of this transformation - this way you can chain all >>> transformations you need. >>> >>> 2) Await on the result of the future (*we discourage this*) as it will >>> block the thread that you're calling await from: >>> >>> Future future = null; >>> Object o = scala.concurrent.Await.result(future, Duration.apply(100, >>> TimeUnit.DAYS)) >>> >>> >>> Hope this helps, happy hakkionmg! >>> >>> On Mon, Nov 17, 2014 at 11:36 AM, Syd Gillani >>> wrote: >>> Hi, I wanted to ask if there is any way to map the internal variables to the external java ones. For instance, for the following method String testVar=null; future.onComplete(new OnComplete(){ public void onComplete(Throwable t, Object result){ testVar=(String) result; } }, ec); I have tried the following method to get the results by calling onSuccess future.onComplete(new OnComplete(){ public void onComplete(Throwable t, Object result){ return result; } }, ec); future.onSuccess(new Result(), ec); However I am kept on getting the error (cannot cast the Result class to a partial function ). Cheers -- >> 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+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. >>> >>> >>> >>> -- >>> Cheers, >>> Konrad 'ktoso' Malawski >>> hAkker @ Typesafe >>> >>> >>> -- >> >> 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+...@googlegroups.com . >> To post to this group, send email to akka...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/akka-user. >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Cheers, > Konrad 'ktoso' Malawski > hAkker @ Typesafe > > > -- >> 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 unsubscri
Re: [akka-user] Accessing Future's onComplete Internal variables
You’ll have to block then. Consider using Actors instead if you can. — k On 17 November 2014 at 13:51:29, Syd Gillani (s.zeeshangill...@gmail.com) wrote: Alright, but I would like to send the result to an API ( a method in an external class). Is there any way for it. Cheers Syd On Monday, 17 November 2014 12:35:42 UTC+1, Konrad Malawski wrote: Have you looked into our pipeTo pattern? It allows to send the result of a Future to an Actor, without having to block on the result: import static akka.pattern.Patterns.pipe; final ActorRef alice = ???; final Future future = ???; pipe(future, ec).to(alice); Alice can receive the value and do things with it. More info in the docs: http://doc.akka.io/docs/akka/2.3.7/java/untyped-actors.html#Ask__Send-And-Receive-Future -- k On Mon, Nov 17, 2014 at 12:22 PM, Syd Gillani wrote: Thanks Konrad, The issue with the mapping is that I won't be able to send the results to an external class -- that is exactly my case. I need to send the result of the future to an external class which will perform some other computation and so. I knew about the await method, but as It is described in the documentation (not a preferred approach ), so I was hesitant to use it. Cheers Syd On Monday, 17 November 2014 12:10:16 UTC+1, Konrad Malawski wrote: Hi Syd, your code samples are not valid Java (well, the first one could be if testVar would be a field, but that's unsafe instead maybe use `AtomicReference` and `set` it from the completion?). OnComplete has a `void` method so you cannot return from it. Instead of taking things out of the future like this you can either: 1) keep mapping (transfroming the value): future.map(new Function1(){ @Override public Object apply(Object v1) { return null; } }, ec); never getting out of this transformation - this way you can chain all transformations you need. 2) Await on the result of the future (we discourage this) as it will block the thread that you're calling await from: Future future = null; Object o = scala.concurrent.Await.result(future, Duration.apply(100, TimeUnit.DAYS)) Hope this helps, happy hakkionmg! On Mon, Nov 17, 2014 at 11:36 AM, Syd Gillani wrote: Hi, I wanted to ask if there is any way to map the internal variables to the external java ones. For instance, for the following method String testVar=null; future.onComplete(new OnComplete(){ public void onComplete(Throwable t, Object result){ testVar=(String) result; } }, ec); I have tried the following method to get the results by calling onSuccess future.onComplete(new OnComplete(){ public void onComplete(Throwable t, Object result){ return result; } }, ec); future.onSuccess(new Result(), ec); However I am kept on getting the error (cannot cast the Result class to a partial function ). Cheers -- >> 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+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, Konrad 'ktoso' Malawski hAkker @ Typesafe -- >> 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+...@googlegroups.com. To post to this group, send email to akka...@googlegroups.com. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout. -- Cheers, Konrad 'ktoso' Malawski hAkker @ Typesafe -- >> 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. -- Konrad 'ktoso' Malawski hAkker @ typesafe http://akka.io -- >> Read the d
Re: [akka-user] Accessing Future's onComplete Internal variables
Why not call the method from within the map function? Instead of trying to get the result out of the Future, you can move more processing into the Future. On Mon Nov 17 2014 at 12:51:34 PM Syd Gillani wrote: > Alright, but I would like to send the result to an API ( a method in an > external class). Is there any way for it. Cheers > > > Syd > > > On Monday, 17 November 2014 12:35:42 UTC+1, Konrad Malawski wrote: > >> Have you looked into our pipeTo pattern? It allows to send the result of >> a Future to an Actor, without having to block on the result: >> >> import static akka.pattern.Patterns.pipe; >> >> >> final ActorRef alice = ???; >> final Future future = ???; >> pipe(future, ec).to(alice); >> >> >> Alice can receive the value and do things with it. >> More info in the docs: http://doc.akka.io/docs/akka/2.3.7/java/untyped- >> actors.html#Ask__Send-And-Receive-Future >> >> -- k >> > >> >> On Mon, Nov 17, 2014 at 12:22 PM, Syd Gillani >> wrote: >> >>> Thanks Konrad, >>> The issue with the mapping is that I won't be able to send the results >>> to an external class -- that is exactly my case. I need to send the result >>> of the future to an external class which will perform some other >>> computation and so. >>> I knew about the await method, but as It is described in the >>> documentation (not a preferred approach ), so I was hesitant to use it. >>> Cheers >>> >>> Syd >>> >>> >>> >>> >>> On Monday, 17 November 2014 12:10:16 UTC+1, Konrad Malawski wrote: Hi Syd, your code samples are not valid Java (well, the first one could be if testVar would be a field, but that's unsafe instead maybe use `AtomicReference` and `set` it from the completion?). OnComplete has a `void` method so you cannot return from it. Instead of taking things out of the future like this you can either: 1) keep mapping (transfroming the value): future.map(new Function1(){ @Override public Object apply(Object v1) { return null; } }, ec); never getting out of this transformation - this way you can chain all transformations you need. 2) Await on the result of the future (*we discourage this*) as it will block the thread that you're calling await from: Future future = null; Object o = scala.concurrent.Await.result(future, Duration.apply(100, TimeUnit.DAYS)) Hope this helps, happy hakkionmg! On Mon, Nov 17, 2014 at 11:36 AM, Syd Gillani wrote: > Hi, > > I wanted to ask if there is any way to map the internal variables to > the external java ones. For instance, for the following method > > String testVar=null; > > > future.onComplete(new OnComplete(){ > public void onComplete(Throwable t, Object result){ > > testVar=(String) result; > > } > }, ec); > > > I have tried the following method to get the results by calling > onSuccess > > future.onComplete(new OnComplete(){ > public void onComplete(Throwable t, Object result){ > >return result; > > } > }, ec); > > > future.onSuccess(new Result(), ec); > > > However I am kept on getting the error (cannot cast the Result class > to a partial function ). Cheers > > > > -- > >> Read the docs: http://akka.io/docs/ > >> Check the FAQ: http://doc.akka.io/docs/akka/c > urrent/additional/faq.html > >> Search the archives: https://groups.google.com/grou > p/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+...@googlegroups.com. > To post to this group, send email to akka...@googlegroups.com. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- Cheers, Konrad 'ktoso' Malawski hAkker @ Typesafe -- >>> >> 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+...@googlegroups.com. >>> To post to this group, send email to akka...@googlegroups.com. >>> Visit this group at http://groups.google.com/group/akka-user. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Cheers, >> Konrad 'ktoso' Malawski >> hAkker @ Typesafe >> >> >> -- > >> Read the docs: h