TypedActor message dispatch semantics

75 views
Skip to first unread message

r4dium

unread,
Feb 11, 2012, 9:19:20 PM2/11/12
to Akka User List
The documentation states:
akka.dispatch.Future<?> will use send-request-reply semantics, exactly
like ActorRef.ask

Now, does this only apply to methods which specify Future<?> as
return value e.g.

Future<T> mytest()

or also to methods which return a subclass of Future<?> e.g.

" Promize<T> mytest()

where Promize<T> implements Promise<T>" ?

Help appreciated!

Regards
R4dium

Roland Kuhn

unread,
Feb 12, 2012, 3:21:45 AM2/12/12
to akka...@googlegroups.com

Should work for any subtype of Future. Did you encounter any problems?

Regards,

Roland Kuhn
Typesafe — The software stack for applications that scale
twitter: @rolandkuhn

r4dium

unread,
Feb 12, 2012, 4:35:35 AM2/12/12
to Akka User List
Well, I am not sure......

I extended Promise in the above mentioned way:

public class Promize<T> implements akka.dispatch.Promise<T>
{
.....
public Promize<T> complete(Either<Throwable, T> arg0)
{
return new Promize<T>( _promise.complete(arg0) );
}
.....
}

which basically wraps the DefaultPromise _promise:
_promise = new
DefaultPromise<T>( ActorSystemSingleton.get().dispatcher() );


Now I have a typed-actor "task" which implements the following method:

public Promize<Object> update(String msg)
{
_extractedText = msg;
return new Promize<Object>().complete( new Right<Throwable,
Object>(null) );
}

which gets called by:
Promize<Object> p = task.update( d.extractText(data) );

However, it seems that before reaching the row "return new
Promize<Object>().complete( new Right<Throwable, Object>(null) );" the
following
exception gets thrown by the proxy of "task":

akka.dispatch.DefaultPromise cannot be cast to
com.cisco.www.irrupt.remoteservices.businesslayer.tasks.Promize
java.lang.ClassCastException: akka.dispatch.DefaultPromise cannot be
cast to
com.cisco.www.irrupt.remoteservices.businesslayer.tasks.Promize
at $Proxy7.update(Unknown Source)

Any idea?

Regards

R4DIUM





√iktor Ҡlang

unread,
Feb 12, 2012, 12:20:19 PM2/12/12
to akka...@googlegroups.com
On Sun, Feb 12, 2012 at 10:35 AM, r4dium <a...@profindis.de> wrote:
> On 12 Feb., 09:21, Roland Kuhn <goo...@rkuhn.info> wrote:
>> On 12 feb 2012, at 03:19, r4dium <a...@profindis.de> wrote:
>>
>> > The documentation states:
>> > akka.dispatch.Future<?> will use send-request-reply semantics, exactly
>> > like ActorRef.ask
>>
>> > Now, does this only apply to methods which specify  Future<?> as
>> > return value e.g.
>>
>> > Future<T> mytest()
>>
>> > or also to methods which return a subclass of Future<?> e.g.
>>
>> > " Promize<T> mytest()
>>
>> > where Promize<T> implements Promise<T>" ?
>>
>> Should work for any subtype of Future. Did you encounter any problems?
>>
>> Regards,
>>
>> Roland Kuhn
>> Typesafe — The software stack for applications that scale
>> twitter: @rolandkuhn
>
>
>
> Well, I am not sure......
>
> I extended Promise in the above mentioned way:
>
> public class Promize<T> implements akka.dispatch.Promise<T>
> {
>    .....
>    public Promize<T> complete(Either<Throwable, T> arg0)
>    {
>        return new Promize<T>( _promise.complete(arg0) );
>    }

That is not according to the contract for "complete", read the ScalaDoc.

>    .....
> }
>
> which basically wraps the DefaultPromise _promise:
> _promise = new
> DefaultPromise<T>( ActorSystemSingleton.get().dispatcher() );
>
>
> Now I have a typed-actor "task" which implements the following method:
>
> public Promize<Object> update(String msg)
> {
>    _extractedText = msg;
>    return new Promize<Object>().complete( new Right<Throwable,
> Object>(null) );

What is this?

> }
>
> which gets called by:
> Promize<Object> p = task.update( d.extractText(data) );
>
> However, it seems that before reaching the row "return new
> Promize<Object>().complete( new Right<Throwable, Object>(null) );" the
> following
> exception gets thrown by the proxy of "task":
>
>  akka.dispatch.DefaultPromise cannot be cast to
> com.cisco.www.irrupt.remoteservices.businesslayer.tasks.Promize
> java.lang.ClassCastException: akka.dispatch.DefaultPromise cannot be
> cast to
> com.cisco.www.irrupt.remoteservices.businesslayer.tasks.Promize
>        at $Proxy7.update(Unknown Source)
>
> Any idea?
>
> Regards
>
> R4DIUM
>
>
>
>
>

> --
> You received this message because you are subscribed to the Google Groups "Akka User List" group.
> To post to this group, send email to akka...@googlegroups.com.
> To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
>

--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

r4dium

unread,
Feb 12, 2012, 5:08:24 PM2/12/12
to Akka User List
Thx, for the hint - But I didn't understand it :-)

JavaDoc:
Completes this Promise with the specified result, if not already
completed.

This is exactly what my Promize.complete() does or not?


Can you please elaborate on this, would be very helpfull.


R4DIUM
> > For more options, visit this group athttp://groups.google.com/group/akka-user?hl=en.

√iktor Ҡlang

unread,
Feb 13, 2012, 2:47:47 PM2/13/12
to akka...@googlegroups.com
On Sun, Feb 12, 2012 at 11:08 PM, r4dium <a...@profindis.de> wrote:
> Thx, for the hint - But I didn't understand it :-)
>
> JavaDoc:
> Completes this Promise with the specified result, if not already
> completed.
>
> This is exactly what my Promize.complete() does or not?
>
>
> Can you please elaborate on this, would be very helpfull.

What is the return type of the complete method in the docs:
http://akka.io/api/akka/2.0-M4/#akka.dispatch.Promise

> For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.

r4dium

unread,
Feb 16, 2012, 6:15:02 PM2/16/12
to Akka User List
Well, it returns "this" and not a "new Promize()".
However, if I return "this", the same excetion gets thrown:

"akka.dispatch.DefaultPromise cannot be
cast to
com.cisco.www.irrupt.remoteservices.businesslayer.tasks.Promize"




On 13 Feb., 20:47, √iktor Ҡlang <viktor.kl...@gmail.com> wrote:
> On Sun, Feb 12, 2012 at 11:08 PM,r4dium<a...@profindis.de> wrote:
> > Thx, for the hint - But I didn't understand it :-)
>
> > JavaDoc:
> > Completes this Promise with the specified result, if not already
> > completed.
>
> > This is exactly what my Promize.complete() does or not?
>
> > Can you please elaborate on this, would be very helpfull.
>
> What is the return type of the complete method in the docs:http://akka.io/api/akka/2.0-M4/#akka.dispatch.Promise
>
>
>
>
>
>
>
>
>
>
>
> >R4DIUM
>
> > On 12 Feb., 18:20, √iktor Ҡlang <viktor.kl...@gmail.com> wrote:
> >> On Sun, Feb 12, 2012 at 10:35 AM,r4dium<a...@profindis.de> wrote:
> >> > On 12 Feb., 09:21, Roland Kuhn <goo...@rkuhn.info> wrote:
Reply all
Reply to author
Forward
0 new messages