Skip to content

Commit

Permalink
Declare default methods for supportsSourceType and getOrder
Browse files Browse the repository at this point in the history
Issue: SPR-17163
  • Loading branch information
jhoeller committed Aug 10, 2018
1 parent 309ffc6 commit c437a0d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,24 +24,40 @@

/**
* Extended variant of the standard {@link ApplicationListener} interface,
* exposing further metadata such as the supported event type.
* exposing further metadata such as the supported event and source type.
*
* <p>As of Spring Framework 4.2, supersedes {@link SmartApplicationListener} with
* proper handling of generics-based event.
* <p>As of Spring Framework 4.2, this interface supersedes the Class-based
* {@link SmartApplicationListener} with full handling of generic event types.
*
* @author Stephane Nicoll
* @since 4.2
* @see SmartApplicationListener
* @see GenericApplicationListenerAdapter
*/
public interface GenericApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {

/**
* Determine whether this listener actually supports the given event type.
* @param eventType the event type (never {@code null})
*/
boolean supportsEventType(ResolvableType eventType);

/**
* Determine whether this listener actually supports the given source type.
* <p>The default implementation always returns {@code true}.
* @param sourceType the source type, or {@code null} if no source
*/
boolean supportsSourceType(@Nullable Class<?> sourceType);
default boolean supportsSourceType(@Nullable Class<?> sourceType) {
return true;
}

/**
* Determine this listener's order in a set of listeners for the same event.
* <p>The default implementation returns {@link #LOWEST_PRECEDENCE}.
*/
@Override
default int getOrder() {
return LOWEST_PRECEDENCE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,40 @@

/**
* Extended variant of the standard {@link ApplicationListener} interface,
* exposing further metadata such as the supported event type.
* exposing further metadata such as the supported event and source type.
*
* <p>Users are <b>strongly advised</b> to use the {@link GenericApplicationListener}
* interface instead as it provides an improved detection of generics-based
* event types.
* <p>For full introspection of generic event types, consider implementing
* the {@link GenericApplicationListener} interface instead.
*
* @author Juergen Hoeller
* @since 3.0
* @see GenericApplicationListener
* @see GenericApplicationListenerAdapter
*/
public interface SmartApplicationListener extends ApplicationListener<ApplicationEvent>, Ordered {

/**
* Determine whether this listener actually supports the given event type.
* @param eventType the event type (never {@code null})
*/
boolean supportsEventType(Class<? extends ApplicationEvent> eventType);

/**
* Determine whether this listener actually supports the given source type.
* <p>The default implementation always returns {@code true}.
* @param sourceType the source type, or {@code null} if no source
*/
boolean supportsSourceType(@Nullable Class<?> sourceType);
default boolean supportsSourceType(@Nullable Class<?> sourceType) {
return true;
}

/**
* Determine this listener's order in a set of listeners for the same event.
* <p>The default implementation returns {@link #LOWEST_PRECEDENCE}.
*/
@Override
default int getOrder() {
return LOWEST_PRECEDENCE;
}

}

0 comments on commit c437a0d

Please sign in to comment.