类com.alibaba.dubbo.rpc.service.GenericService源码实例Demo

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

源代码1 项目: dubbox   文件: ServiceConfig.java
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (ref instanceof GenericService) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                .getContextClassLoader());
        }
    } catch (ClassNotFoundException t) {
        throw new IllegalStateException(t.getMessage(), t);
    }
    return interfaceClass;
}
 
源代码2 项目: dubbo-2.6.5   文件: HessianProtocolTest.java
@Test
public void testGenericInvoke() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    String result = (String) client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{"haha"});
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
 
源代码3 项目: dubbo-2.6.5   文件: HessianProtocolTest.java
@Test
public void testGenericInvokeWithNativeJava() throws IOException, ClassNotFoundException {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&generic=nativejava");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    Serialization serialization = new NativeJavaSerialization();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject("haha");
    objectOutput.flushBuffer();

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{byteArrayOutputStream.toByteArray()});
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream((byte[]) result);
    ObjectInput objectInput = serialization.deserialize(url, byteArrayInputStream);
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", objectInput.readObject());
    invoker.destroy();
    exporter.unexport();
}
 
源代码4 项目: dubbo-2.6.5   文件: HessianProtocolTest.java
@Test
public void testGenericInvokeWithRpcContext() {
    RpcContext.getContext().setAttachment("myContext", "123");

    HessianServiceImpl server = new HessianServiceImpl();
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    String result = (String) client.$invoke("context", new String[]{"java.lang.String"}, new Object[]{"haha"});
    Assert.assertEquals("Hello, haha context, 123", result);
    invoker.destroy();
    exporter.unexport();
}
 
源代码5 项目: dubbo-2.6.5   文件: HessianProtocolTest.java
@Test
public void testGenericInvokeWithBean() {
    HessianServiceImpl server = new HessianServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&generic=bean");
    Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    JavaBeanDescriptor javaBeanDescriptor = JavaBeanSerializeUtil.serialize("haha");

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{javaBeanDescriptor});
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) result));
    invoker.destroy();
    exporter.unexport();
}
 
源代码6 项目: dubbo-2.6.5   文件: HttpProtocol.java
@Override
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = getAddr(url);
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, createExporter(impl, type));

    final String genericPath = path + "/" + Constants.GENERIC_KEY;

    skeletonMap.put(genericPath, createExporter(impl, GenericService.class));
    return new Runnable() {
        @Override
        public void run() {
            skeletonMap.remove(path);
            skeletonMap.remove(genericPath);
        }
    };
}
 
源代码7 项目: dubbo-2.6.5   文件: HttpProtocolTest.java
@Test
public void testGenericInvoke() {
    HttpServiceImpl server = new HttpServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker, true);
    String result = (String) client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{"haha"});
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", result);
    invoker.destroy();
    exporter.unexport();
}
 
源代码8 项目: dubbo-2.6.5   文件: HttpProtocolTest.java
@Test
public void testGenericInvokeWithNativeJava() throws IOException, ClassNotFoundException {
    HttpServiceImpl server = new HttpServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0&generic=nativejava");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    Serialization serialization = new NativeJavaSerialization();
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeObject("haha");
    objectOutput.flushBuffer();

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{byteArrayOutputStream.toByteArray()});
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream((byte[]) result);
    ObjectInput objectInput = serialization.deserialize(url, byteArrayInputStream);
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", objectInput.readObject());
    invoker.destroy();
    exporter.unexport();
}
 
源代码9 项目: dubbo-2.6.5   文件: HttpProtocolTest.java
@Test
public void testGenericInvokeWithBean() {
    HttpServiceImpl server = new HttpServiceImpl();
    Assert.assertFalse(server.isCalled());
    ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
    Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
    URL url = URL.valueOf("http://127.0.0.1:5342/" + HttpService.class.getName() + "?version=1.0.0&generic=bean");
    Exporter<HttpService> exporter = protocol.export(proxyFactory.getInvoker(server, HttpService.class, url));
    Invoker<GenericService> invoker = protocol.refer(GenericService.class, url);
    GenericService client = proxyFactory.getProxy(invoker);

    JavaBeanDescriptor javaBeanDescriptor = JavaBeanSerializeUtil.serialize("haha");

    Object result = client.$invoke("sayHello", new String[]{"java.lang.String"}, new Object[]{javaBeanDescriptor});
    Assert.assertTrue(server.isCalled());
    Assert.assertEquals("Hello, haha", JavaBeanSerializeUtil.deserialize((JavaBeanDescriptor) result));
    invoker.destroy();
    exporter.unexport();
}
 
源代码10 项目: dubbo-2.6.5   文件: EnumBak.java
@Ignore
@Test
public void testGenricCustomArg() {

    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);

    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");

    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->" + obj);
    reference.destroy();
}
 
源代码11 项目: dubbo-2.6.5   文件: EnumBak.java
@Test
public void testGenericEnum() throws InterruptedException {
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE
    );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);

    URL consumerurl = serviceurl;

    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);

    GenericService demoProxy = (GenericService) proxy.getProxy(reference);
    Object obj = demoProxy.$invoke("enumlength", new String[]{Type[].class.getName()}, new Object[]{new Type[]{Type.High, Type.High}});
    System.out.println("obj---------->" + obj);

    invoker.destroy();
    reference.destroy();
}
 
源代码12 项目: dubbo-2.6.5   文件: ConfigTest.java
@Test
public void testGenericServiceConfig() throws Exception {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setApplication(new ApplicationConfig("test"));
    service.setRegistry(new RegistryConfig("mock://localhost"));
    service.setInterface(DemoService.class.getName());
    service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
    service.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });
    try {
        service.export();
        Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
        MockRegistry registry = (MockRegistry) collection.iterator().next();
        URL url = registry.getRegistered().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        MockRegistryFactory.cleanCachedRegistry();
        service.unexport();
    }
}
 
源代码13 项目: dubbo-2.6.5   文件: ServiceConfig.java
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (ref instanceof GenericService) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                    .getContextClassLoader());
        }
    } catch (ClassNotFoundException t) {
        throw new IllegalStateException(t.getMessage(), t);
    }
    return interfaceClass;
}
 
源代码14 项目: dubbo-2.6.5   文件: ReferenceConfig.java
public Class<?> getInterfaceClass() {
        if (interfaceClass != null) {
            return interfaceClass;
        }
        if (isGeneric()
                || (getConsumer() != null && getConsumer().isGeneric())) {
            return GenericService.class;
        }
        try {
            if (interfaceName != null && interfaceName.length() > 0) {
//                获取接口的Class类型
                this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                        .getContextClassLoader());
            }
        } catch (ClassNotFoundException t) {
            throw new IllegalStateException(t.getMessage(), t);
        }
        return interfaceClass;
    }
 
源代码15 项目: alchemy   文件: DubboSinkFunction.java
private ReferenceConfig<GenericService> referenceConfig(DubboProperties properties) throws Exception {
    ApplicationConfig application = new ApplicationConfig();
    application.setName(properties.getApplicationName());
    ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
    reference.setApplication(application);
    reference.setRegistry(new RegistryConfig(properties.getRegistryAddr()));
    reference.setInterface(properties.getInterfaceName());
    reference.setVersion(properties.getVersion());
    reference.setGeneric(true);
    reference.setCheck(false);
    reference.setInit(true);
    if(properties.getProperties() != null){
        BeanUtils.copyProperties(reference, properties.getProperties());
    }
    return reference;
}
 
源代码16 项目: soul   文件: AlibabaDubboProxyService.java
/**
 * Generic invoker object.
 *
 * @param body     the body
 * @param metaData the meta data
 * @return the object
 * @throws SoulException the soul exception
 */
public Object genericInvoker(final String body, final MetaData metaData) throws SoulException {
    ReferenceConfig<GenericService> reference = ApplicationConfigCache.getInstance().get(metaData.getServiceName());
    if (Objects.isNull(reference) || StringUtils.isEmpty(reference.getInterface())) {
        ApplicationConfigCache.getInstance().invalidate(metaData.getServiceName());
        reference = ApplicationConfigCache.getInstance().initRef(metaData);
    }
    GenericService genericService = reference.get();
    try {
        if (null == body || "".equals(body) || "{}".equals(body) || "null".equals(body)) {
            return genericService.$invoke(metaData.getMethodName(), new String[]{}, new Object[]{});
        } else {
            Pair<String[], Object[]> pair = dubboParamResolveService.buildParameter(body, metaData.getParameterTypes());
            return genericService.$invoke(metaData.getMethodName(), pair.getLeft(), pair.getRight());
        }
    } catch (GenericException e) {
        log.error("dubbo invoker have exception", e);
        throw new SoulException(e.getMessage());
    }
}
 
源代码17 项目: pampas   文件: DubboServiceFactory.java
public Object genericInvoke(DubboRequest dubboRequest) {

        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
        reference.setApplication(application);
        reference.setRegistry(registry);
        reference.setInterface(dubboRequest.getService());
        reference.setGeneric(true);
        ReferenceConfigCache cache = ReferenceConfigCache.getCache();
        GenericService genericService = cache.get(reference);

        int len = dubboRequest.getParams().size();
        String[] invokeParamTyeps = new String[len];
        Object[] invokeParams = new Object[len];
        for (int i = 0; i < len; i++) {
            invokeParamTyeps[i] = String.valueOf(dubboRequest.getParams().getJSONObject(i).getString("type"));
            invokeParams[i] = dubboRequest.getParams().getJSONObject(i).get("value");
        }
        return genericService.$invoke(dubboRequest.getMethod(), invokeParamTyeps, invokeParams);

    }
 
源代码18 项目: dubbo-samples   文件: Consumer.java
public static void main(String[] args) {

         System.out.println("\n\n\nstart to generic invoke");
         ApplicationConfig applicationConfig = new ApplicationConfig();
         ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
         applicationConfig.setName("UserProviderGer");
         reference.setApplication(applicationConfig);
         RegistryConfig registryConfig = new RegistryConfig();
         registryConfig.setAddress("zookeeper://127.0.0.1:2181");
         reference.setRegistry(registryConfig);
         reference.setGeneric(true);
         reference.setInterface("com.ikurento.user.UserProvider");
         GenericService genericService = reference.get();
         Object[] parameterArgs = new Object[]{"A003"};
         Object result = genericService.$invoke("GetUser", null , parameterArgs);
         System.out.println("res: " + result);

         System.out.println("\n\n\nstart to generic invoke1");
         User user = new User();
         user.setName("Patrick");
         user.setId("id");
         user.setAge(10);
         parameterArgs = new Object[]{user};
         Object result1 = genericService.$invoke("queryUser", new String[]{"com.ikurento.user.User"} , parameterArgs);
         System.out.println("res: " + result1);
    }
 
private <T extends EtMonitor> EtMonitor generateProxy(String appId, Class<T> monitorInterface) {
    return (EtMonitor) Proxy.newProxyInstance(monitorInterface.getClassLoader(), new Class[] { monitorInterface }, new InvocationHandler() {
        
        private GenericService service = generateService(appId, monitorInterface);
        private ConcurrentHashMap<Method, String[]> mapParameterCLassString = new ConcurrentHashMap<>();
        
        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            
            String[] paramTypeStr = mapParameterCLassString.computeIfAbsent(method, m->{
                return Arrays.stream(m.getParameterTypes()).map(clazz->clazz.getName()).toArray(String[]::new);
            });
            
            return service.$invoke(method.getName(), paramTypeStr, args);
        }
    });
}
 
源代码20 项目: dubbo-mock   文件: DubboServiceConfig.java
public ServiceConfig<GenericService> fillDubboService(MockService mockService, com.tony.test.mock.po.RegistryConfig registryConfig,
        com.tony.test.mock.po.ProtocolConfig protocolConfig, MockGenericService tmpMockservice) {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setInterface(mockService.getServiceInterface());
    service.setRef(tmpMockservice); // 指向一个通用服务实现 
    RegistryConfig registry = createRegistry(registryConfig.getRegistryAddress(), registryConfig.getRegistryTimeout());
    service.setRegistry(registry);
    service.setProtocols(Lists.newArrayList(new ProtocolConfig(protocolConfig.getProtocolName(), protocolConfig.getProtocolPort())));
    if (!StringUtils.isBlank(mockService.getGroupName())) {
        service.setGroup(mockService.getGroupName());
    }
    service.setTimeout(mockService.getTimeout());
    service.setRetries(mockService.getRetries());
    service.setApplication(new ApplicationConfig(mockService.getApplicationName()));
    return service;
}
 
源代码21 项目: dubbox   文件: EnumBak.java
public void testGenricCustomArg(){
    
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    
    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->"+obj);
    reference.destroy();
}
 
源代码22 项目: dubbox   文件: ServiceConfig.java
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (ref instanceof GenericService) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                .getContextClassLoader());
        }
    } catch (ClassNotFoundException t) {
        throw new IllegalStateException(t.getMessage(), t);
    }
    return interfaceClass;
}
 
源代码23 项目: dubbox   文件: ReferenceConfig.java
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (isGeneric()
           || (getConsumer() != null && getConsumer().isGeneric())) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                   .getContextClassLoader());
        }
       } catch (ClassNotFoundException t) {
           throw new IllegalStateException(t.getMessage(), t);
       }
    return interfaceClass;
}
 
源代码24 项目: dubbox-hystrix   文件: EnumBak.java
public void testGenricCustomArg(){
    
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    
    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->"+obj);
    reference.destroy();
}
 
源代码25 项目: dubbox-hystrix   文件: EnumBak.java
@Test
public void testGenericEnum() throws InterruptedException{
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
            );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    
    URL consumerurl = serviceurl;
    
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Object obj = demoProxy.$invoke("enumlength", new String[]{Type[].class.getName()}, new Object[]{new Type[]{Type.High,Type.High}});
    System.out.println("obj---------->"+obj);
    
    invoker.destroy();
    reference.destroy();
}
 
源代码26 项目: dubbox-hystrix   文件: ConfigTest.java
@Test
public void testGenericServiceConfig() throws Exception {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setApplication(new ApplicationConfig("test"));
    service.setRegistry(new RegistryConfig("mock://localhost"));
    service.setInterface(DemoService.class.getName());
    service.setGeneric(Constants.GENERIC_SERIALIZATION_BEAN);
    service.setRef(new GenericService(){

        public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
            return null;
        }
    });
    try {
        service.export();
        Collection<Registry> collection = MockRegistryFactory.getCachedRegistry();
        MockRegistry registry = (MockRegistry)collection.iterator().next();
        URL url = registry.getRegistered().get(0);
        Assert.assertEquals(Constants.GENERIC_SERIALIZATION_BEAN, url.getParameter(Constants.GENERIC_KEY));
    } finally {
        MockRegistryFactory.cleanCachedRegistry();
        service.unexport();
    }
}
 
源代码27 项目: dubbox-hystrix   文件: ServiceConfig.java
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (ref instanceof GenericService) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                .getContextClassLoader());
        }
    } catch (ClassNotFoundException t) {
        throw new IllegalStateException(t.getMessage(), t);
    }
    return interfaceClass;
}
 
源代码28 项目: dubbox-hystrix   文件: ReferenceConfig.java
public Class<?> getInterfaceClass() {
    if (interfaceClass != null) {
        return interfaceClass;
    }
    if (isGeneric()
           || (getConsumer() != null && getConsumer().isGeneric())) {
        return GenericService.class;
    }
    try {
        if (interfaceName != null && interfaceName.length() > 0) {
            this.interfaceClass = Class.forName(interfaceName, true, Thread.currentThread()
                   .getContextClassLoader());
        }
       } catch (ClassNotFoundException t) {
           throw new IllegalStateException(t.getMessage(), t);
       }
    return interfaceClass;
}
 
源代码29 项目: dubbo3   文件: EnumBak.java
public void testGenricCustomArg(){
    
    int port = 20880;
    URL consumerurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout=2000000"
    );
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Map<String, Object> arg = new HashMap<String, Object>();
    arg.put("type", "High");
    arg.put("name", "hi");
    
    Object obj = demoProxy.$invoke("get", new String[]{"com.alibaba.dubbo.rpc.CustomArgument"}, new Object[]{arg});
    System.out.println("obj---------->"+obj);
    reference.destroy();
}
 
源代码30 项目: dubbo3   文件: EnumBak.java
@Test
public void testGenericEnum() throws InterruptedException{
    int port = NetUtils.getAvailablePort();
    URL serviceurl = URL.valueOf("dubbo://127.0.0.1:"+port+"/test?timeout="+Integer.MAX_VALUE
            );
    DemoService demo = new DemoServiceImpl();
    Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
    protocol.export(invoker);
    
    URL consumerurl = serviceurl;
    
    Invoker<GenericService> reference = protocol.refer(GenericService.class, consumerurl);
    
    GenericService demoProxy = (GenericService)proxy.getProxy(reference);
    Object obj = demoProxy.$invoke("enumlength", new String[]{Type[].class.getName()}, new Object[]{new Type[]{Type.High,Type.High}});
    System.out.println("obj---------->"+obj);
    
    invoker.destroy();
    reference.destroy();
}
 
 类所在包
 类方法
 同包方法