com.alibaba.dubbo.rpc.StaticContext Java Examples

The following examples show how to use com.alibaba.dubbo.rpc.StaticContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReferenceConfig.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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()));
    }
}
 
Example #2
Source File: ReferenceConfig.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
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()));
    }
}
 
Example #3
Source File: ReferenceConfig.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
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()));
    }
}
 
Example #4
Source File: ReferenceConfig.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
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()));
    }
}
 
Example #5
Source File: ReferenceConfig.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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()));
    }
}
 
Example #6
Source File: ReferenceConfig.java    From dubbox with Apache License 2.0 6 votes vote down vote up
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()));
    }
}
 
Example #7
Source File: ImplicitCallBackTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #8
Source File: FutureFilter.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example #9
Source File: ImplicitCallBackTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
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);
    
}
 
Example #10
Source File: ImplicitCallBackTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #11
Source File: FutureFilter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example #12
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #13
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #14
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
    
}
 
Example #15
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #16
Source File: FutureFilter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example #17
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #18
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #19
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
    
}
 
Example #20
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #21
Source File: ImplicitCallBackTest.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #22
Source File: FutureFilter.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
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);
        }
    }
 
Example #23
Source File: ImplicitCallBackTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #24
Source File: ImplicitCallBackTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
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);
    
}
 
Example #25
Source File: ImplicitCallBackTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #26
Source File: ImplicitCallBackTest.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example #27
Source File: FutureFilter.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
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);
    }
}
 
Example #28
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #29
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
    
}
 
Example #30
Source File: ImplicitCallBackTest.java    From dubbox with Apache License 2.0 4 votes vote down vote up
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);
}