dnrajugade / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

HandlerFindingStrategy is not replaceable #1210

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In Event bus the HandlerFindingStrategy is private final instance of an 
AnnotatedHandlerFinder. 

I wanted to be able to have an interface MyEventHandler<T extends EventObject> 
that handler classes could inherit with a pre-annotatted handler method that 
took a T parameter. 

I was hoping AnnotatedHandlerFinder would look down the method inheritance 
chain to discover the annotation so that it did not have to be declared on the 
method in the handler class it self. 

However it does not do this and the HandlerFindingStrategy can not be plugged 
into the Event bus. 

/**
   * Strategy for finding handler methods in registered objects.  Currently,
   * only the {@link AnnotatedHandlerFinder} is supported, but this is
   * encapsulated for future expansion.
   */
  private final HandlerFindingStrategy finder = new AnnotatedHandlerFinder();

When will the future expansion occur. If it we not written this way I could 
have easily extended the Strategy. 

Original issue reported on code.google.com by simon.pe...@simaptech.com on 22 Nov 2012 at 8:32

GoogleCodeExporter commented 9 years ago
Sorry I realize what I wanted to do would not work in java anyhow. Still forget 
Java generics not like c# generics.

public class A implements EventHandler<BEvent>, EventHandler<CEvent>
{
    public void handleEvent(BEvent event) {
        // do stuff
    }

    public void handleEvent(CEvent event) {
        // do stuff
    }
}

Original comment by simon.pe...@simaptech.com on 22 Nov 2012 at 9:22

GoogleCodeExporter commented 9 years ago
Hi Simon,

Are you using the latest version of Guava (13.0.1)? Unless I'm misunderstanding 
your request version 13.0.1 _does_ consider interface-level annotations 
(meaning that they're inherited). I have some code that relies on this, 
actually.

If you _are_ using 13.0.1, perhaps the use of a generic type parameter has 
something to do with it. Didn't test that.

Original comment by stephan...@gmail.com on 22 Nov 2012 at 9:25

GoogleCodeExporter commented 9 years ago
Ah, our comments crossed :) So you verified that in absence of generics the 
interface-level annotation _is_ respected?

Original comment by stephan...@gmail.com on 22 Nov 2012 at 9:26

GoogleCodeExporter commented 9 years ago
Hi,
I stumbled across this discussion while I was investigating how 
eventBus.register() would work for classes that are Spring proxies. 
I am finding that the AnnotationHandlerFinder will not work for a class (that 
is registered with the eventBus) for which Spring has created a dynamic proxy 
because the annotations (@Subscribe in this case) will not be available on the 
proxy.

So I decided to write my own custom impl of HandlerFinder but then I discovered 
that there is no way to set the finder on the EventBus.... bummer!

Is there a suggestion on how I can tell the eventBus to use a different 
strategy short of extending the EventBus class itself?

Thanks!

Original comment by pankajta...@gmail.com on 7 Dec 2012 at 7:19

GoogleCodeExporter commented 9 years ago
Gaaaah! HandlerFindingStrategy is a private interface!
Any suggestions for this problem?

To rephrase: How can I @Subscribe beans that are registered as a JDK Dynamic 
proxy?
Thanks!

Original comment by pankajta...@gmail.com on 7 Dec 2012 at 7:43

GoogleCodeExporter commented 9 years ago
Possibility: write a new wrapper class to put around the proxies that provides 
a 

@Subscribe
public void passEventToProxy(Object event)

and then implement whatever reflective mojo you need in that wrapper class.  
Then just use EventBus.register(new ProxyWrapper(proxy)).

Original comment by lowas...@google.com on 7 Dec 2012 at 9:11

GoogleCodeExporter commented 9 years ago
I guess I was hoping to make my original class implement a custom interface 
(called Subscribe, say) and since interfaces are available on the proxy, use a 
custom implementation of the handler finder look for proxies with that 
interface on it.

But, I've got around this issue for now by registering the original 
(pre-proxied) bean. But making that HandlerFindingStrategy interface public for 
future extensions would greatly help!

Thanks!

Original comment by pankajta...@gmail.com on 9 Dec 2012 at 9:22

GoogleCodeExporter commented 9 years ago

Original comment by wasserman.louis on 22 Jul 2013 at 3:27

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08