当前位置: 首页>>代码示例>>Java>>正文


Java User类代码示例

本文整理汇总了Java中com.alibaba.dubbo.config.api.User的典型用法代码示例。如果您正苦于以下问题:Java User类的具体用法?Java User怎么用?Java User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


User类属于com.alibaba.dubbo.config.api包,在下文中一共展示了User类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getUsers

import com.alibaba.dubbo.config.api.User; //导入依赖的package包/类
public List<User> getUsers(List<User> users) {
    return users;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:4,代码来源:DemoServiceImpl.java

示例2: testGenericServiceException

import com.alibaba.dubbo.config.api.User; //导入依赖的package包/类
@Test
public void testGenericServiceException() {
    ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
    service.setApplication(new ApplicationConfig("generic-provider"));
    service.setRegistry(new RegistryConfig("N/A"));
    service.setProtocol(new ProtocolConfig("dubbo", 29581));
    service.setInterface(DemoService.class.getName());
    service.setRef(new GenericService() {

        public Object $invoke(String method, String[] parameterTypes, Object[] args)
            throws GenericException {
            if ("sayName".equals(method)) {
                return "Generic " + args[0];
            }
            if ("throwDemoException".equals(method)) {
                throw new GenericException(DemoException.class.getName(), "Generic");
            }
            if ("getUsers".equals(method)) {
                return args[0];
            }
            return null;
        }
    });
    service.export();
    try {
        ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
        reference.setApplication(new ApplicationConfig("generic-consumer"));
        reference.setInterface(DemoService.class);
        reference.setUrl("dubbo://127.0.0.1:29581?generic=true");
        DemoService demoService = reference.get();
        try {
            // say name
            Assert.assertEquals("Generic Haha", demoService.sayName("Haha"));
            // get users
            List<User> users = new ArrayList<User>();
            users.add(new User("Aaa"));
            users = demoService.getUsers(users);
            Assert.assertEquals("Aaa", users.get(0).getName());
            // throw demo exception
            try {
                demoService.throwDemoException();
                Assert.fail();
            } catch (DemoException e) {
                Assert.assertEquals("Generic", e.getMessage());
            }
        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:53,代码来源:GenericServiceTest.java

示例3: testGenericSerializationJava

import com.alibaba.dubbo.config.api.User; //导入依赖的package包/类
@Test
public void testGenericSerializationJava() throws Exception {
    ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
    service.setApplication(new ApplicationConfig("generic-provider"));
    service.setRegistry(new RegistryConfig("N/A"));
    service.setProtocol(new ProtocolConfig("dubbo", 29581));
    service.setInterface(DemoService.class.getName());
    DemoServiceImpl ref = new DemoServiceImpl();
    service.setRef(ref);
    service.export();
    try {
        ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();
        reference.setApplication(new ApplicationConfig("generic-consumer"));
        reference.setInterface(DemoService.class);
        reference.setUrl("dubbo://127.0.0.1:29581?scope=remote");
        reference.setGeneric(Constants.GENERIC_SERIALIZATION_NATIVE_JAVA);
        GenericService genericService = reference.get();
        try {
            String name = "kimi";
            ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
            ExtensionLoader.getExtensionLoader(Serialization.class)
                .getExtension("nativejava").serialize(null, bos).writeObject(name);
            byte[] arg = bos.toByteArray();
            Object obj = genericService.$invoke("sayName", new String[]{String.class.getName()}, new Object[]{arg});
            Assert.assertTrue(obj instanceof byte[]);
            byte[] result = (byte[]) obj;
            Assert.assertEquals(ref.sayName(name), ExtensionLoader.getExtensionLoader(Serialization.class)
                .getExtension("nativejava").deserialize(null, new ByteArrayInputStream(result)).readObject().toString());

            // getUsers
            List<User> users = new ArrayList<User>();
            User user = new User();
            user.setName(name);
            users.add(user);
            bos = new ByteArrayOutputStream(512);
            ExtensionLoader.getExtensionLoader(Serialization.class)
                .getExtension("nativejava").serialize(null, bos).writeObject(users);
            obj = genericService.$invoke("getUsers",
                                         new String[]{List.class.getName()},
                                         new Object[]{bos.toByteArray()});
            Assert.assertTrue(obj instanceof byte[]);
            result = (byte[]) obj;
            Assert.assertEquals(users,
                                ExtensionLoader.getExtensionLoader(Serialization.class)
                                    .getExtension("nativejava")
                                    .deserialize(null, new ByteArrayInputStream(result))
                                    .readObject());

            // echo(int)
            bos = new ByteArrayOutputStream(512);
            ExtensionLoader.getExtensionLoader(Serialization.class).getExtension("nativejava")
                .serialize(null, bos).writeObject(Integer.MAX_VALUE);
            obj = genericService.$invoke("echo", new String[]{int.class.getName()}, new Object[]{bos.toByteArray()});
            Assert.assertTrue(obj instanceof byte[]);
            Assert.assertEquals(Integer.MAX_VALUE,
                                ExtensionLoader.getExtensionLoader(Serialization.class)
                                    .getExtension("nativejava")
                                    .deserialize(null, new ByteArrayInputStream((byte[]) obj))
                                    .readObject());

        } finally {
            reference.destroy();
        }
    } finally {
        service.unexport();
    }
}
 
开发者ID:xingmima,项目名称:dubbos,代码行数:68,代码来源:GenericServiceTest.java


注:本文中的com.alibaba.dubbo.config.api.User类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。