use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class ClusterSupport method init.
public void init() {
long start = System.currentTimeMillis();
prepareCluster();
URL subUrl = toSubscribeUrl(url);
for (URL ru : registryUrls) {
String directUrlStr = ru.getParameter(URLParamType.directUrl.getName());
// 如果有directUrl,直接使用这些directUrls进行初始化,不用到注册中心discover
if (StringUtils.isNotBlank(directUrlStr)) {
List<URL> directUrls = UrlUtils.stringToURLs(directUrlStr);
if (!directUrls.isEmpty()) {
notify(ru, directUrls);
LoggerUtil.info("Use direct urls, refUrl={}, directUrls={}", url, directUrls);
continue;
}
}
// client 注册自己,同时订阅service列表
Registry registry = getRegistry(ru);
registry.subscribe(subUrl, this);
}
boolean check = Boolean.parseBoolean(url.getParameter(URLParamType.check.getName(), URLParamType.check.getValue()));
if (!CollectionUtil.isEmpty(cluster.getReferers()) || !check) {
cluster.init();
if (CollectionUtil.isEmpty(cluster.getReferers()) && !check) {
LoggerUtil.warn(String.format("refer:%s", this.url.getPath() + "/" + this.url.getVersion()), "No services");
}
LoggerUtil.info("cluster init cost " + (System.currentTimeMillis() - start) + ", refer size:" + (cluster.getReferers() == null ? 0 : cluster.getReferers().size()) + ", cluster:" + cluster.getUrl().toSimpleString());
StatsUtil.registryStatisticCallback(this);
return;
}
throw new MotanFrameworkException(String.format("ClusterSupport No service urls for the refer:%s, registries:%s", this.url.getIdentity(), registryUrls), MotanErrorMsgConstant.SERVICE_UNFOUND);
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class FailoverHaStrategy method call.
@Override
public Response call(Request request, LoadBalance<T> loadBalance) {
List<Referer<T>> referers = selectReferers(request, loadBalance);
if (referers.isEmpty()) {
throw new MotanServiceException(String.format("FailoverHaStrategy No referers for request:%s, loadbalance:%s", request, loadBalance));
}
URL refUrl = referers.get(0).getUrl();
// 先使用method的配置
int tryCount = refUrl.getMethodParameter(request.getMethodName(), request.getParamtersDesc(), URLParamType.retries.getName(), URLParamType.retries.getIntValue());
// 如果有问题,则设置为不重试
if (tryCount < 0) {
tryCount = 0;
}
for (int i = 0; i <= tryCount; i++) {
Referer<T> refer = referers.get(i % referers.size());
try {
request.setRetries(i);
return refer.call(request);
} catch (RuntimeException e) {
// 对于业务异常,直接抛出
if (ExceptionUtil.isBizException(e)) {
throw e;
} else if (i >= tryCount) {
throw e;
}
LoggerUtil.warn(String.format("FailoverHaStrategy Call false for request:%s error=%s", request, e.getMessage()));
}
}
throw new MotanFrameworkException("FailoverHaStrategy.call should not come here!");
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class DefaultRpcProtocolTest method testProtocol.
@Test
public void testProtocol() {
url = new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
url.getParameters().put(URLParamType.endpointFactory.getName(), "mockEndpoint");
try {
defaultRpcProtocol.export(null, null);
} catch (Exception e) {
if (e instanceof MotanFrameworkException) {
Assert.assertTrue(e.getMessage().contains("url is null"));
} else {
Assert.assertTrue(false);
}
}
try {
defaultRpcProtocol.export(null, url);
} catch (Exception e) {
if (e instanceof MotanFrameworkException) {
Assert.assertTrue(e.getMessage().contains("provider is null"));
} else {
Assert.assertTrue(false);
}
}
defaultRpcProtocol.export(new Provider<IHello>() {
private IHello hello = new Hello();
@Override
public Response call(Request request) {
hello.hello();
return new DefaultResponse("hello");
}
@Override
public void init() {
}
@Override
public void destroy() {
}
@Override
public boolean isAvailable() {
return false;
}
@Override
public String desc() {
return null;
}
@Override
public URL getUrl() {
return new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
}
@Override
public Class<IHello> getInterface() {
return IHello.class;
}
@Override
public Method lookupMethod(String methodName, String methodDesc) {
return null;
}
@Override
public IHello getImpl() {
return hello;
}
}, url);
Referer<IHello> referer = defaultRpcProtocol.refer(IHello.class, url);
DefaultRequest request = new DefaultRequest();
request.setMethodName("hello");
request.setInterfaceName(IHello.class.getName());
Response response = referer.call(request);
System.out.println("client: " + response.getValue());
defaultRpcProtocol.destroy();
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class FailbackRegistry method register.
@Override
public void register(URL url) {
failedRegistered.remove(url);
failedUnregistered.remove(url);
try {
super.register(url);
} catch (Exception e) {
if (isCheckingUrls(getUrl(), url)) {
throw new MotanFrameworkException(String.format("[%s] false to registery %s to %s", registryClassName, url, getUrl()), e);
}
failedRegistered.add(url);
}
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class FailbackRegistry method unregister.
@Override
public void unregister(URL url) {
failedRegistered.remove(url);
failedUnregistered.remove(url);
try {
super.unregister(url);
} catch (Exception e) {
if (isCheckingUrls(getUrl(), url)) {
throw new MotanFrameworkException(String.format("[%s] false to unregistery %s to %s", registryClassName, url, getUrl()), e);
}
failedUnregistered.add(url);
}
}
Aggregations