Java Code Examples for com.alibaba.dubbo.rpc.Invoker#getInterface()

The following examples show how to use com.alibaba.dubbo.rpc.Invoker#getInterface() . 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: AbstractProxyFactory.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example 2
Source File: DubboMythTransactionFilter.java    From myth with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Result invoke(final Invoker<?> invoker, final Invocation invocation) throws RpcException {
    String methodName = invocation.getMethodName();
    Class clazz = invoker.getInterface();
    Class[] args = invocation.getParameterTypes();
    Method method;
    Myth myth = null;
    try {
        method = clazz.getDeclaredMethod(methodName, args);
        myth = method.getAnnotation(Myth.class);
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    if (Objects.nonNull(myth)) {
        final MythTransactionContext mythTransactionContext = TransactionContextLocal.getInstance().get();
        if (Objects.nonNull(mythTransactionContext)) {
            RpcMediator.getInstance().transmit(RpcContext.getContext()::setAttachment,
                    mythTransactionContext);
        }
    }
    return invoker.invoke(invocation);
}
 
Example 3
Source File: AbstractProxyFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example 4
Source File: AbstractProxyFactory.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example 5
Source File: AbstractProxyFactory.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i ++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[] {invoker.getInterface(), EchoService.class};
    }
    return getProxy(invoker, interfaces);
}
 
Example 6
Source File: ProtocolFilterWrapper.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private static <T> Invoker<T> buildInvokerChain(final Invoker<T> invoker, String key, String group) {
    Invoker<T> last = invoker;
    List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(invoker.getUrl(), key, group);
    if (filters.size() > 0) {
        for (int i = filters.size() - 1; i >= 0; i --) {
            final Filter filter = filters.get(i);
            final Invoker<T> next = last;
            last = new Invoker<T>() {

                public Class<T> getInterface() {
                    return invoker.getInterface();
                }

                public URL getUrl() {
                    return invoker.getUrl();
                }

                public boolean isAvailable() {
                    return invoker.isAvailable();
                }

                public Result invoke(Invocation invocation) throws RpcException {
                    return filter.invoke(next, invocation);
                }

                public void destroy() {
                    invoker.destroy();
                }

                @Override
                public String toString() {
                    return invoker.toString();
                }
            };
        }
    }
    return last;
}
 
Example 7
Source File: AbstractExporter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public AbstractExporter(Invoker<T> invoker) {
    if (invoker == null)
        throw new IllegalStateException("service invoker == null");
    if (invoker.getInterface() == null)
        throw new IllegalStateException("service type == null");
    if (invoker.getUrl() == null)
        throw new IllegalStateException("service url == null");
    this.invoker = invoker;
}
 
Example 8
Source File: TokenFilter.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation inv)
		throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
   		String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
   		if (! token.equals(remoteToken)) {
   			throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());
   		}
    }
	return invoker.invoke(inv);
}
 
Example 9
Source File: ProtocolFilterWrapper.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
private static <T> Invoker<T> buildInvokerChain(final Invoker<T> invoker, String key, String group) {
    Invoker<T> last = invoker;
    List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(invoker.getUrl(), key, group);
    if (filters.size() > 0) {
        for (int i = filters.size() - 1; i >= 0; i --) {
            final Filter filter = filters.get(i);
            final Invoker<T> next = last;
            last = new Invoker<T>() {

                public Class<T> getInterface() {
                    return invoker.getInterface();
                }

                public URL getUrl() {
                    return invoker.getUrl();
                }

                public boolean isAvailable() {
                    return invoker.isAvailable();
                }

                public Result invoke(Invocation invocation) throws RpcException {
                    return filter.invoke(next, invocation);
                }

                public void destroy() {
                    invoker.destroy();
                }

                @Override
                public String toString() {
                    return invoker.toString();
                }
            };
        }
    }
    return last;
}
 
Example 10
Source File: AbstractExporter.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public AbstractExporter(Invoker<T> invoker) {
    if (invoker == null)
        throw new IllegalStateException("service invoker == null");
    if (invoker.getInterface() == null)
        throw new IllegalStateException("service type == null");
    if (invoker.getUrl() == null)
        throw new IllegalStateException("service url == null");
    this.invoker = invoker;
}
 
Example 11
Source File: ConsumerSubscribeListener.java    From dubbo-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public void referred(Invoker<?> invoker) throws RpcException {
  Class<?> interfaceClass = invoker.getInterface();
  URL url = invoker.getUrl();
  String group = url.getParameter(DubboSpringBootStarterConstants.GROUP);
  String version = url.getParameter(DubboSpringBootStarterConstants.VERSION);
  ClassIdBean classIdBean = new ClassIdBean(interfaceClass, group, version);
  SUBSCRIBEDINTERFACES_SET.add(classIdBean);
}
 
Example 12
Source File: TokenFilter.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation inv)
		throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
   		String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
   		if (! token.equals(remoteToken)) {
   			throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());
   		}
    }
	return invoker.invoke(inv);
}
 
Example 13
Source File: AbstractExporter.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public AbstractExporter(Invoker<T> invoker) {
    if (invoker == null)
        throw new IllegalStateException("service invoker == null");
    if (invoker.getInterface() == null)
        throw new IllegalStateException("service type == null");
    if (invoker.getUrl() == null)
        throw new IllegalStateException("service url == null");
    this.invoker = invoker;
}
 
Example 14
Source File: ProtocolFilterWrapper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static <T> Invoker<T> buildInvokerChain(final Invoker<T> invoker, String key, String group) {
    Invoker<T> last = invoker;
    List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(invoker.getUrl(), key, group);
    if (filters.size() > 0) {
        for (int i = filters.size() - 1; i >= 0; i --) {
            final Filter filter = filters.get(i);
            final Invoker<T> next = last;
            last = new Invoker<T>() {

                public Class<T> getInterface() {
                    return invoker.getInterface();
                }

                public URL getUrl() {
                    return invoker.getUrl();
                }

                public boolean isAvailable() {
                    return invoker.isAvailable();
                }

                public Result invoke(Invocation invocation) throws RpcException {
                    return filter.invoke(next, invocation);
                }

                public void destroy() {
                    invoker.destroy();
                }

                @Override
                public String toString() {
                    return invoker.toString();
                }
            };
        }
    }
    return last;
}
 
Example 15
Source File: TokenFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation inv)
		throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
   		String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
   		if (! token.equals(remoteToken)) {
   			throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());
   		}
    }
	return invoker.invoke(inv);
}
 
Example 16
Source File: TokenFilter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation inv)
		throws RpcException {
    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);
    if (ConfigUtils.isNotEmpty(token)) {
        Class<?> serviceType = invoker.getInterface();
        Map<String, String> attachments = inv.getAttachments();
   		String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);
   		if (! token.equals(remoteToken)) {
   			throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());
   		}
    }
	return invoker.invoke(inv);
}
 
Example 17
Source File: AbstractExporter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public AbstractExporter(Invoker<T> invoker) {
    if (invoker == null)
        throw new IllegalStateException("service invoker == null");
    if (invoker.getInterface() == null)
        throw new IllegalStateException("service type == null");
    if (invoker.getUrl() == null)
        throw new IllegalStateException("service url == null");
    this.invoker = invoker;
}
 
Example 18
Source File: RedisProtocolTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testReferClass() {
    Invoker<IDemoService> refer = protocol.refer(IDemoService.class, registryUrl);

    Class<IDemoService> serviceClass = refer.getInterface();
    assertThat(serviceClass.getName(), is("com.alibaba.dubbo.rpc.protocol.redis.IDemoService"));
}
 
Example 19
Source File: ProtocolFilterWrapper.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static <T> Invoker<T> buildInvokerChain(final Invoker<T> invoker, String key, String group) {
    Invoker<T> last = invoker;
    List<Filter> filters = ExtensionLoader.getExtensionLoader(Filter.class).getActivateExtension(invoker.getUrl(), key, group);
    if (filters.size() > 0) {
        for (int i = filters.size() - 1; i >= 0; i --) {
            final Filter filter = filters.get(i);
            final Invoker<T> next = last;
            last = new Invoker<T>() {

                public Class<T> getInterface() {
                    return invoker.getInterface();
                }

                public URL getUrl() {
                    return invoker.getUrl();
                }

                public boolean isAvailable() {
                    return invoker.isAvailable();
                }

                public Result invoke(Invocation invocation) throws RpcException {
                    return filter.invoke(next, invocation);
                }

                public void destroy() {
                    invoker.destroy();
                }

                @Override
                public String toString() {
                    return invoker.toString();
                }
            };
        }
    }
    return last;
}
 
Example 20
Source File: AbstractProxyFactory.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException {
    Class<?>[] interfaces = null;
    String config = invoker.getUrl().getParameter("interfaces");
    if (config != null && config.length() > 0) {
        String[] types = Constants.COMMA_SPLIT_PATTERN.split(config);
        if (types != null && types.length > 0) {
            interfaces = new Class<?>[types.length + 2];
            interfaces[0] = invoker.getInterface();
            interfaces[1] = EchoService.class;
            for (int i = 0; i < types.length; i++) {
                interfaces[i + 1] = ReflectUtils.forName(types[i]);
            }
        }
    }
    if (interfaces == null) {
        interfaces = new Class<?>[]{invoker.getInterface(), EchoService.class};
    }

    if (!invoker.getInterface().equals(GenericService.class) && generic) {
        int len = interfaces.length;
        Class<?>[] temp = interfaces;
        interfaces = new Class<?>[len + 1];
        System.arraycopy(temp, 0, interfaces, 0, len);
        interfaces[len] = GenericService.class;
    }

    return getProxy(invoker, interfaces);
}