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

backward compatible with ListenableFilter #5623

Merged
merged 1 commit into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* MonitorFilter. (SPI, Singleton, ThreadSafe)
*/
@Activate(group = {PROVIDER, CONSUMER})
public class MonitorFilter implements Filter, Filter.Listener {
public class MonitorFilter implements Filter, Filter.Listener2 {

private static final Logger logger = LoggerFactory.getLogger(MonitorFilter.class);
private static final String MONITOR_FILTER_START_TIME = "monitor_filter_start_time";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface Filter {
Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException;

/**
* Please use {@link Listener#onMessage(Result, Invoker, Invocation)} instead.
* Please use {@link Listener2#onMessage(Result, Invoker, Invocation)} instead.
* This method is kept only for compatibility and may get removed at any version in the future.
*
* @param appResponse
Expand All @@ -60,11 +60,19 @@ default Result onResponse(Result appResponse, Invoker<?> invoker, Invocation inv
return appResponse;
}

@Deprecated
interface Listener {

void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation);

void onError(Throwable t, Invoker<?> invoker, Invocation invocation);
}
interface Listener2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keep two methods in Listener is better:

interface Listener {
        @Deprecated
        void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation);

        default void onMessage(Result appResponse, Invoker<?> invoker, Invocation invocation) {
                onResponse(appResponse, invoker, invocation);
        }

        void onError(Throwable t, Invoker<?> invoker, Invocation invocation);
    }

Then call the onMessage method in ProtocolFilterWrapper, so user can implement eithor onMessage or onResponse method.


void onMessage(Result appResponse, Invoker<?> invoker, Invocation invocation);

void onError(Throwable t, Invoker<?> invoker, Invocation invocation);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

/**
* This abstract will be removed soon from one future release.
* Please implementing Filter.Listener directly for callback registration,
* Please implementing Filter.Listener2 directly for callback registration,
* check the default implementation, see {@link org.apache.dubbo.rpc.filter.ExceptionFilter}, for example.
*/
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @see Filter
*/
@Activate(group = CONSUMER, value = ACTIVES_KEY)
public class ActiveLimitFilter implements Filter, Filter.Listener {
public class ActiveLimitFilter implements Filter, Filter.Listener2 {

private static final String ACTIVELIMIT_FILTER_START_TIME = "activelimit_filter_start_time";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @see Filter
*
*/
public class CompatibleFilter implements Filter, Filter.Listener {
public class CompatibleFilter implements Filter, Filter.Listener2 {

private static Logger logger = LoggerFactory.getLogger(CompatibleFilter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* @see RpcContext
*/
@Activate(group = PROVIDER, order = -10000)
public class ContextFilter implements Filter, Filter.Listener {
public class ContextFilter implements Filter, Filter.Listener2 {
private static final String TAG_KEY = "dubbo.tag";

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* </ol>
*/
@Activate(group = CommonConstants.PROVIDER)
public class ExceptionFilter implements Filter, Filter.Listener {
public class ExceptionFilter implements Filter, Filter.Listener2 {
private Logger logger = LoggerFactory.getLogger(ExceptionFilter.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
*
*/
@Activate(group = CommonConstants.PROVIDER, value = EXECUTES_KEY)
public class ExecuteLimitFilter implements Filter, Filter.Listener {
public class ExecuteLimitFilter implements Filter, Filter.Listener2 {

private static final String EXECUTELIMIT_FILTER_START_TIME = "execugtelimit_filter_start_time";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
* GenericInvokerFilter.
*/
@Activate(group = CommonConstants.PROVIDER, order = -20000)
public class GenericFilter implements Filter, Filter.Listener {
public class GenericFilter implements Filter, Filter.Listener2 {

@Override
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* GenericImplInvokerFilter
*/
@Activate(group = CommonConstants.CONSUMER, value = GENERIC_KEY, order = 20000)
public class GenericImplFilter implements Filter, Filter.Listener {
public class GenericImplFilter implements Filter, Filter.Listener2 {

private static final Logger logger = LoggerFactory.getLogger(GenericImplFilter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Log any invocation timeout, but don't stop server from running
*/
@Activate(group = CommonConstants.PROVIDER)
public class TimeoutFilter implements Filter, Filter.Listener {
public class TimeoutFilter implements Filter, Filter.Listener2 {

private static final Logger logger = LoggerFactory.getLogger(TimeoutFilter.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public Result invoke(Invocation invocation) throws RpcException {
if (listener != null) {
listener.onError(e, invoker, invocation);
}
} else if (filter instanceof Filter.Listener) {
Filter.Listener listener = (Filter.Listener) filter;
} else if (filter instanceof Filter.Listener2) {
Filter.Listener2 listener = (Filter.Listener2) filter;
listener.onError(e, invoker, invocation);
}
throw e;
Expand All @@ -98,13 +98,13 @@ public Result invoke(Invocation invocation) throws RpcException {
Filter.Listener listener = ((ListenableFilter) filter).listener();
if (listener != null) {
if (t == null) {
listener.onMessage(r, invoker, invocation);
listener.onResponse(r, invoker, invocation);
} else {
listener.onError(t, invoker, invocation);
}
}
} else if (filter instanceof Filter.Listener) {
Filter.Listener listener = (Filter.Listener) filter;
} else if (filter instanceof Filter.Listener2) {
Filter.Listener2 listener = (Filter.Listener2) filter;
if (t == null) {
listener.onMessage(r, invoker, invocation);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void run() {
activeLimitFilter.onMessage(result, invoker, invocation);
} catch (RpcException expected) {
count.incrementAndGet();
// activeLimitFilter.listener().onError(expected, invoker, invocation);
// activeLimitFilter.Listener2().onError(expected, invoker, invocation);
} catch (Exception e) {
fail();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* EventFilter
*/
@Activate(group = CommonConstants.CONSUMER)
public class FutureFilter implements Filter, Filter.Listener {
public class FutureFilter implements Filter, Filter.Listener2 {

protected static final Logger logger = LoggerFactory.getLogger(FutureFilter.class);

Expand Down