private <T> void invoke(Map<Object, Set<Method>> methods, T instance) {
        for (Map.Entry<Object, Set<Method>> entry : methods.entrySet()) {
            Object listener = entry.getKey();
            Set<Method> listenerMethods = entry.getValue();
            if (listenerMethods != null) {
                for (Method method : listenerMethods) {
                    Class<?> parameterType = method.getParameterTypes()[0];
                    if (parameterType.isAssignableFrom(instance.getClass())) {
                        try {
                            method.invoke(listener, instance);
                        } catch (IllegalAccessException e) {
                            throw new XOException("Cannot access instance listener method " + method.toGenericString(), e);
                        } catch (InvocationTargetException e) {
                            throw new XOException("Cannot invoke instance listener method " + method.toGenericString(), e);
                        }
                    }
                }
            }
        }
    }
private < T > void invoke ( Map < Object , Set < Method > > methods , T instance ) { for ( Map . Entry < Object , Set < Method > > entry : methods . entrySet ( ) ) { Object listener = entry . getKey ( ) ; Set < Method > listenerMethods = entry . getValue ( ) ; if ( listenerMethods != null ) { for ( Method method : listenerMethods ) { Class < ? > parameterType = method . getParameterTypes ( ) [ 0 ] ; if ( parameterType . isAssignableFrom ( instance . getClass ( ) ) ) { try { method . invoke ( listener , instance ) ; } catch ( IllegalAccessException e ) { throw new XOException ( "Cannot access instance listener method " + method . toGenericString ( ) , e ) ; } catch ( InvocationTargetException e ) { throw new XOException ( "Cannot invoke instance listener method " + method . toGenericString ( ) , e ) ; } } } } } }
Invokes all registered lifecycle methods on a given instance.

@param methods
The registered methods.
@param instance
The instance.
@param <T>
The instance type.