Package com.alibaba.dubbo.rpc

Examples of com.alibaba.dubbo.rpc.RpcException


                    // ignore
                }
            }
            return toUrls(url, providers);
        } catch (Throwable e) {
            throw new RpcException("Failed to lookup " + url + " from zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);
        }
    }
View Full Code Here


            Result result = invoker.invoke(invocation);
            Throwable e = result.getException();
            if (e != null) {
                String name = e.getClass().getName();
                if (name.startsWith(HESSIAN_EXCEPTION_PREFIX)) {
                    RpcException re = new RpcException("Failed to invoke remote service: " + getInterface() + ", method: "
                            + invocation.getMethodName() + ", cause: " + e.getMessage(), e);
                    throw setRpcExceptionCode(e, re);
                }
            }
            return result;
        } catch (RpcException e) {
            throw setRpcExceptionCode(e.getCause(), e);
        } catch (HessianException e) {
            throw setRpcExceptionCode(e, new RpcException("Failed to invoke remote service: " + getInterface() + ", method: "
                    + invocation.getMethodName() + ", cause: " + e.getMessage(), e));
        } catch (Throwable e) {
            return new RpcResult(e);
        }
    }
View Full Code Here

                result = invoker.invoke(invocation);
            }
        } catch (RpcException e) {
            throw setRpcExceptionCode(e.getCause(), e);
        } catch (Throwable e) {
            throw setRpcExceptionCode(e, new RpcException(e.getMessage(), e));
        }

        Throwable e = result.getException();
        if (e != null && e instanceof RemoteException) {
            throw setRpcExceptionCode(e, new RpcException("Failed to invoke remote service: " + getInterface() + ", method: "
                    + invocation.getMethodName() + ", url: " + invoker.getUrl() + ", cause: " + e.getMessage(), e));
        }
        return result;
    }
View Full Code Here

            rmiServiceExporter.setServiceInterface(invoker.getInterface());
            rmiServiceExporter.setService(proxyFactory.getProxy(invoker));
            try {
                rmiServiceExporter.afterPropertiesSet();
            } catch (RemoteException e) {
                throw new RpcException(e.getMessage(), e);
            }
            Exporter<T> exporter = new Exporter<T>() {
                public Invoker<T> getInvoker() {
                    return invoker;
                }
                public void unexport() {
                    try {
                        rmiServiceExporter.destroy();
                    } catch (Throwable e) {
                        logger.warn(e.getMessage(), e);
                    }
                    try {
                        invoker.destroy();
                    } catch (Throwable e) {
                        logger.warn(e.getMessage(), e);
                    }
                }
            };
            return exporter;
        } else {
            Remote remote = rmiProxyFactory.getProxy(invoker);
            // export.
            try {
                UnicastRemoteObject.exportObject(remote, 0);
            } catch (RemoteException e) {
                if ("object already exported".equalsIgnoreCase(e.getMessage())) {
                    logger.warn("Ignore 'object already exported' exception.", e);
                } else {
                    throw new RpcException("Export rmi service error.", e);
                }
            }
            // register.
            Registry registry = getOrCreateRegistry(invoker.getUrl().getPort());
            try {
                // bind service.
                registry.bind(invoker.getUrl().getPath(), remote);
            } catch (RemoteException e) {
                throw new RpcException("Bind rmi service [" + invoker.getUrl().getPath() + "] error.",
                        e);
            } catch (AlreadyBoundException e) {
                throw new RpcException("Bind rmi service error. Service name ["
                        + invoker.getUrl().getPath() + "] already bound.", e);
            }
            RmiExporter<T> exporter = new RmiExporter<T>(invoker, remote, registry);
            exporterMap.put(serviceKey(invoker.getUrl()), exporter);
            return exporter;
View Full Code Here

                        Throwable t = e.getTargetException();
                        if (t instanceof RemoteAccessException) {
                            t = ((RemoteAccessException)t).getCause();
                        }
                        if (t instanceof RemoteException) {
                            throw RmiInvoker.setRpcExceptionCode(t, new RpcException("Failed to invoke remote service: " + serviceType + ", method: "
                                    + invocation.getMethodName() + ", url: " + url + ", cause: " + t.getMessage(), t));
                        } else {
                            return new RpcResult(t);
                        }
                    } catch (Throwable e) {
                        if (e instanceof RemoteAccessException) {
                            e = ((RemoteAccessException)e).getCause();
                        }
                        throw RmiInvoker.setRpcExceptionCode(e, new RpcException("Failed to invoke remote service: " + serviceType + ", method: "
                                + invocation.getMethodName() + ", url: " + url + ", cause: " + e.getMessage(), e));
                    }
                }
                public void destroy() {
                }
            };
        } else {
            Invoker<T> invoker;
            try {
                if ("dubbo".equals(url.getParameter("codec"))) {
                    RmiProtocol.getRemoteClass(serviceType);
                }
                Registry registry = LocateRegistry.getRegistry(url.getHost(), url.getPort());
                String path = url.getPath();
                if (path == null || path.length() == 0) {
                    path = serviceType.getName();
                }
                invoker = new RmiInvoker<T>(registry, rmiProxyFactory, rmiProxyFactory.getInvoker(registry.lookup(path), serviceType, url));
            } catch (RemoteException e) {
                Throwable cause = e.getCause();
                boolean isExportedBySpringButNoSpringClass = ClassNotFoundException.class
                        .isInstance(cause)
                        && cause.getMessage().contains(
                                "org.springframework.remoting.rmi.RmiInvocationHandler");
   
                String msg = String
                        .format("Can not create remote object%s. url = %s",
                                isExportedBySpringButNoSpringClass ? "(Rmi object is exported by spring rmi but NO spring class org.springframework.remoting.rmi.RmiInvocationHandler at consumer side)"
                                        : "", url);
                throw new RpcException(msg, e);
            } catch (NotBoundException e) {
                throw new RpcException("Rmi service not found. url = " + url, e);
            }
            invokers.add(invoker);
            return invoker;
        }
    }
View Full Code Here

        }
    }

    public List<Invoker<T>> doList(Invocation invocation) {
        if (forbidden) {
            throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, "Forbid consumer " +  NetUtils.getLocalHost() + " access service " + getInterface().getName() + " from registry " + getUrl().getAddress() + " use dubbo version " + Version.getVersion() + ", Please check registry access list (whitelist/blacklist).");
        }
        List<Invoker<T>> invokers = null;
        Map<String, List<Invoker<T>>> localMethodInvokerMap = this.methodInvokerMap; // local reference
        if (localMethodInvokerMap != null && localMethodInvokerMap.size() > 0) {
            String methodName = invocation.getMethodName();
View Full Code Here

        }
    }

    public List<Invoker<T>> doList(Invocation invocation) {
        if (forbidden) {
            throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, "Forbid consumer " +  NetUtils.getLocalHost() + " access service " + getInterface().getName() + " from registry " + getUrl().getAddress() + " use dubbo version " + Version.getVersion() + ", Please check registry access list (whitelist/blacklist).");
        }
        List<Invoker<T>> invokers = null;
        Map<String, List<Invoker<T>>> localMethodInvokerMap = this.methodInvokerMap; // local reference
        if (localMethodInvokerMap != null && localMethodInvokerMap.size() > 0) {
            String methodName = RpcUtils.getMethodName(invocation);
View Full Code Here

    public void doRegister(URL url) {
        String key = toCategoryPath(url);
        String value = url.toFullString();
        String expire = String.valueOf(System.currentTimeMillis() + expirePeriod);
        boolean success = false;
        RpcException exception = null;
        for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
            JedisPool jedisPool = entry.getValue();
            try {
                Jedis jedis = jedisPool.getResource();
                try {
                    jedis.hset(key, value, expire);
                    jedis.publish(key, Constants.REGISTER);
                    success = true;
                    if (! replicate) {
                      break; //  如果服务器端已同步数据,只需写入单台机器
                    }
                } finally {
                    jedisPool.returnResource(jedis);
                }
            } catch (Throwable t) {
                exception = new RpcException("Failed to register service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
            }
        }
        if (exception != null) {
            if (success) {
                logger.warn(exception.getMessage(), exception);
            } else {
                throw exception;
            }
        }
    }
View Full Code Here

    @Override
    public void doUnregister(URL url) {
        String key = toCategoryPath(url);
        String value = url.toFullString();
        RpcException exception = null;
        boolean success = false;
        for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
            JedisPool jedisPool = entry.getValue();
            try {
                Jedis jedis = jedisPool.getResource();
                try {
                    jedis.hdel(key, value);
                    jedis.publish(key, Constants.UNREGISTER);
                    success = true;
                    if (! replicate) {
                      break; //  如果服务器端已同步数据,只需写入单台机器
                    }
                } finally {
                    jedisPool.returnResource(jedis);
                }
            } catch (Throwable t) {
                exception = new RpcException("Failed to unregister service to redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
            }
        }
        if (exception != null) {
            if (success) {
                logger.warn(exception.getMessage(), exception);
            } else {
                throw exception;
            }
        }
    }
View Full Code Here

            if (notifier == newNotifier) {
                notifier.start();
            }
        }
        boolean success = false;
        RpcException exception = null;
        for (Map.Entry<String, JedisPool> entry : jedisPools.entrySet()) {
            JedisPool jedisPool = entry.getValue();
            try {
                Jedis jedis = jedisPool.getResource();
                try {
                    if (service.endsWith(Constants.ANY_VALUE)) {
                        admin = true;
                        Set<String> keys = jedis.keys(service);
                        if (keys != null && keys.size() > 0) {
                            Map<String, Set<String>> serviceKeys = new HashMap<String, Set<String>>();
                            for (String key : keys) {
                                String serviceKey = toServicePath(key);
                                Set<String> sk = serviceKeys.get(serviceKey);
                                if (sk == null) {
                                    sk = new HashSet<String>();
                                    serviceKeys.put(serviceKey, sk);
                                }
                                sk.add(key);
                            }
                            for (Set<String> sk : serviceKeys.values()) {
                                doNotify(jedis, sk, url, Arrays.asList(listener));
                            }
                        }
                    } else {
                        doNotify(jedis, jedis.keys(service + Constants.PATH_SEPARATOR + Constants.ANY_VALUE), url, Arrays.asList(listener));
                    }
                    success = true;
                    break; // 只需读一个服务器的数据
                } finally {
                    jedisPool.returnResource(jedis);
                }
            } catch(Throwable t) { // 尝试下一个服务器
                exception = new RpcException("Failed to subscribe service from redis registry. registry: " + entry.getKey() + ", service: " + url + ", cause: " + t.getMessage(), t);
            }
        }
        if (exception != null) {
            if (success) {
                logger.warn(exception.getMessage(), exception);
            } else {
                throw exception;
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.rpc.RpcException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.