use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class CompressRpcCodec method decodeResponse.
/**
*
* @param body
* @param dataType
* @param requestId
* @param rpcProtocolVersion rpc协议的版本号,不同版本可能有不同的序列化方式
* @param serialization
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
private Object decodeResponse(byte[] body, byte dataType, long requestId, byte rpcProtocolVersion, Serialization serialization) throws IOException, ClassNotFoundException {
ObjectInput input = createInput(getInputStream(body));
long processTime = input.readLong();
DefaultResponse response = new DefaultResponse();
response.setRequestId(requestId);
response.setProcessTime(processTime);
if (dataType == MotanConstants.FLAG_RESPONSE_VOID) {
return response;
}
String className = input.readUTF();
Class<?> clz = ReflectUtil.forName(className);
Object result = deserialize((byte[]) input.readObject(), clz, serialization);
if (dataType == MotanConstants.FLAG_RESPONSE) {
response.setValue(result);
} else if (dataType == MotanConstants.FLAG_RESPONSE_ATTACHMENT) {
response.setValue(result);
Map<String, String> attachment = decodeRequestAttachments(input);
checkAttachment(attachment);
} else if (dataType == MotanConstants.FLAG_RESPONSE_EXCEPTION) {
response.setException((Exception) result);
} else {
throw new MotanFrameworkException("decode error: response dataType not support " + dataType, MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR);
}
response.setRequestId(requestId);
input.close();
return response;
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class ServiceConfigBean method checkAndConfigExport.
/**
* 检查是否已经装配export,如果没有则到basicConfig查找
*/
private void checkAndConfigExport() {
if (StringUtils.isBlank(getExport()) && getBasicServiceConfig() != null && !StringUtils.isBlank(getBasicServiceConfig().getExport())) {
setExport(getBasicServiceConfig().getExport());
if (getBasicServiceConfig().getProtocols() != null) {
setProtocols(new ArrayList<ProtocolConfig>(getBasicServiceConfig().getProtocols()));
}
}
if (CollectionUtil.isEmpty(getProtocols()) && StringUtils.isNotEmpty(getExport())) {
Map<String, Integer> exportMap = ConfigUtil.parseExport(export);
if (!exportMap.isEmpty()) {
List<ProtocolConfig> protos = new ArrayList<ProtocolConfig>();
for (String p : exportMap.keySet()) {
ProtocolConfig proto = null;
try {
proto = beanFactory.getBean(p, ProtocolConfig.class);
} catch (NoSuchBeanDefinitionException e) {
}
if (proto == null) {
if (MotanConstants.PROTOCOL_MOTAN.equals(p)) {
proto = MotanFrameworkUtil.getDefaultProtocolConfig();
} else {
throw new MotanFrameworkException(String.format("cann't find %s ProtocolConfig bean! export:%s", p, export), MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
}
}
protos.add(proto);
}
setProtocols(protos);
}
}
if (StringUtils.isEmpty(getExport()) || CollectionUtil.isEmpty(getProtocols())) {
throw new MotanFrameworkException(String.format("%s ServiceConfig must config right export value!", getInterface().getName()), MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR);
}
}
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 AbstractEndpointFactory method createServer.
@Override
public Server createServer(URL url, MessageHandler messageHandler) {
HeartbeatFactory heartbeatFactory = getHeartbeatFactory(url);
messageHandler = heartbeatFactory.wrapMessageHandler(messageHandler);
synchronized (ipPort2ServerShareChannel) {
String ipPort = url.getServerPortStr();
String protocolKey = MotanFrameworkUtil.getProtocolKey(url);
boolean shareChannel = url.getBooleanParameter(URLParamType.shareChannel.getName(), URLParamType.shareChannel.getBooleanValue());
if (!shareChannel) {
// 独享一个端口
LoggerUtil.info(this.getClass().getSimpleName() + " create no_share_channel server: url={}", url);
// 如果端口已经被使用了,使用该server bind 会有异常
return innerCreateServer(url, messageHandler);
}
LoggerUtil.info(this.getClass().getSimpleName() + " create share_channel server: url={}", url);
Server server = ipPort2ServerShareChannel.get(ipPort);
if (server != null) {
// can't share service channel
if (!MotanFrameworkUtil.checkIfCanShallServiceChannel(server.getUrl(), url)) {
throw new MotanFrameworkException("Service export Error: share channel but some config param is different, protocol or codec or serialize or maxContentLength or maxServerConnection or maxWorkerThread or heartbeatFactory, source=" + server.getUrl() + " target=" + url, MotanErrorMsgConstant.FRAMEWORK_EXPORT_ERROR);
}
saveEndpoint2Urls(server2UrlsShareChannel, server, protocolKey);
return server;
}
url = url.createCopy();
// 共享server端口,由于有多个interfaces存在,所以把path设置为空
url.setPath("");
server = innerCreateServer(url, messageHandler);
ipPort2ServerShareChannel.put(ipPort, server);
saveEndpoint2Urls(server2UrlsShareChannel, server, protocolKey);
return server;
}
}
use of com.weibo.api.motan.exception.MotanFrameworkException in project motan by weibocom.
the class AbstractEndpointFactory method getHeartbeatFactory.
private HeartbeatFactory getHeartbeatFactory(URL url) {
String heartbeatFactoryName = url.getParameter(URLParamType.heartbeatFactory.getName(), URLParamType.heartbeatFactory.getValue());
HeartbeatFactory heartbeatFactory = ExtensionLoader.getExtensionLoader(HeartbeatFactory.class).getExtension(heartbeatFactoryName);
if (heartbeatFactory == null) {
throw new MotanFrameworkException("HeartbeatFactory not exist: " + heartbeatFactoryName);
}
return heartbeatFactory;
}
Aggregations