Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering with Guice TypeListener #34

Open
nheitz opened this issue Feb 24, 2016 · 0 comments
Open

Registering with Guice TypeListener #34

nheitz opened this issue Feb 24, 2016 · 0 comments

Comments

@nheitz
Copy link

nheitz commented Feb 24, 2016

I am very keen to switch to this JMX enabling library and move away from pojo-mbean, as the features here are a more natural fit. However, I am having trouble letting the export process "discover" managed beans as they are injected, a pattern I have used to great effect previously.
Using jmxutils, the following works:

 private ExportBinder exporter;

 @Override
    protected void configure() {
        bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer());
        install(new MBeanModule());
        exporter = ExportBinder.newExporter(binder());
        exporter.export(MyClass.class).withGeneratedName();
    }

but using Listeners doesn't (I'm using the ManagedBean annotation to "mark" my class...assume that MyClass has that annotation):

   private ExportBinder exporter;

   @Override
    protected void configure() {
        bind(MBeanServer.class).toInstance(ManagementFactory.getPlatformMBeanServer());
        bindListener(Matchers.any(), new JmxTypeListener());
        install(new MBeanModule());
        exporter = ExportBinder.newExporter(binder());
    }

    private class JmxTypeListener implements TypeListener {
        @Override
        public <I> void hear(TypeLiteral<I> type, final TypeEncounter<I> encounter) {

            final Class<? super I> rawType = type.getRawType();

            if (rawType.isAnnotationPresent(ManagedBean.class)) {
                exporter.export(rawType).withGeneratedName(); //this seems to have no effect!
...

Everything executes as expected, but no entry shows up in the jmx console for the second approach. Is it too late to export beans by the time the listener is "hearing" bindings? Is there any workaround that means I don't have to explicitly export beans by type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant