use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class ZookeeperRegistry method discoverService.
@Override
protected List<URL> discoverService(URL url) {
try {
String parentPath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER);
List<String> currentChilds = new ArrayList<String>();
if (zkClient.exists(parentPath)) {
currentChilds = zkClient.getChildren(parentPath);
}
return nodeChildsToUrls(parentPath, currentChilds);
} catch (Throwable e) {
throw new MotanFrameworkException(String.format("Failed to discover service %s from zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e);
}
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class ZookeeperRegistry method unsubscribeCommand.
@Override
protected void unsubscribeCommand(URL url, CommandListener commandListener) {
try {
clientLock.lock();
Map<CommandListener, IZkDataListener> dataChangeListeners = commandListeners.get(url);
if (dataChangeListeners != null) {
IZkDataListener zkDataListener = dataChangeListeners.get(commandListener);
if (zkDataListener != null) {
zkClient.unsubscribeDataChanges(ZkUtils.toCommandPath(url), zkDataListener);
dataChangeListeners.remove(commandListener);
}
}
} catch (Throwable e) {
throw new MotanFrameworkException(String.format("Failed to unsubscribe command %s to zookeeper(%s), cause: %s", url, getUrl(), e.getMessage()), e);
} finally {
clientLock.unlock();
}
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class MockDefaultRpcCodec method decode.
@Override
public Object decode(Channel channel, String remoteIp, byte[] buffer) throws IOException {
Object result = codec.decode(channel, remoteIp, buffer);
if (result instanceof Response) {
DefaultResponse object = (DefaultResponse) result;
byte flag = buffer[3];
byte dataType = (byte) (flag & MASK);
boolean isResponse = (dataType != MotanConstants.FLAG_REQUEST);
if (object.getException() == null) {
if (isResponse && object.getValue().equals("error")) {
DefaultResponse response = (DefaultResponse) object;
response.setException(new MotanFrameworkException("decode error: response dataType not support " + dataType, MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR));
return response;
} else {
throw new MotanFrameworkException(MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR);
}
}
return object;
}
return result;
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class CommandServiceManager method notifyService.
@Override
public void notifyService(URL serviceUrl, URL registryUrl, List<URL> urls) {
if (registry == null) {
throw new MotanFrameworkException("registry must be set.");
}
URL urlCopy = serviceUrl.createCopy();
String groupName = urlCopy.getParameter(URLParamType.group.getName(), URLParamType.group.getValue());
groupServiceCache.put(groupName, urls);
List<URL> finalResult = new ArrayList<URL>();
if (commandCache != null) {
Map<String, Integer> weights = new HashMap<String, Integer>();
finalResult = discoverServiceWithCommand(refUrl, weights, commandCache);
} else {
LoggerUtil.info("command cache is null. service:" + serviceUrl.toSimpleString());
// 没有命令时,只返回这个manager实际group对应的结果
finalResult.addAll(discoverOneGroup(refUrl));
}
for (NotifyListener notifyListener : notifySet) {
notifyListener.notify(registry.getUrl(), finalResult);
}
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class ProviderMessageRouter method handle.
@Override
public Object handle(Channel channel, Object message) {
if (channel == null || message == null) {
throw new MotanFrameworkException("RequestRouter handler(channel, message) params is null");
}
if (!(message instanceof Request)) {
throw new MotanFrameworkException("RequestRouter message type not support: " + message.getClass());
}
Request request = (Request) message;
String serviceKey = MotanFrameworkUtil.getServiceKey(request);
Provider<?> provider = providers.get(serviceKey);
if (provider == null) {
LoggerUtil.error(this.getClass().getSimpleName() + " handler Error: provider not exist serviceKey=" + serviceKey + " " + MotanFrameworkUtil.toString(request));
MotanServiceException exception = new MotanServiceException(this.getClass().getSimpleName() + " handler Error: provider not exist serviceKey=" + serviceKey + " " + MotanFrameworkUtil.toString(request));
DefaultResponse response = new DefaultResponse();
response.setException(exception);
return response;
}
return call(request, provider);
}
Aggregations