use of com.weibo.api.motan.filter.Filter in project motan by weibocom.
the class ProtocolFilterDecorator method addIfAbsent.
private void addIfAbsent(List<Filter> filters, String extensionName) {
if (StringUtils.isBlank(extensionName)) {
return;
}
Filter extFilter = ExtensionLoader.getExtensionLoader(Filter.class).getExtension(extensionName);
if (extFilter == null) {
return;
}
boolean exists = false;
for (Filter f : filters) {
if (f.getClass() == extFilter.getClass()) {
exists = true;
break;
}
}
if (!exists) {
filters.add(extFilter);
}
}
use of com.weibo.api.motan.filter.Filter in project motan by weibocom.
the class ProtocolFilterDecorator method decorateWithFilter.
private <T> Referer<T> decorateWithFilter(Referer<T> referer, URL url) {
List<Filter> filters = getFilters(url, MotanConstants.NODE_TYPE_REFERER);
Referer<T> lastRef = referer;
for (Filter filter : filters) {
final Filter f = filter;
final Referer<T> lf = lastRef;
lastRef = new Referer<T>() {
@Override
public Response call(Request request) {
Activation activation = f.getClass().getAnnotation(Activation.class);
if (activation != null && !activation.retry() && request.getRetries() != 0) {
return lf.call(request);
}
return f.filter(lf, request);
}
@Override
public String desc() {
return lf.desc();
}
@Override
public void destroy() {
lf.destroy();
}
@Override
public Class<T> getInterface() {
return lf.getInterface();
}
@Override
public URL getUrl() {
return lf.getUrl();
}
@Override
public void init() {
lf.init();
}
@Override
public boolean isAvailable() {
return lf.isAvailable();
}
@Override
public int activeRefererCount() {
return lf.activeRefererCount();
}
@Override
public URL getServiceUrl() {
return lf.getServiceUrl();
}
};
}
return lastRef;
}
use of com.weibo.api.motan.filter.Filter in project motan by weibocom.
the class ProtocolFilterDecorator method decorateWithFilter.
private <T> Provider<T> decorateWithFilter(Provider<T> provider, URL url) {
List<Filter> filters = getFilters(url, MotanConstants.NODE_TYPE_SERVICE);
if (filters == null || filters.size() == 0) {
return provider;
}
Provider<T> lastProvider = provider;
for (Filter filter : filters) {
final Filter f = filter;
final Provider<T> lp = lastProvider;
lastProvider = new Provider<T>() {
@Override
public Response call(Request request) {
return f.filter(lp, request);
}
@Override
public String desc() {
return lp.desc();
}
@Override
public void destroy() {
lp.destroy();
}
@Override
public Class<T> getInterface() {
return lp.getInterface();
}
@Override
public URL getUrl() {
return lp.getUrl();
}
@Override
public void init() {
lp.init();
}
@Override
public boolean isAvailable() {
return lp.isAvailable();
}
};
}
return lastProvider;
}
Aggregations