类com.alibaba.dubbo.rpc.StaticContext源码实例Demo

下面列出了怎么用com.alibaba.dubbo.rpc.StaticContext的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dubbo-2.6.5   文件: ReferenceConfig.java
private static void checkAndConvertImplicitConfig(MethodConfig method, Map<String, String> map, Map<Object, Object> attributes) {
    //check config conflict 异步返回禁用、异步返回调用对象、异常调用对象为空
    if (Boolean.FALSE.equals(method.isReturn()) && (method.getOnreturn() != null || method.getOnthrow() != null)) {
        throw new IllegalStateException("method config error : return attribute must be set true when onreturn or onthrow has been setted.");
    }
    //convert onreturn methodName to Method 覆盖静态上下文中异步调用的方法 onreturn.method
    String onReturnMethodKey = StaticContext.getKey(map, method.getName(), Constants.ON_RETURN_METHOD_KEY);
    Object onReturnMethod = attributes.get(onReturnMethodKey);
    if (onReturnMethod instanceof String) {
        attributes.put(onReturnMethodKey, getMethodByName(method.getOnreturn().getClass(), onReturnMethod.toString()));
    }
    //convert onthrow methodName to Method 覆盖静态上下文中异常调用方法 onthrow.method
    String onThrowMethodKey = StaticContext.getKey(map, method.getName(), Constants.ON_THROW_METHOD_KEY);
    Object onThrowMethod = attributes.get(onThrowMethodKey);
    if (onThrowMethod instanceof String) {
        attributes.put(onThrowMethodKey, getMethodByName(method.getOnthrow().getClass(), onThrowMethod.toString()));
    }
    //convert oninvoke methodName to Method 覆盖静态上下文中异步调用后执行的方法 oninvoke.method
    String onInvokeMethodKey = StaticContext.getKey(map, method.getName(), Constants.ON_INVOKE_METHOD_KEY);
    Object onInvokeMethod = attributes.get(onInvokeMethodKey);
    if (onInvokeMethod instanceof String) {
        attributes.put(onInvokeMethodKey, getMethodByName(method.getOninvoke().getClass(), onInvokeMethod.toString()));
    }
}
 
源代码2 项目: dubbox   文件: ReferenceConfig.java
private static void checkAndConvertImplicitConfig(MethodConfig method, Map<String,String> map, Map<Object,Object> attributes){
  //check config conflict
    if (Boolean.FALSE.equals(method.isReturn()) && (method.getOnreturn() != null || method.getOnthrow() != null)) {
        throw new IllegalStateException("method config error : return attribute must be set true when onreturn or onthrow has been setted.");
    }
    //convert onreturn methodName to Method
    String onReturnMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_RETURN_METHOD_KEY);
    Object onReturnMethod = attributes.get(onReturnMethodKey);
    if (onReturnMethod != null && onReturnMethod instanceof String){
        attributes.put(onReturnMethodKey, getMethodByName(method.getOnreturn().getClass(), onReturnMethod.toString()));
    }
    //convert onthrow methodName to Method
    String onThrowMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_THROW_METHOD_KEY);
    Object onThrowMethod = attributes.get(onThrowMethodKey);
    if (onThrowMethod != null && onThrowMethod instanceof String){
        attributes.put(onThrowMethodKey, getMethodByName(method.getOnthrow().getClass(), onThrowMethod.toString()));
    }
    //convert oninvoke methodName to Method
    String onInvokeMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_INVOKE_METHOD_KEY);
    Object onInvokeMethod = attributes.get(onInvokeMethodKey);
    if (onInvokeMethod != null && onInvokeMethod instanceof String){
        attributes.put(onInvokeMethodKey, getMethodByName(method.getOninvoke().getClass(), onInvokeMethod.toString()));
    }
}
 
源代码3 项目: dubbox-hystrix   文件: ReferenceConfig.java
private static void checkAndConvertImplicitConfig(MethodConfig method, Map<String,String> map, Map<Object,Object> attributes){
  //check config conflict
    if (Boolean.FALSE.equals(method.isReturn()) && (method.getOnreturn() != null || method.getOnthrow() != null)) {
        throw new IllegalStateException("method config error : return attribute must be set true when onreturn or onthrow has been setted.");
    }
    //convert onreturn methodName to Method
    String onReturnMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_RETURN_METHOD_KEY);
    Object onReturnMethod = attributes.get(onReturnMethodKey);
    if (onReturnMethod != null && onReturnMethod instanceof String){
        attributes.put(onReturnMethodKey, getMethodByName(method.getOnreturn().getClass(), onReturnMethod.toString()));
    }
    //convert onthrow methodName to Method
    String onThrowMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_THROW_METHOD_KEY);
    Object onThrowMethod = attributes.get(onThrowMethodKey);
    if (onThrowMethod != null && onThrowMethod instanceof String){
        attributes.put(onThrowMethodKey, getMethodByName(method.getOnthrow().getClass(), onThrowMethod.toString()));
    }
    //convert oninvoke methodName to Method
    String onInvokeMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_INVOKE_METHOD_KEY);
    Object onInvokeMethod = attributes.get(onInvokeMethodKey);
    if (onInvokeMethod != null && onInvokeMethod instanceof String){
        attributes.put(onInvokeMethodKey, getMethodByName(method.getOninvoke().getClass(), onInvokeMethod.toString()));
    }
}
 
源代码4 项目: dubbo3   文件: ReferenceConfig.java
private static void checkAndConvertImplicitConfig(MethodConfig method, Map<String, String> map, Map<Object, Object> attributes) {
    //check config conflict
    if (Boolean.FALSE.equals(method.isReturn()) && (method.getOnreturn() != null || method.getOnthrow() != null)) {
        throw new IllegalStateException("method config error : return attribute must be set true when onreturn or onthrow has been setted.");
    }
    //convert onreturn methodName to Method
    String onReturnMethodKey = StaticContext.getKey(map, method.getName(), Constants.ON_RETURN_METHOD_KEY);
    Object onReturnMethod = attributes.get(onReturnMethodKey);
    if (onReturnMethod != null && onReturnMethod instanceof String) {
        attributes.put(onReturnMethodKey, getMethodByName(method.getOnreturn().getClass(), onReturnMethod.toString()));
    }
    //convert onthrow methodName to Method
    String onThrowMethodKey = StaticContext.getKey(map, method.getName(), Constants.ON_THROW_METHOD_KEY);
    Object onThrowMethod = attributes.get(onThrowMethodKey);
    if (onThrowMethod != null && onThrowMethod instanceof String) {
        attributes.put(onThrowMethodKey, getMethodByName(method.getOnthrow().getClass(), onThrowMethod.toString()));
    }
    //convert oninvoke methodName to Method
    String onInvokeMethodKey = StaticContext.getKey(map, method.getName(), Constants.ON_INVOKE_METHOD_KEY);
    Object onInvokeMethod = attributes.get(onInvokeMethodKey);
    if (onInvokeMethod != null && onInvokeMethod instanceof String) {
        attributes.put(onInvokeMethodKey, getMethodByName(method.getOninvoke().getClass(), onInvokeMethod.toString()));
    }
}
 
源代码5 项目: dubbox   文件: ReferenceConfig.java
private static void checkAndConvertImplicitConfig(MethodConfig method, Map<String,String> map, Map<Object,Object> attributes){
  //check config conflict
    if (Boolean.FALSE.equals(method.isReturn()) && (method.getOnreturn() != null || method.getOnthrow() != null)) {
        throw new IllegalStateException("method config error : return attribute must be set true when onreturn or onthrow has been setted.");
    }
    //convert onreturn methodName to Method
    String onReturnMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_RETURN_METHOD_KEY);
    Object onReturnMethod = attributes.get(onReturnMethodKey);
    if (onReturnMethod != null && onReturnMethod instanceof String){
        attributes.put(onReturnMethodKey, getMethodByName(method.getOnreturn().getClass(), onReturnMethod.toString()));
    }
    //convert onthrow methodName to Method
    String onThrowMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_THROW_METHOD_KEY);
    Object onThrowMethod = attributes.get(onThrowMethodKey);
    if (onThrowMethod != null && onThrowMethod instanceof String){
        attributes.put(onThrowMethodKey, getMethodByName(method.getOnthrow().getClass(), onThrowMethod.toString()));
    }
    //convert oninvoke methodName to Method
    String onInvokeMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_INVOKE_METHOD_KEY);
    Object onInvokeMethod = attributes.get(onInvokeMethodKey);
    if (onInvokeMethod != null && onInvokeMethod instanceof String){
        attributes.put(onInvokeMethodKey, getMethodByName(method.getOninvoke().getClass(), onInvokeMethod.toString()));
    }
}
 
源代码6 项目: dubbox   文件: ReferenceConfig.java
private static void checkAndConvertImplicitConfig(MethodConfig method, Map<String,String> map, Map<Object,Object> attributes){
  //check config conflict
    if (Boolean.FALSE.equals(method.isReturn()) && (method.getOnreturn() != null || method.getOnthrow() != null)) {
        throw new IllegalStateException("method config error : return attribute must be set true when onreturn or onthrow has been setted.");
    }
    //convert onreturn methodName to Method
    String onReturnMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_RETURN_METHOD_KEY);
    Object onReturnMethod = attributes.get(onReturnMethodKey);
    if (onReturnMethod != null && onReturnMethod instanceof String){
        attributes.put(onReturnMethodKey, getMethodByName(method.getOnreturn().getClass(), onReturnMethod.toString()));
    }
    //convert onthrow methodName to Method
    String onThrowMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_THROW_METHOD_KEY);
    Object onThrowMethod = attributes.get(onThrowMethodKey);
    if (onThrowMethod != null && onThrowMethod instanceof String){
        attributes.put(onThrowMethodKey, getMethodByName(method.getOnthrow().getClass(), onThrowMethod.toString()));
    }
    //convert oninvoke methodName to Method
    String onInvokeMethodKey = StaticContext.getKey(map,method.getName(),Constants.ON_INVOKE_METHOD_KEY);
    Object onInvokeMethod = attributes.get(onInvokeMethodKey);
    if (onInvokeMethod != null && onInvokeMethod instanceof String){
        attributes.put(onInvokeMethodKey, getMethodByName(method.getOninvoke().getClass(), onInvokeMethod.toString()));
    }
}
 
源代码7 项目: dubbo-2.6.5   文件: FutureFilter.java
private void fireThrowCallback(final Invoker<?> invoker, final Invocation invocation, final Throwable exception) {
//        从静态上下文中获取抛异常的方法 onthrow.method属性值指定=》
        final Method onthrowMethod = (Method) StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_METHOD_KEY));
//        从静态上下文中获取抛异常的对象 onthrow.instance属性值指定
        final Object onthrowInst = StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_INSTANCE_KEY));

        //onthrow callback not configured
        if (onthrowMethod == null && onthrowInst == null) {
            return;
        }
        if (onthrowMethod == null || onthrowInst == null) {
            throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() + " has a onthrow callback config , but no such " + (onthrowMethod == null ? "method" : "instance") + " found. url:" + invoker.getUrl());
        }
        if (!onthrowMethod.isAccessible()) {
            onthrowMethod.setAccessible(true);
        }
        Class<?>[] rParaTypes = onthrowMethod.getParameterTypes();
        if (rParaTypes[0].isAssignableFrom(exception.getClass())) {
            try {
                Object[] args = invocation.getArguments();
                Object[] params;

                if (rParaTypes.length > 1) {
                    if (rParaTypes.length == 2 && rParaTypes[1].isAssignableFrom(Object[].class)) {
                        params = new Object[2];
                        params[0] = exception;
                        params[1] = args;
                    } else {
                        params = new Object[args.length + 1];
                        params[0] = exception;
                        System.arraycopy(args, 0, params, 1, args.length);
                    }
                } else {
                    params = new Object[]{exception};
                }
//                异常方法执行
                onthrowMethod.invoke(onthrowInst, params);
            } catch (Throwable e) {
                logger.error(invocation.getMethodName() + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), e);
            }
        } else {
            logger.error(invocation.getMethodName() + ".call back method invoke error . callback method :" + onthrowMethod + ", url:" + invoker.getUrl(), exception);
        }
    }
 
源代码8 项目: dubbo-2.6.5   文件: ImplicitCallBackTest.java
public void initOrResetUrl(boolean isAsync) throws Exception {
    int port = NetUtils.getAvailablePort();
    consumerUrl = serviceURL = URL.valueOf("dubbo://127.0.0.1:" + port + "/" + IDemoService.class.getName() + "?group=test&async=" + isAsync + "&timeout=100000&reference.filter=future");
    StaticContext.getSystemContext().clear();
}
 
源代码9 项目: dubbo-2.6.5   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnthrow() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_METHOD_KEY), onThrowMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_INSTANCE_KEY), notify);
}
 
源代码10 项目: dubbo-2.6.5   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnreturn() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_METHOD_KEY), onReturnMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_INSTANCE_KEY), notify);

}
 
源代码11 项目: dubbo-2.6.5   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOninvoke() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_METHOD_KEY), onInvokeMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_INSTANCE_KEY), notify);
}
 
源代码12 项目: dubbox   文件: FutureFilter.java
private void fireThrowCallback(final Invoker<?> invoker, final Invocation invocation, final Throwable exception) {
    final Method onthrowMethod = (Method)StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_METHOD_KEY));
    final Object onthrowInst = StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_INSTANCE_KEY));

    //没有设置onthrow callback.
    if (onthrowMethod == null  &&  onthrowInst == null ){
        return ;
    }
    if (onthrowMethod == null  ||  onthrowInst == null ){
        throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() +" has a onthrow callback config , but no such "+(onthrowMethod == null ? "method" : "instance")+" found. url:"+invoker.getUrl());
    }
    if (onthrowMethod != null && ! onthrowMethod.isAccessible()) {
        onthrowMethod.setAccessible(true);
    }
    Class<?>[] rParaTypes = onthrowMethod.getParameterTypes() ;
    if (rParaTypes[0].isAssignableFrom(exception.getClass())){
        try {
            Object[] args = invocation.getArguments();
            Object[] params;
            
            if (rParaTypes.length >1 ) {
                if (rParaTypes.length == 2 && rParaTypes[1].isAssignableFrom(Object[].class)){
                    params = new Object[2];
                    params[0] = exception;
                    params[1] = args ;
                }else {
                    params = new Object[args.length + 1];
                    params[0] = exception;
                    System.arraycopy(args, 0, params, 1, args.length);
                }
            } else {
                params = new Object[] { exception };
            }
            onthrowMethod.invoke(onthrowInst,params);
        } catch (Throwable e) {
            logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), e);
        } 
    } else {
        logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), exception);
    }
}
 
源代码13 项目: dubbox   文件: ImplicitCallBackTest.java
public void initOrResetUrl(boolean isAsync) throws Exception {
    int port = NetUtils.getAvailablePort() ;
    consumerUrl = serviceURL =  URL.valueOf("dubbo://127.0.0.1:"+port+"/"+IDemoService.class.getName()+"?group=test&async="+isAsync+"&timeout=100000&reference.filter=future" );
    StaticContext.getSystemContext().clear();
}
 
源代码14 项目: dubbox   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnthrow() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_METHOD_KEY),onThrowMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_INSTANCE_KEY),notify);
}
 
源代码15 项目: dubbox   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnreturn() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_METHOD_KEY),onReturnMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_INSTANCE_KEY),notify);
    
}
 
源代码16 项目: dubbox   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOninvoke() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_METHOD_KEY),onInvokeMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_INSTANCE_KEY),notify);
}
 
源代码17 项目: dubbox-hystrix   文件: FutureFilter.java
private void fireThrowCallback(final Invoker<?> invoker, final Invocation invocation, final Throwable exception) {
    final Method onthrowMethod = (Method)StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_METHOD_KEY));
    final Object onthrowInst = StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_INSTANCE_KEY));

    //没有设置onthrow callback.
    if (onthrowMethod == null  &&  onthrowInst == null ){
        return ;
    }
    if (onthrowMethod == null  ||  onthrowInst == null ){
        throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() +" has a onthrow callback config , but no such "+(onthrowMethod == null ? "method" : "instance")+" found. url:"+invoker.getUrl());
    }
    if (onthrowMethod != null && ! onthrowMethod.isAccessible()) {
        onthrowMethod.setAccessible(true);
    }
    Class<?>[] rParaTypes = onthrowMethod.getParameterTypes() ;
    if (rParaTypes[0].isAssignableFrom(exception.getClass())){
        try {
            Object[] args = invocation.getArguments();
            Object[] params;
            
            if (rParaTypes.length >1 ) {
                if (rParaTypes.length == 2 && rParaTypes[1].isAssignableFrom(Object[].class)){
                    params = new Object[2];
                    params[0] = exception;
                    params[1] = args ;
                }else {
                    params = new Object[args.length + 1];
                    params[0] = exception;
                    System.arraycopy(args, 0, params, 1, args.length);
                }
            } else {
                params = new Object[] { exception };
            }
            onthrowMethod.invoke(onthrowInst,params);
        } catch (Throwable e) {
            logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), e);
        } 
    } else {
        logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), exception);
    }
}
 
源代码18 项目: dubbox-hystrix   文件: ImplicitCallBackTest.java
public void initOrResetUrl(boolean isAsync) throws Exception {
    int port = NetUtils.getAvailablePort() ;
    consumerUrl = serviceURL =  URL.valueOf("dubbo://127.0.0.1:"+port+"/"+IDemoService.class.getName()+"?group=test&async="+isAsync+"&timeout=100000&reference.filter=future" );
    StaticContext.getSystemContext().clear();
}
 
源代码19 项目: dubbox-hystrix   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnthrow() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_METHOD_KEY),onThrowMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_INSTANCE_KEY),notify);
}
 
源代码20 项目: dubbox-hystrix   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnreturn() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_METHOD_KEY),onReturnMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_INSTANCE_KEY),notify);
    
}
 
源代码21 项目: dubbox-hystrix   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOninvoke() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_METHOD_KEY),onInvokeMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_INSTANCE_KEY),notify);
}
 
源代码22 项目: dubbo3   文件: FutureFilter.java
private void fireThrowCallback(final Invoker<?> invoker, final Invocation invocation, final Throwable exception) {
    final Method onthrowMethod = (Method)StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_METHOD_KEY));
    final Object onthrowInst = StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_INSTANCE_KEY));

    //没有设置onthrow callback.
    if (onthrowMethod == null  &&  onthrowInst == null ){
        return ;
    }
    if (onthrowMethod == null  ||  onthrowInst == null ){
        throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() +" has a onthrow callback config , but no such "+(onthrowMethod == null ? "method" : "instance")+" found. url:"+invoker.getUrl());
    }
    if (! onthrowMethod.isAccessible()) {
        onthrowMethod.setAccessible(true);
    }
    Class<?>[] rParaTypes = onthrowMethod.getParameterTypes() ;
    if (rParaTypes[0].isAssignableFrom(exception.getClass())){
        try {
            Object[] args = invocation.getArguments();
            Object[] params;
            
            if (rParaTypes.length >1 ) {
                if (rParaTypes.length == 2 && rParaTypes[1].isAssignableFrom(Object[].class)){
                    params = new Object[2];
                    params[0] = exception;
                    params[1] = args ;
                }else {
                    params = new Object[args.length + 1];
                    params[0] = exception;
                    System.arraycopy(args, 0, params, 1, args.length);
                }
            } else {
                params = new Object[] { exception };
            }
            onthrowMethod.invoke(onthrowInst,params);
        } catch (Throwable e) {
            logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), e);
        } 
    } else {
        logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), exception);
    }
}
 
源代码23 项目: dubbo3   文件: ImplicitCallBackTest.java
public void initOrResetUrl(boolean isAsync) throws Exception {
    int port = NetUtils.getAvailablePort() ;
    consumerUrl = serviceURL =  URL.valueOf("dubbo://127.0.0.1:"+port+"/"+IDemoService.class.getName()+"?group=test&async="+isAsync+"&timeout=100000&reference.filter=future" );
    StaticContext.getSystemContext().clear();
}
 
源代码24 项目: dubbo3   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnthrow() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_METHOD_KEY),onThrowMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_INSTANCE_KEY),notify);
}
 
源代码25 项目: dubbo3   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnreturn() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_METHOD_KEY),onReturnMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_INSTANCE_KEY),notify);
    
}
 
源代码26 项目: dubbo3   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOninvoke() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_METHOD_KEY),onInvokeMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_INVOKE_INSTANCE_KEY),notify);
}
 
源代码27 项目: dubbox   文件: FutureFilter.java
private void fireThrowCallback(final Invoker<?> invoker, final Invocation invocation, final Throwable exception) {
    final Method onthrowMethod = (Method)StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_METHOD_KEY));
    final Object onthrowInst = StaticContext.getSystemContext().get(StaticContext.getKey(invoker.getUrl(), invocation.getMethodName(), Constants.ON_THROW_INSTANCE_KEY));

    //没有设置onthrow callback.
    if (onthrowMethod == null  &&  onthrowInst == null ){
        return ;
    }
    if (onthrowMethod == null  ||  onthrowInst == null ){
        throw new IllegalStateException("service:" + invoker.getUrl().getServiceKey() +" has a onthrow callback config , but no such "+(onthrowMethod == null ? "method" : "instance")+" found. url:"+invoker.getUrl());
    }
    if (onthrowMethod != null && ! onthrowMethod.isAccessible()) {
        onthrowMethod.setAccessible(true);
    }
    Class<?>[] rParaTypes = onthrowMethod.getParameterTypes() ;
    if (rParaTypes[0].isAssignableFrom(exception.getClass())){
        try {
            Object[] args = invocation.getArguments();
            Object[] params;
            
            if (rParaTypes.length >1 ) {
                if (rParaTypes.length == 2 && rParaTypes[1].isAssignableFrom(Object[].class)){
                    params = new Object[2];
                    params[0] = exception;
                    params[1] = args ;
                }else {
                    params = new Object[args.length + 1];
                    params[0] = exception;
                    System.arraycopy(args, 0, params, 1, args.length);
                }
            } else {
                params = new Object[] { exception };
            }
            onthrowMethod.invoke(onthrowInst,params);
        } catch (Throwable e) {
            logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), e);
        } 
    } else {
        logger.error(invocation.getMethodName() +".call back method invoke error . callback method :" + onthrowMethod + ", url:"+ invoker.getUrl(), exception);
    }
}
 
源代码28 项目: dubbox   文件: ImplicitCallBackTest.java
public void initOrResetUrl(boolean isAsync) throws Exception {
    int port = NetUtils.getAvailablePort() ;
    consumerUrl = serviceURL =  URL.valueOf("dubbo://127.0.0.1:"+port+"/"+IDemoService.class.getName()+"?group=test&async="+isAsync+"&timeout=100000&reference.filter=future" );
    StaticContext.getSystemContext().clear();
}
 
源代码29 项目: dubbox   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnthrow() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_METHOD_KEY),onThrowMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_THROW_INSTANCE_KEY),notify);
}
 
源代码30 项目: dubbox   文件: ImplicitCallBackTest.java
public void initImplicitCallBackURL_onlyOnreturn() throws Exception {
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_METHOD_KEY),onReturnMethod);
    StaticContext.getSystemContext().put(StaticContext.getKey(consumerUrl, "get", Constants.ON_RETURN_INSTANCE_KEY),notify);
    
}
 
 类所在包
 类方法
 同包方法