All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dxee.dject.event.guava.GuavaSubscriberProxy Maven / Gradle / Ivy

Go to download

A collection of guice extensions, help to improve the developer experience of guice.

There is a newer version: 1.5.1
Show newest version
package com.github.dxee.dject.event.guava;

import com.github.dxee.dject.event.ApplicationEvent;
import com.google.common.eventbus.Subscribe;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

class GuavaSubscriberProxy {

    private final Object handlerInstance;
    private final Method handlerMethod;
    private final Class acceptedType;

    public GuavaSubscriberProxy(Object handlerInstance, Method handlerMethod, Class acceptedType) {
        this.handlerInstance = handlerInstance;
        this.handlerMethod = handlerMethod;
        this.acceptedType = acceptedType;
    }

    @Subscribe
    public void invokeEventHandler(ApplicationEvent event)
            throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        if (acceptedType.isAssignableFrom(event.getClass())) {
            if (!handlerMethod.isAccessible()) {
                handlerMethod.setAccessible(true);
            }
            handlerMethod.invoke(handlerInstance, event);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy