Java API for event bus is broken

56 views
Skip to first unread message

Patrik Nordwall

unread,
Feb 5, 2014, 10:26:19 AM2/5/14
to akka...@googlegroups.com
I was about to add sample code to the documentation of how to use the event bus abstraction, but I can't find a way to use it from Java. Subclassing the abstract classes in akka.event.japi doesn't compile for other types of E, S, C than Object.

I hope I'm wrong, otherwise what do we do for 2.3.0?

Minimized problem:

trait Bus {
  type Subscriber
  type Classifier

  def subscribe(subscriber: Subscriber, to: Classifier): Boolean
}

abstract class JBus[S, C] extends Bus {
  type Subscriber = S
  type Classifier = C
}

public class MyEventBus extends JBus<ActorRef, String> {
  @Override
  public boolean subscribe(ActorRef subscriber, String to) {
    return false;
  }
}


[error] /Users/patrik/dev/akka/akka-actor-tests/src/test/java/akka/event/MyEventBus.java:8: error: MyEventBus is not abstract and does not override abstract method subscribe(Object,Object) in Bus
[error] public class MyEventBus extends JBus<ActorRef, String> {
[error]        ^
[error] /Users/patrik/dev/akka/akka-actor-tests/src/test/java/akka/event/MyEventBus.java:10: error: method does not override or implement a method from a supertype
[error]   @Override
[error]   ^
[error] 2 errors

--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Patrik Nordwall

unread,
Feb 6, 2014, 3:13:28 AM2/6/14
to akka...@googlegroups.com
One solution is to define a new working Java API, with same functionality, still reusing the Scala implementation.
It's not touching the Scala API and it's only fixing something that can't have been used, so it might be possible to add to 2.3.0 (with or without additional RC). Otherwise I suggest that we remove the japi in 2.3.0 and add the working api in 2.3.1.
WDYT?


Eugene Vigdorchik

unread,
Feb 6, 2014, 3:17:19 AM2/6/14
to akka...@googlegroups.com


среда, 5 февраля 2014 г., 19:26:19 UTC+4 пользователь patriknw написал:
I was about to add sample code to the documentation of how to use the event bus abstraction, but I can't find a way to use it from Java. Subclassing the abstract classes in akka.event.japi doesn't compile for other types of E, S, C than Object.

Yeah, that's the same scenario that is rejected by javac in pure java:

interface Base {
    Boolean f(Object obj);
}

class Drv<T> implements Base {
    Boolean f(T obj) {
        return false;
    }
}

B.java:5: error: Drv is not abstract and does not override abstract method f(Object) in Base
class Drv<T> implements Base {
^
B.java:6: error: name clash: f(T) in Drv and f(Object) in Base have the same era  sure, yet neither overrides the other
    Boolean f(T obj) {
            ^
  where T is a type-variable:
    T extends Object declared in class Drv
2 errors

Coming back to the bus:
In scala there's an abstract Object method created (in bytecode)  for the signature with abstract types, and it can't be implemented in any way with generics in java, neither made non-abstract by inheritance with type parameters in scala.
So the honest thing would be to declare akka hasa problem in this java interop aspect...

Eugene.

Patrik Nordwall

unread,
Feb 6, 2014, 9:22:05 AM2/6/14
to akka...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "Akka Developer List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Roland Kuhn

unread,
Feb 6, 2014, 9:58:14 AM2/6/14
to akka...@googlegroups.com
Hi Patrik,

the PR is looking good, and since it fixes something which
  • was broken since a long time without anybody noticing
  • without touching other code
I would say that it does not need another RC by itself. The chances of introducing a regression are rather slim, unless I am missing something.

Great work!

Regards,

Roland


Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


Patrik Nordwall

unread,
Feb 6, 2014, 10:02:41 AM2/6/14
to akka...@googlegroups.com
On Thu, Feb 6, 2014 at 3:58 PM, Roland Kuhn <goo...@rkuhn.info> wrote:
Hi Patrik,

the PR is looking good, and since it fixes something which
  • was broken since a long time without anybody noticing
  • without touching other code
I would say that it does not need another RC by itself. The chances of introducing a regression are rather slim, unless I am missing something.

Thanks Roland, yes that was my conclusion as well when working on this.
/Patrik
Reply all
Reply to author
Forward
0 new messages