Search in sources :

Example 11 with MotanFrameworkException

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);
    }
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) ArrayList(java.util.ArrayList)

Example 12 with MotanFrameworkException

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();
    }
}
Also used : CommandListener(com.weibo.api.motan.registry.support.command.CommandListener) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) IZkDataListener(org.I0Itec.zkclient.IZkDataListener)

Example 13 with MotanFrameworkException

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;
}
Also used : Response(com.weibo.api.motan.rpc.Response) DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException)

Example 14 with MotanFrameworkException

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);
    }
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URL(com.weibo.api.motan.rpc.URL) NotifyListener(com.weibo.api.motan.registry.NotifyListener)

Example 15 with MotanFrameworkException

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);
}
Also used : DefaultResponse(com.weibo.api.motan.rpc.DefaultResponse) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) Request(com.weibo.api.motan.rpc.Request) MotanServiceException(com.weibo.api.motan.exception.MotanServiceException)

Aggregations

MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)41 URL (com.weibo.api.motan.rpc.URL)7 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)6 ArrayList (java.util.ArrayList)6 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)5 IOException (java.io.IOException)5 Method (java.lang.reflect.Method)4 Registry (com.weibo.api.motan.registry.Registry)3 Response (com.weibo.api.motan.rpc.Response)3 HeartbeatFactory (com.weibo.api.motan.transport.HeartbeatFactory)3 ObjectInput (java.io.ObjectInput)3 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Serialization (com.weibo.api.motan.codec.Serialization)2 ConfigHandler (com.weibo.api.motan.config.handler.ConfigHandler)2 CommandListener (com.weibo.api.motan.registry.support.command.CommandListener)2 ServiceListener (com.weibo.api.motan.registry.support.command.ServiceListener)2 TransportException (com.weibo.api.motan.transport.TransportException)2 Map (java.util.Map)2 IZkChildListener (org.I0Itec.zkclient.IZkChildListener)2