/**
* DeprecatedInvokerFilter
* 服务于consumer 包含deprecated属性
*/
@Activate(group = Constants.CONSUMER, value = Constants.DEPRECATED_KEY)
public class DeprecatedFilter implements Filter {
private static final Logger LOGGER = LoggerFactory.getLogger(DeprecatedFilter.class);
private static final Set<String> logged = new ConcurrentHashSet<String>();
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
//获得key
String key = invoker.getInterface().getName() + "." + invocation.getMethodName();
//如果未打印
if (!logged.contains(key)) {
logged.add(key);
//点调用废弃方法的时候 打印错误日志
if (invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.DEPRECATED_KEY, false)) {
LOGGER.error("The service method " + invoker.getInterface().getName() + "." + getMethodSignature(invocation) + " is DEPRECATED! Declare from " + invoker.getUrl());
}
}
return invoker.invoke(invocation);
}
private String getMethodSignature(Invocation invocation) {
StringBuilder buf = new StringBuilder(invocation.getMethodName());
buf.append("(");
Class<?>[] types = invocation.getParameterTypes();
if (types != null && types.length > 0) {
boolean first = true;
for (Class<?> type : types) {
if (first) {
first = false;
} else {
buf.append(", ");
}
buf.append(type.getSimpleName());
}
}
buf.append(")");
return buf.toString();
}
}