From 2147d90679bdaf56f515bc8bae08fcc301771022 Mon Sep 17 00:00:00 2001 From: Yuhao Bi Date: Thu, 3 Jan 2019 17:42:11 +0800 Subject: [PATCH 001/217] Release resource after use in ConfigParserTest (#3127) Release resource after use in ConfigParserTest --- .../configurator/parser/ConfigParserTest.java | 187 +++++++++--------- 1 file changed, 96 insertions(+), 91 deletions(-) diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java index 0c365c02ad8..25af5447d3f 100644 --- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java +++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/configurator/parser/ConfigParserTest.java @@ -27,6 +27,7 @@ import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor; +import java.io.IOException; import java.io.InputStream; import java.util.List; @@ -35,129 +36,133 @@ */ public class ConfigParserTest { - private String streamToString(InputStream stream) { - try { - byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - return new String(bytes); - } catch (Exception e) { - e.printStackTrace(); - } - return null; + private String streamToString(InputStream stream) throws IOException { + byte[] bytes = new byte[stream.available()]; + stream.read(bytes); + return new String(bytes); } @Test - public void snakeYamlBasicTest() { - InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml"); + public void snakeYamlBasicTest() throws IOException { + try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) { - Constructor constructor = new Constructor(ConfiguratorConfig.class); - TypeDescription carDescription = new TypeDescription(ConfiguratorConfig.class); - carDescription.addPropertyParameters("items", ConfigItem.class); - constructor.addTypeDescription(carDescription); + Constructor constructor = new Constructor(ConfiguratorConfig.class); + TypeDescription carDescription = new TypeDescription(ConfiguratorConfig.class); + carDescription.addPropertyParameters("items", ConfigItem.class); + constructor.addTypeDescription(carDescription); - Yaml yaml = new Yaml(constructor); - ConfiguratorConfig config = yaml.load(yamlStream); - System.out.println(config); + Yaml yaml = new Yaml(constructor); + ConfiguratorConfig config = yaml.load(yamlStream); + System.out.println(config); + } } @Test public void parseConfiguratorsServiceNoAppTest() throws Exception { - InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml"); - List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); - Assert.assertNotNull(urls); - Assert.assertEquals(2, urls.size()); - URL url = urls.get(0); - Assert.assertEquals(url.getAddress(), "127.0.0.1:20880"); - Assert.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222); + try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoApp.yml")) { + List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); + Assert.assertNotNull(urls); + Assert.assertEquals(2, urls.size()); + URL url = urls.get(0); + Assert.assertEquals(url.getAddress(), "127.0.0.1:20880"); + Assert.assertEquals(url.getParameter(Constants.WEIGHT_KEY, 0), 222); + } } @Test public void parseConfiguratorsServiceGroupVersionTest() throws Exception { - InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml"); - List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); - Assert.assertNotNull(urls); - Assert.assertEquals(1, urls.size()); - URL url = urls.get(0); - Assert.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY)); - Assert.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY)); + try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceGroupVersion.yml")) { + List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); + Assert.assertNotNull(urls); + Assert.assertEquals(1, urls.size()); + URL url = urls.get(0); + Assert.assertEquals("testgroup", url.getParameter(Constants.GROUP_KEY)); + Assert.assertEquals("1.0.0", url.getParameter(Constants.VERSION_KEY)); + } } @Test - public void parseConfiguratorsServiceMultiAppsTest() { - InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml"); - List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); - Assert.assertNotNull(urls); - Assert.assertEquals(4, urls.size()); - URL url = urls.get(0); - Assert.assertEquals("127.0.0.1", url.getAddress()); - Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); - Assert.assertNotNull(url.getParameter(Constants.APPLICATION_KEY)); + public void parseConfiguratorsServiceMultiAppsTest() throws IOException { + try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceMultiApps.yml")) { + List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); + Assert.assertNotNull(urls); + Assert.assertEquals(4, urls.size()); + URL url = urls.get(0); + Assert.assertEquals("127.0.0.1", url.getAddress()); + Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assert.assertNotNull(url.getParameter(Constants.APPLICATION_KEY)); + } } @Test(expected = IllegalStateException.class) - public void parseConfiguratorsServiceNoRuleTest() { - InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml"); - ConfigParser.parseConfigurators(streamToString(yamlStream)); - Assert.fail(); + public void parseConfiguratorsServiceNoRuleTest() throws IOException { + try(InputStream yamlStream = this.getClass().getResourceAsStream("/ServiceNoRule.yml")) { + ConfigParser.parseConfigurators(streamToString(yamlStream)); + Assert.fail(); + } } @Test - public void parseConfiguratorsAppMultiServicesTest() { - InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml"); - String yamlFile = streamToString(yamlStream); - List urls = ConfigParser.parseConfigurators(yamlFile); - Assert.assertNotNull(urls); - Assert.assertEquals(4, urls.size()); - URL url = urls.get(0); - Assert.assertEquals("127.0.0.1", url.getAddress()); - Assert.assertEquals("service1", url.getServiceInterface()); - Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); - Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); - Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + public void parseConfiguratorsAppMultiServicesTest() throws IOException { + try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppMultiServices.yml")) { + String yamlFile = streamToString(yamlStream); + List urls = ConfigParser.parseConfigurators(yamlFile); + Assert.assertNotNull(urls); + Assert.assertEquals(4, urls.size()); + URL url = urls.get(0); + Assert.assertEquals("127.0.0.1", url.getAddress()); + Assert.assertEquals("service1", url.getServiceInterface()); + Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); + Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + } } @Test - public void parseConfiguratorsAppAnyServicesTest() { - InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml"); - List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); - Assert.assertNotNull(urls); - Assert.assertEquals(2, urls.size()); - URL url = urls.get(0); - Assert.assertEquals("127.0.0.1", url.getAddress()); - Assert.assertEquals("*", url.getServiceInterface()); - Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); - Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); - Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + public void parseConfiguratorsAppAnyServicesTest() throws IOException { + try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppAnyServices.yml")) { + List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); + Assert.assertNotNull(urls); + Assert.assertEquals(2, urls.size()); + URL url = urls.get(0); + Assert.assertEquals("127.0.0.1", url.getAddress()); + Assert.assertEquals("*", url.getServiceInterface()); + Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); + Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + } } @Test - public void parseConfiguratorsAppNoServiceTest() { - InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml"); - List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); - Assert.assertNotNull(urls); - Assert.assertEquals(1, urls.size()); - URL url = urls.get(0); - Assert.assertEquals("127.0.0.1", url.getAddress()); - Assert.assertEquals("*", url.getServiceInterface()); - Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); - Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); - Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + public void parseConfiguratorsAppNoServiceTest() throws IOException { + try(InputStream yamlStream = this.getClass().getResourceAsStream("/AppNoService.yml")) { + List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); + Assert.assertNotNull(urls); + Assert.assertEquals(1, urls.size()); + URL url = urls.get(0); + Assert.assertEquals("127.0.0.1", url.getAddress()); + Assert.assertEquals("*", url.getServiceInterface()); + Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); + Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + } } @Test - public void parseConsumerSpecificProvidersTest() { - InputStream yamlStream = this.getClass().getResourceAsStream("/ConsumerSpecificProviders.yml"); - List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); - Assert.assertNotNull(urls); - Assert.assertEquals(1, urls.size()); - URL url = urls.get(0); - Assert.assertEquals("127.0.0.1", url.getAddress()); - Assert.assertEquals("*", url.getServiceInterface()); - Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); - Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); - Assert.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY)); - Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + public void parseConsumerSpecificProvidersTest() throws IOException { + try(InputStream yamlStream = this.getClass().getResourceAsStream("/ConsumerSpecificProviders.yml")) { + List urls = ConfigParser.parseConfigurators(streamToString(yamlStream)); + Assert.assertNotNull(urls); + Assert.assertEquals(1, urls.size()); + URL url = urls.get(0); + Assert.assertEquals("127.0.0.1", url.getAddress()); + Assert.assertEquals("*", url.getServiceInterface()); + Assert.assertEquals(6666, url.getParameter(Constants.TIMEOUT_KEY, 0)); + Assert.assertEquals("random", url.getParameter(Constants.LOADBALANCE_KEY)); + Assert.assertEquals("127.0.0.1:20880", url.getParameter(Constants.OVERRIDE_PROVIDERS_KEY)); + Assert.assertEquals(url.getParameter(Constants.APPLICATION_KEY), "demo-consumer"); + } } } From 4b2b673ba346ae34a5c556f043321c4b987efedd Mon Sep 17 00:00:00 2001 From: Leishunyu <791825162@qq.com> Date: Fri, 4 Jan 2019 15:23:04 +0800 Subject: [PATCH 002/217] add javadoc for registry and some code (#3140) add javadoc for registry and optimize code --- .../support/AbstractRegistryFactory.java | 1 + .../dubbo/registry/dubbo/DubboRegistry.java | 15 +++--- .../registry/dubbo/DubboRegistryFactory.java | 6 +-- .../dubbo/registry/redis/RedisRegistry.java | 14 ++--- .../registry/zookeeper/ZookeeperRegistry.java | 51 ++++++++----------- .../zookeeper/ZookeeperRegistryFactory.java | 4 ++ 6 files changed, 41 insertions(+), 50 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java index 64647f4ba60..0f5dffc0f4c 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java @@ -93,6 +93,7 @@ public Registry getRegistry(URL url) { if (registry != null) { return registry; } + //create registry by spi/ioc registry = createRegistry(url); if (registry == null) { throw new IllegalStateException("Can not create registry " + url); diff --git a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java index 2c6b8c1f1ec..72604d64474 100644 --- a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java +++ b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistry.java @@ -71,15 +71,12 @@ public DubboRegistry(Invoker registryInvoker, RegistryService r this.registryService = registryService; // Start reconnection timer this.reconnectPeriod = registryInvoker.getUrl().getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, RECONNECT_PERIOD_DEFAULT); - reconnectFuture = reconnectTimer.scheduleWithFixedDelay(new Runnable() { - @Override - public void run() { - // Check and connect to the registry - try { - connect(); - } catch (Throwable t) { // Defensive fault tolerance - logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t); - } + reconnectFuture = reconnectTimer.scheduleWithFixedDelay(() -> { + // Check and connect to the registry + try { + connect(); + } catch (Throwable t) { // Defensive fault tolerance + logger.error("Unexpected error occur at reconnect, cause: " + t.getMessage(), t); } }, reconnectPeriod, reconnectPeriod, TimeUnit.MILLISECONDS); } diff --git a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java index ea9fc802ce1..27d90ed57c9 100644 --- a/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-default/src/main/java/org/apache/dubbo/registry/dubbo/DubboRegistryFactory.java @@ -56,7 +56,7 @@ private static URL getRegistryURL(URL url) { .addParameterIfAbsent(Constants.TIMEOUT_KEY, "10000") .addParameterIfAbsent(Constants.CALLBACK_INSTANCES_LIMIT_KEY, "10000") .addParameterIfAbsent(Constants.CONNECT_TIMEOUT_KEY, "10000") - .addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ",")) + .addParameter(Constants.METHODS_KEY, StringUtils.join(new HashSet<>(Arrays.asList(Wrapper.getWrapper(RegistryService.class).getDeclaredMethodNames())), ",")) //.addParameter(Constants.STUB_KEY, RegistryServiceStub.class.getName()) //.addParameter(Constants.STUB_EVENT_KEY, Boolean.TRUE.toString()) //for event dispatch //.addParameter(Constants.ON_DISCONNECT_KEY, "disconnect") @@ -79,7 +79,7 @@ public void setCluster(Cluster cluster) { @Override public Registry createRegistry(URL url) { url = getRegistryURL(url); - List urls = new ArrayList(); + List urls = new ArrayList<>(); urls.add(url.removeParameter(Constants.BACKUP_KEY)); String backup = url.getParameter(Constants.BACKUP_KEY); if (backup != null && backup.length() > 0) { @@ -88,7 +88,7 @@ public Registry createRegistry(URL url) { urls.add(url.setAddress(address)); } } - RegistryDirectory directory = new RegistryDirectory(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString())); + RegistryDirectory directory = new RegistryDirectory<>(RegistryService.class, url.addParameter(Constants.INTERFACE_KEY, RegistryService.class.getName()).addParameterAndEncoded(Constants.REFER_KEY, url.toParameterString())); Invoker registryInvoker = cluster.join(directory); RegistryService registryService = proxyFactory.getProxy(registryInvoker); DubboRegistry registry = new DubboRegistry(registryInvoker, registryService); diff --git a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java index d37276345df..c0c7c22ff22 100644 --- a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java +++ b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisRegistry.java @@ -69,7 +69,7 @@ public class RedisRegistry extends FailbackRegistry { private final String root; - private final Map jedisPools = new ConcurrentHashMap(); + private final Map jedisPools = new ConcurrentHashMap<>(); private final ConcurrentMap notifiers = new ConcurrentHashMap(); @@ -360,12 +360,12 @@ public void doSubscribe(final URL url, final NotifyListener listener) { admin = true; Set keys = jedis.keys(service); if (keys != null && !keys.isEmpty()) { - Map> serviceKeys = new HashMap>(); + Map> serviceKeys = new HashMap<>(); for (String key : keys) { String serviceKey = toServicePath(key); Set sk = serviceKeys.get(serviceKey); if (sk == null) { - sk = new HashSet(); + sk = new HashSet<>(); serviceKeys.put(serviceKey, sk); } sk.add(key); @@ -400,8 +400,8 @@ public void doUnsubscribe(URL url, NotifyListener listener) { } private void doNotify(Jedis jedis, String key) { - for (Map.Entry> entry : new HashMap>(getSubscribed()).entrySet()) { - doNotify(jedis, Arrays.asList(key), entry.getKey(), new HashSet(entry.getValue())); + for (Map.Entry> entry : new HashMap<>(getSubscribed()).entrySet()) { + doNotify(jedis, Arrays.asList(key), entry.getKey(), new HashSet<>(entry.getValue())); } } @@ -411,7 +411,7 @@ private void doNotify(Jedis jedis, Collection keys, URL url, Collection< return; } long now = System.currentTimeMillis(); - List result = new ArrayList(); + List result = new ArrayList<>(); List categories = Arrays.asList(url.getParameter(Constants.CATEGORY_KEY, new String[0])); String consumerService = url.getServiceInterface(); for (String key : keys) { @@ -425,7 +425,7 @@ private void doNotify(Jedis jedis, Collection keys, URL url, Collection< if (!categories.contains(Constants.ANY_VALUE) && !categories.contains(category)) { continue; } - List urls = new ArrayList(); + List urls = new ArrayList<>(); Map values = jedis.hgetAll(key); if (values != null && values.size() > 0) { for (Map.Entry entry : values.entrySet()) { diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java index d7a8ee097ac..37f1f21a16f 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java @@ -50,7 +50,7 @@ public class ZookeeperRegistry extends FailbackRegistry { private final String root; - private final Set anyServices = new ConcurrentHashSet(); + private final Set anyServices = new ConcurrentHashSet<>(); private final ConcurrentMap> zkListeners = new ConcurrentHashMap>(); @@ -67,15 +67,12 @@ public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) { } this.root = group; zkClient = zookeeperTransporter.connect(url); - zkClient.addStateListener(new StateListener() { - @Override - public void stateChanged(int state) { - if (state == RECONNECTED) { - try { - recover(); - } catch (Exception e) { - logger.error(e.getMessage(), e); - } + zkClient.addStateListener(state -> { + if (state == StateListener.RECONNECTED) { + try { + recover(); + } catch (Exception e) { + logger.error(e.getMessage(), e); } } }); @@ -133,21 +130,18 @@ public void doSubscribe(final URL url, final NotifyListener listener) { String root = toRootPath(); ConcurrentMap listeners = zkListeners.get(url); if (listeners == null) { - zkListeners.putIfAbsent(url, new ConcurrentHashMap()); + zkListeners.putIfAbsent(url, new ConcurrentHashMap<>()); listeners = zkListeners.get(url); } ChildListener zkListener = listeners.get(listener); if (zkListener == null) { - listeners.putIfAbsent(listener, new ChildListener() { - @Override - public void childChanged(String parentPath, List currentChilds) { - for (String child : currentChilds) { - child = URL.decode(child); - if (!anyServices.contains(child)) { - anyServices.add(child); - subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child, - Constants.CHECK_KEY, String.valueOf(false)), listener); - } + listeners.putIfAbsent(listener, (parentPath, currentChilds) -> { + for (String child : currentChilds) { + child = URL.decode(child); + if (!anyServices.contains(child)) { + anyServices.add(child); + subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child, + Constants.CHECK_KEY, String.valueOf(false)), listener); } } }); @@ -164,21 +158,16 @@ public void childChanged(String parentPath, List currentChilds) { } } } else { - List urls = new ArrayList(); + List urls = new ArrayList<>(); for (String path : toCategoriesPath(url)) { ConcurrentMap listeners = zkListeners.get(url); if (listeners == null) { - zkListeners.putIfAbsent(url, new ConcurrentHashMap()); + zkListeners.putIfAbsent(url, new ConcurrentHashMap<>()); listeners = zkListeners.get(url); } ChildListener zkListener = listeners.get(listener); if (zkListener == null) { - listeners.putIfAbsent(listener, new ChildListener() { - @Override - public void childChanged(String parentPath, List currentChilds) { - ZookeeperRegistry.this.notify(url, listener, toUrlsWithEmpty(url, parentPath, currentChilds)); - } - }); + listeners.putIfAbsent(listener, (parentPath, currentChilds) -> ZookeeperRegistry.this.notify(url, listener, toUrlsWithEmpty(url, parentPath, currentChilds))); zkListener = listeners.get(listener); } zkClient.create(path, false); @@ -218,7 +207,7 @@ public List lookup(URL url) { throw new IllegalArgumentException("lookup url == null"); } try { - List providers = new ArrayList(); + List providers = new ArrayList<>(); for (String path : toCategoriesPath(url)) { List children = zkClient.getChildren(path); if (children != null) { @@ -274,7 +263,7 @@ private String toUrlPath(URL url) { } private List toUrlsWithoutEmpty(URL consumer, List providers) { - List urls = new ArrayList(); + List urls = new ArrayList<>(); if (providers != null && !providers.isEmpty()) { for (String provider : providers) { provider = URL.decode(provider); diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java index 6fd33431b56..d702d0184cb 100644 --- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistryFactory.java @@ -29,6 +29,10 @@ public class ZookeeperRegistryFactory extends AbstractRegistryFactory { private ZookeeperTransporter zookeeperTransporter; + /** + * Invisible injection of zookeeper client via IOC/SPI + * @param zookeeperTransporter + */ public void setZookeeperTransporter(ZookeeperTransporter zookeeperTransporter) { this.zookeeperTransporter = zookeeperTransporter; } From ba27bc5352bb0c069b446f1f60bd37c2d816820f Mon Sep 17 00:00:00 2001 From: kexianjun Date: Fri, 4 Jan 2019 23:07:56 +0800 Subject: [PATCH 003/217] Correct spelling error (#3146) --- .../apache/dubbo/registry/integration/RegistryProtocol.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java index 049c94f5cbe..af908127e77 100644 --- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java +++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/RegistryProtocol.java @@ -263,8 +263,8 @@ private ExporterChangeableWrapper doChangeLocalExport(final Invoker origi if (exporter == null) { logger.warn(new IllegalStateException("error state, exporter should not be null")); } else { - final Invoker invokerDelegete = new InvokerDelegate(originInvoker, newInvokerUrl); - exporter.setExporter(protocol.export(invokerDelegete)); + final Invoker invokerDelegate = new InvokerDelegate(originInvoker, newInvokerUrl); + exporter.setExporter(protocol.export(invokerDelegate)); } return exporter; } From f36bed947210a8d675e73374b6ff32a1ac46798d Mon Sep 17 00:00:00 2001 From: huazhongming Date: Fri, 4 Jan 2019 23:32:18 +0800 Subject: [PATCH 004/217] Code optimization (#3118) * code optimization * useless import * optimization --- .../cluster/directory/StaticDirectory.java | 4 +- .../rpc/cluster/router/AbstractRouter.java | 1 + .../apache/dubbo/common/logger/Logger.java | 40 +++++++++---------- .../apache/dubbo/common/utils/NetUtils.java | 31 +++++++------- .../apache/dubbo/config/AbstractConfig.java | 34 ++++++++++++---- .../apache/dubbo/config/ReferenceConfig.java | 4 +- .../apache/dubbo/config/ServiceConfig.java | 6 +-- .../definition/model/MethodDefinition.java | 8 +++- .../definition/model/ServiceDefinition.java | 8 +++- .../definition/model/TypeDefinition.java | 8 +++- .../support/AbstractMetadataReport.java | 3 ++ .../remoting/transport/AbstractServer.java | 2 +- .../remoting/transport/mina/MinaServer.java | 2 +- .../support/AbstractZookeeperClient.java | 2 + .../rpc/protocol/injvm/InjvmInvoker.java | 4 +- 15 files changed, 97 insertions(+), 60 deletions(-) diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java index e868bd792c1..160543867cd 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/directory/StaticDirectory.java @@ -29,7 +29,6 @@ /** * StaticDirectory - * */ public class StaticDirectory extends AbstractDirectory { private static final Logger logger = LoggerFactory.getLogger(StaticDirectory.class); @@ -50,8 +49,9 @@ public StaticDirectory(URL url, List> invokers) { public StaticDirectory(URL url, List> invokers, RouterChain routerChain) { super(url == null && invokers != null && !invokers.isEmpty() ? invokers.get(0).getUrl() : url, routerChain); - if (invokers == null || invokers.isEmpty()) + if (invokers == null || invokers.isEmpty()) { throw new IllegalArgumentException("invokers == null"); + } this.invokers = invokers; } diff --git a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java index da4bd7c37eb..411c213eb29 100644 --- a/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java +++ b/dubbo-cluster/src/main/java/org/apache/dubbo/rpc/cluster/router/AbstractRouter.java @@ -70,6 +70,7 @@ public int compareTo(Router o) { return (this.getPriority() >= o.getPriority()) ? 1 : -1; } + @Override public int getPriority() { return priority; } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java index 3b78d04542c..c505326d0c3 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/logger/Logger.java @@ -28,14 +28,14 @@ public interface Logger { * * @param msg log this message */ - public void trace(String msg); + void trace(String msg); /** * Logs an error with trace log level. * * @param e log this cause */ - public void trace(Throwable e); + void trace(Throwable e); /** * Logs an error with trace log level. @@ -43,21 +43,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void trace(String msg, Throwable e); + void trace(String msg, Throwable e); /** * Logs a message with debug log level. * * @param msg log this message */ - public void debug(String msg); + void debug(String msg); /** * Logs an error with debug log level. * * @param e log this cause */ - public void debug(Throwable e); + void debug(Throwable e); /** * Logs an error with debug log level. @@ -65,21 +65,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void debug(String msg, Throwable e); + void debug(String msg, Throwable e); /** * Logs a message with info log level. * * @param msg log this message */ - public void info(String msg); + void info(String msg); /** * Logs an error with info log level. * * @param e log this cause */ - public void info(Throwable e); + void info(Throwable e); /** * Logs an error with info log level. @@ -87,21 +87,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void info(String msg, Throwable e); + void info(String msg, Throwable e); /** * Logs a message with warn log level. * * @param msg log this message */ - public void warn(String msg); + void warn(String msg); /** * Logs a message with warn log level. * * @param e log this message */ - public void warn(Throwable e); + void warn(Throwable e); /** * Logs a message with warn log level. @@ -109,21 +109,21 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void warn(String msg, Throwable e); + void warn(String msg, Throwable e); /** * Logs a message with error log level. * * @param msg log this message */ - public void error(String msg); + void error(String msg); /** * Logs an error with error log level. * * @param e log this cause */ - public void error(Throwable e); + void error(Throwable e); /** * Logs an error with error log level. @@ -131,41 +131,41 @@ public interface Logger { * @param msg log this message * @param e log this cause */ - public void error(String msg, Throwable e); + void error(String msg, Throwable e); /** * Is trace logging currently enabled? * * @return true if trace is enabled */ - public boolean isTraceEnabled(); + boolean isTraceEnabled(); /** * Is debug logging currently enabled? * * @return true if debug is enabled */ - public boolean isDebugEnabled(); + boolean isDebugEnabled(); /** * Is info logging currently enabled? * * @return true if info is enabled */ - public boolean isInfoEnabled(); + boolean isInfoEnabled(); /** * Is warn logging currently enabled? * * @return true if warn is enabled */ - public boolean isWarnEnabled(); + boolean isWarnEnabled(); /** * Is error logging currently enabled? * * @return true if error is enabled */ - public boolean isErrorEnabled(); + boolean isErrorEnabled(); } \ No newline at end of file diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java index 29d79a30f0f..fafe1518f91 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.common.utils; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.logger.Logger; import org.apache.dubbo.common.logger.LoggerFactory; @@ -37,8 +38,6 @@ */ public class NetUtils { - public static final String LOCALHOST = "127.0.0.1"; - public static final String ANYHOST = "0.0.0.0"; private static final Logger logger = LoggerFactory.getLogger(NetUtils.class); private static final int RND_PORT_START = 30000; @@ -109,18 +108,18 @@ public static boolean isValidAddress(String address) { public static boolean isLocalHost(String host) { return host != null && (LOCAL_IP_PATTERN.matcher(host).matches() - || host.equalsIgnoreCase("localhost")); + || host.equalsIgnoreCase(Constants.LOCALHOST_KEY)); } public static boolean isAnyHost(String host) { - return "0.0.0.0".equals(host); + return Constants.ANYHOST_VALUE.equals(host); } public static boolean isInvalidLocalHost(String host) { return host == null || host.length() == 0 - || host.equalsIgnoreCase("localhost") - || host.equals("0.0.0.0") + || host.equalsIgnoreCase(Constants.LOCALHOST_KEY) + || host.equals(Constants.ANYHOST_VALUE) || (LOCAL_IP_PATTERN.matcher(host).matches()); } @@ -139,13 +138,14 @@ static boolean isValidAddress(InetAddress address) { } String name = address.getHostAddress(); return (name != null - && !ANYHOST.equals(name) - && !LOCALHOST.equals(name) - && IP_PATTERN.matcher(name).matches()); + && IP_PATTERN.matcher(name).matches() + && !Constants.ANYHOST_VALUE.equals(name) + && !Constants.LOCALHOST_VALUE.equals(name)); } /** * Check if an ipv6 address is reachable. + * * @param address the given address * @return true if it is reachable */ @@ -166,12 +166,13 @@ static boolean isValidV6Address(Inet6Address address) { * normalize the ipv6 Address, convert scope name to scope id. * e.g. * convert - * fe80:0:0:0:894:aeec:f37d:23e1%en0 + * fe80:0:0:0:894:aeec:f37d:23e1%en0 * to - * fe80:0:0:0:894:aeec:f37d:23e1%5 - * + * fe80:0:0:0:894:aeec:f37d:23e1%5 + *

* The %5 after ipv6 address is called scope id. * see java doc of {@link Inet6Address} for more details. + * * @param address the input address * @return the normalized address, with scope id converted to int */ @@ -191,7 +192,7 @@ static InetAddress normalizeV6Address(Inet6Address address) { public static String getLocalHost() { InetAddress address = getLocalAddress(); - return address == null ? LOCALHOST : address.getHostAddress(); + return address == null ? Constants.LOCALHOST_VALUE : address.getHostAddress(); } public static String filterLocalHost(String host) { @@ -236,7 +237,7 @@ private static InetAddress getLocalAddress0() { localAddress = InetAddress.getLocalHost(); if (localAddress instanceof Inet6Address) { Inet6Address address = (Inet6Address) localAddress; - if (isValidV6Address(address)){ + if (isValidV6Address(address)) { return normalizeV6Address(address); } } else if (isValidAddress(localAddress)) { @@ -259,7 +260,7 @@ private static InetAddress getLocalAddress0() { InetAddress address = addresses.nextElement(); if (address instanceof Inet6Address) { Inet6Address v6Address = (Inet6Address) address; - if (isValidV6Address(v6Address)){ + if (isValidV6Address(v6Address)) { return normalizeV6Address(v6Address); } } else if (isValidAddress(address)) { diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java index 7f2612aaaa2..5921abc3d35 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractConfig.java @@ -304,9 +304,9 @@ protected static void checkExtension(Class type, String property, String valu * Check whether there is a Extension who's name (property) is value (special treatment is * required) * - * @param type The Extension type + * @param type The Extension type * @param property The extension key - * @param value The Extension name + * @param value The Extension name */ protected static void checkMultiExtension(Class type, String property, String value) { checkMultiName(property, value); @@ -485,12 +485,7 @@ public Map getMetaData() { for (Method method : methods) { try { String name = method.getName(); - if ((name.startsWith("get") || name.startsWith("is")) - && !name.equals("get") - && !"getClass".equals(name) - && Modifier.isPublic(method.getModifiers()) - && method.getParameterTypes().length == 0 - && ClassHelper.isPrimitive(method.getReturnType())) { + if (isMetaMethod(method)) { String prop = calculateAttributeFromGetter(name); String key; Parameter parameter = method.getAnnotation(Parameter.class); @@ -620,4 +615,27 @@ public boolean isValid() { return true; } + private boolean isMetaMethod(Method method) { + String name = method.getName(); + if (!(name.startsWith("get") || name.startsWith("is"))) { + return false; + } + if ("get".equals(name)) { + return false; + } + if ("getClass".equals(name)) { + return false; + } + if (!Modifier.isPublic(method.getModifiers())) { + return false; + } + if (method.getParameterTypes().length != 0) { + return false; + } + if (!ClassHelper.isPrimitive(method.getReturnType())) { + return false; + } + return true; + } + } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index ea75c3d50f3..3110d762ecc 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -72,7 +72,7 @@ public class ReferenceConfig extends AbstractReferenceConfig { * *

  • when the url is dubbo://224.5.6.7:1234/org.apache.dubbo.config.api.DemoService?application=dubbo-sample, then * the protocol is DubboProtocol
  • - * + *

    * Actually,when the {@link ExtensionLoader} init the {@link Protocol} instants,it will automatically wraps two * layers, and eventually will get a ProtocolFilterWrapper or ProtocolListenerWrapper */ @@ -327,7 +327,7 @@ private T createProxy(Map map) { } if (isJvmRefer) { - URL url = new URL(Constants.LOCAL_PROTOCOL, NetUtils.LOCALHOST, 0, interfaceClass.getName()).addParameters(map); + URL url = new URL(Constants.LOCAL_PROTOCOL, Constants.LOCALHOST_VALUE, 0, interfaceClass.getName()).addParameters(map); invoker = refprotocol.refer(interfaceClass, url); if (logger.isInfoEnabled()) { logger.info("Using injvm service " + interfaceClass.getName()); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index 0309ff039b2..e1e3d0c969f 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -57,7 +57,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; -import static org.apache.dubbo.common.utils.NetUtils.LOCALHOST; +import static org.apache.dubbo.common.Constants.LOCALHOST_VALUE; import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort; import static org.apache.dubbo.common.utils.NetUtils.getLocalHost; import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost; @@ -82,7 +82,7 @@ public class ServiceConfig extends AbstractServiceConfig { * *

  • when the url is dubbo://224.5.6.7:1234/org.apache.dubbo.config.api.DemoService?application=dubbo-sample, then * the protocol is DubboProtocol
  • - * + *

    * Actually,when the {@link ExtensionLoader} init the {@link Protocol} instants,it will automatically wraps two * layers, and eventually will get a ProtocolFilterWrapper or ProtocolListenerWrapper */ @@ -583,7 +583,7 @@ private void exportLocal(URL url) { if (!Constants.LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) { URL local = URL.valueOf(url.toFullString()) .setProtocol(Constants.LOCAL_PROTOCOL) - .setHost(LOCALHOST) + .setHost(LOCALHOST_VALUE) .setPort(0); Exporter exporter = protocol.export( proxyFactory.getInvoker(ref, (Class) interfaceClass, local)); diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java index c1e154840d6..3746ab5b9bd 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java @@ -74,8 +74,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MethodDefinition)) return false; + if (this == o) { + return true; + } + if (!(o instanceof MethodDefinition)) { + return false; + } MethodDefinition that = (MethodDefinition) o; return Objects.equals(getName(), that.getName()) && Arrays.equals(getParameterTypes(), that.getParameterTypes()) && diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java index f94e4d5704c..78d3bcb6f66 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/ServiceDefinition.java @@ -80,8 +80,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ServiceDefinition)) return false; + if (this == o) { + return true; + } + if (!(o instanceof ServiceDefinition)) { + return false; + } ServiceDefinition that = (ServiceDefinition) o; return Objects.equals(getCanonicalName(), that.getCanonicalName()) && Objects.equals(getCodeSource(), that.getCodeSource()) && diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java index f4cc145f8d6..7ca5bd894aa 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/model/TypeDefinition.java @@ -106,8 +106,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof TypeDefinition)) return false; + if (this == o) { + return true; + } + if (!(o instanceof TypeDefinition)) { + return false; + } TypeDefinition that = (TypeDefinition) o; return Objects.equals(getId(), that.getId()) && Objects.equals(getType(), that.getType()) && diff --git a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java index 9aab901f5d1..09e6e0bb318 100644 --- a/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java +++ b/dubbo-metadata-report/dubbo-metadata-report-api/src/main/java/org/apache/dubbo/metadata/support/AbstractMetadataReport.java @@ -52,6 +52,7 @@ import java.util.concurrent.atomic.AtomicLong; /** + * */ public abstract class AbstractMetadataReport implements MetadataReport { @@ -229,6 +230,7 @@ public void run() { } } + @Override public void storeProviderMetadata(MetadataIdentifier providerMetadataIdentifier, FullServiceDefinition serviceDefinition) { if (syncReport) { storeProviderMetadataTask(providerMetadataIdentifier, serviceDefinition); @@ -261,6 +263,7 @@ private void storeProviderMetadataTask(MetadataIdentifier providerMetadataIdenti } } + @Override public void storeConsumerMetadata(MetadataIdentifier consumerMetadataIdentifier, Map serviceParameterMap) { if (syncReport) { storeConsumerMetadataTask(consumerMetadataIdentifier, serviceParameterMap); diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java index c95183835b9..2020fee79fb 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractServer.java @@ -54,7 +54,7 @@ public AbstractServer(URL url, ChannelHandler handler) throws RemotingException String bindIp = getUrl().getParameter(Constants.BIND_IP_KEY, getUrl().getHost()); int bindPort = getUrl().getParameter(Constants.BIND_PORT_KEY, getUrl().getPort()); if (url.getParameter(Constants.ANYHOST_KEY, false) || NetUtils.isInvalidLocalHost(bindIp)) { - bindIp = NetUtils.ANYHOST; + bindIp = Constants.ANYHOST_VALUE; } bindAddress = new InetSocketAddress(bindIp, bindPort); this.accepts = url.getParameter(Constants.ACCEPTS_KEY, Constants.DEFAULT_ACCEPTS); diff --git a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java index 80e336d7e82..540213b4443 100644 --- a/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java +++ b/dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaServer.java @@ -60,7 +60,7 @@ protected void doOpen() throws Throwable { Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker", true))); // config - SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig(); + SocketAcceptorConfig cfg = acceptor.getDefaultConfig(); cfg.setThreadModel(ThreadModel.MANUAL); // set codec. acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this))); diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java index 852c974111e..e90f7fb9c71 100644 --- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java +++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/support/AbstractZookeeperClient.java @@ -127,6 +127,7 @@ public void close() { } } + @Override public void create(String path, String content, boolean ephemeral) { if (checkExists(path)) { delete(path); @@ -142,6 +143,7 @@ public void create(String path, String content, boolean ephemeral) { } } + @Override public String getContent(String path) { if (!checkExists(path)) { return null; diff --git a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java index 591022ecde4..37d23d5bdf7 100644 --- a/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java +++ b/dubbo-rpc/dubbo-rpc-injvm/src/main/java/org/apache/dubbo/rpc/protocol/injvm/InjvmInvoker.java @@ -16,8 +16,8 @@ */ package org.apache.dubbo.rpc.protocol.injvm; +import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.rpc.Exporter; import org.apache.dubbo.rpc.Invocation; import org.apache.dubbo.rpc.Result; @@ -58,7 +58,7 @@ public Result doInvoke(Invocation invocation) throws Throwable { if (exporter == null) { throw new RpcException("Service [" + key + "] not found."); } - RpcContext.getContext().setRemoteAddress(NetUtils.LOCALHOST, 0); + RpcContext.getContext().setRemoteAddress(Constants.LOCALHOST_VALUE, 0); return exporter.getInvoker().invoke(invocation); } } From ddb518de3ab3b54ec4b6a8a52db6cde1b3f58262 Mon Sep 17 00:00:00 2001 From: Wang jie <260072856@qq.com> Date: Fri, 4 Jan 2019 23:42:01 +0800 Subject: [PATCH 005/217] Code rule (#3016) --- .../dubbo/common/compiler/support/ClassUtils.java | 3 ++- .../main/java/org/apache/dubbo/common/json/JSON.java | 2 ++ .../org/apache/dubbo/common/json/JSONWriter.java | 1 + .../java/org/apache/dubbo/common/json/Yylex.java | 1 + .../dubbo/rpc/protocol/thrift/ThriftCodec.java | 12 +++++++----- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java index e4db9a8cb5c..1c552086016 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/compiler/support/ClassUtils.java @@ -79,7 +79,7 @@ public static Class forName(String className) { } public static Class _forName(String className) throws ClassNotFoundException { - switch(className){ + switch (className) { case "boolean": return boolean.class; case "byte": @@ -112,6 +112,7 @@ public static Class _forName(String className) throws ClassNotFoundException return float[].class; case "double[]": return double[].class; + default: } try { return arrayForName(className); diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java index 1d3aa8891d2..0903cfbc869 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java @@ -579,6 +579,7 @@ private static Object parse(Reader reader, JSONVisitor handler, int expect) thro handler.objectItemValue(value, false); break; } + default: } } break; @@ -629,6 +630,7 @@ private static Object parse(Reader reader, JSONVisitor handler, int expect) thro handler.objectItemValue(value, false); break; } + default: } } break; diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONWriter.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONWriter.java index 094832134c0..6c6bf09c0fe 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONWriter.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONWriter.java @@ -275,6 +275,7 @@ private void beforeValue() throws IOException { case OBJECT_VALUE: mState.type = OBJECT; return; + default: } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java b/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java index 8abb42d1ab2..822175e6031 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java @@ -837,6 +837,7 @@ public JSONToken yylex() throws java.io.IOException, ParseException { return null; } else { zzScanError(ZZ_NO_MATCH); + break; } } } diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java index 02c0699af2c..d171ce12435 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java @@ -66,11 +66,12 @@ *

    * header fields in version 1 *

      - *
    1. string - service name
    2. - *
    3. long - dubbo request id
    4. + *
    5. string - service name
    6. + *
    7. long - dubbo request id
    8. *
    *

    */ + /** * @since 2.7.0, use https://github.com/dubbo/dubbo-rpc-native-thrift instead */ @@ -108,7 +109,7 @@ public void encode(Channel channel, ChannelBuffer buffer, Object message) } else if (message instanceof Response) { encodeResponse(channel, buffer, (Response) message); } else { - throw new UnsupportedOperationException("Thrift codec only support encode " + throw new UnsupportedOperationException("Thrift codec only support encode " + Request.class.getName() + " and " + Response.class.getName()); } @@ -299,7 +300,7 @@ private Object decode(TProtocol protocol) .getExtension(ThriftClassNameGenerator.NAME).generateResultClassName(serviceName, message.name); if (StringUtils.isEmpty(resultClassName)) { - throw new IllegalArgumentException("Could not infer service result class name from service name " + throw new IllegalArgumentException("Could not infer service result class name from service name " + serviceName + ", the service name you specified may not generated by thrift idl compiler"); } @@ -401,7 +402,7 @@ private void encodeRequest(Channel channel, ChannelBuffer buffer, Request reques String serviceName = inv.getAttachment(Constants.INTERFACE_KEY); if (StringUtils.isEmpty(serviceName)) { - throw new IllegalArgumentException("Could not find service name in attachment with key " + throw new IllegalArgumentException("Could not find service name in attachment with key " + Constants.INTERFACE_KEY); } @@ -667,6 +668,7 @@ private void encodeResponse(Channel channel, ChannelBuffer buffer, Response resp case TMessageType.REPLY: resultObj.write(protocol); break; + default: } protocol.writeMessageEnd(); protocol.getTransport().flush(); From e095bd9bab6c9527ee4da7031f49575651af1696 Mon Sep 17 00:00:00 2001 From: huazhongming Date: Tue, 8 Jan 2019 10:20:10 +0800 Subject: [PATCH 006/217] code optimization (#3167) code optimization --- .../src/main/java/org/apache/dubbo/rpc/AbstractResult.java | 4 +++- .../src/main/java/org/apache/dubbo/rpc/RpcContext.java | 3 ++- .../src/main/java/org/apache/dubbo/rpc/RpcException.java | 5 ++++- .../src/main/java/org/apache/dubbo/rpc/RpcInvocation.java | 3 ++- .../java/org/apache/dubbo/rpc/service/GenericService.java | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java index 760a9c1a111..b898934c63c 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/AbstractResult.java @@ -16,6 +16,8 @@ */ package org.apache.dubbo.rpc; +import org.apache.dubbo.common.utils.StringUtils; + import java.util.HashMap; import java.util.Map; @@ -58,7 +60,7 @@ public String getAttachment(String key) { @Override public String getAttachment(String key, String defaultValue) { String result = attachments.get(key); - if (result == null || result.length() == 0) { + if (StringUtils.isEmpty(result)) { result = defaultValue; } return result; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java index a9000ecb001..eaa467daa61 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcContext.java @@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL; import org.apache.dubbo.common.threadlocal.InternalThreadLocal; import org.apache.dubbo.common.utils.NetUtils; +import org.apache.dubbo.common.utils.StringUtils; import java.net.InetSocketAddress; import java.util.ArrayList; @@ -364,7 +365,7 @@ public String getLocalAddressString() { */ public String getLocalHostName() { String host = localAddress == null ? null : localAddress.getHostName(); - if (host == null || host.length() == 0) { + if (StringUtils.isEmpty(host)) { return getLocalHost(); } return host; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java index deb37caa588..dc8a1b416b5 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcException.java @@ -34,7 +34,10 @@ public static final int SERIALIZATION_EXCEPTION = 5; public static final int NO_INVOKER_AVAILABLE_AFTER_FILTER = 6; private static final long serialVersionUID = 7815426752583648734L; - private int code; // RpcException cannot be extended, use error code for exception type to keep compatibility + /** + * RpcException cannot be extended, use error code for exception type to keep compatibility + */ + private int code; public RpcException() { super(); diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java index b40f544cf54..707bf3b77ad 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/RpcInvocation.java @@ -18,6 +18,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.utils.StringUtils; import java.io.Serializable; import java.lang.reflect.Method; @@ -198,7 +199,7 @@ public String getAttachment(String key, String defaultValue) { return defaultValue; } String value = attachments.get(key); - if (value == null || value.length() == 0) { + if (StringUtils.isEmpty(value)) { return defaultValue; } return value; diff --git a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java index 124db22807b..07517d474a4 100644 --- a/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java +++ b/dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/service/GenericService.java @@ -31,7 +31,7 @@ public interface GenericService { * @param parameterTypes Parameter types * @param args Arguments * @return invocation return value - * @throws Throwable potential exception thrown from the invocation + * @throws GenericException potential exception thrown from the invocation */ Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException; From e6325048846efbc3d121e6f40fe13f652e0fe32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E9=87=91=E5=87=AF?= Date: Tue, 8 Jan 2019 10:54:51 +0800 Subject: [PATCH 007/217] Add javadoc for dubbo-serialization module(#3002). (#3004) Add javadoc for dubbo-serialization module(#3002). --- .../dubbo/common/serialize/Cleanable.java | 6 +++++ .../dubbo/common/serialize/DataInput.java | 2 +- .../dubbo/common/serialize/DataOutput.java | 8 +++--- .../dubbo/common/serialize/ObjectInput.java | 25 ++++++++++++------- .../dubbo/common/serialize/ObjectOutput.java | 2 +- .../dubbo/common/serialize/Serialization.java | 23 ++++++++++------- .../support/SerializableClassRegistry.java | 14 +++++++++++ .../support/SerializationOptimizer.java | 8 ++++-- .../fastjson/FastJsonObjectInput.java | 3 +++ .../fastjson/FastJsonObjectOutput.java | 3 +++ .../fastjson/FastJsonSerialization.java | 7 ++++++ .../common/serialize/fst/FstFactory.java | 3 +++ .../common/serialize/fst/FstObjectInput.java | 4 ++- .../common/serialize/fst/FstObjectOutput.java | 4 ++- .../serialize/fst/FstSerialization.java | 7 ++++++ .../hessian2/Hessian2ObjectInput.java | 2 +- .../hessian2/Hessian2ObjectOutput.java | 2 +- .../hessian2/Hessian2Serialization.java | 7 ++++++ .../java/CompactedJavaSerialization.java | 7 ++++++ .../java/CompactedObjectInputStream.java | 2 +- .../java/CompactedObjectOutputStream.java | 2 +- .../serialize/java/JavaObjectInput.java | 2 +- .../serialize/java/JavaObjectOutput.java | 2 +- .../serialize/java/JavaSerialization.java | 7 ++++++ .../nativejava/NativeJavaObjectInput.java | 3 +++ .../nativejava/NativeJavaObjectOutput.java | 3 +++ .../nativejava/NativeJavaSerialization.java | 7 ++++++ .../serialize/kryo/KryoObjectInput.java | 3 +++ .../serialize/kryo/KryoObjectOutput.java | 3 +++ .../serialize/kryo/KryoSerialization.java | 3 +++ .../protostuff/ProtostuffObjectInput.java | 3 +++ .../protostuff/ProtostuffObjectOutput.java | 3 +++ .../protostuff/ProtostuffSerialization.java | 7 ++++++ .../protostuff/delegate/TimeDelegate.java | 3 +++ .../protostuff/utils/WrapperUtils.java | 15 +++++++++++ 35 files changed, 171 insertions(+), 34 deletions(-) diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Cleanable.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Cleanable.java index a8f96d3b0e9..425bb0a4ede 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Cleanable.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Cleanable.java @@ -16,7 +16,13 @@ */ package org.apache.dubbo.common.serialize; +/** + * Interface defines that the object is cleanable. + */ public interface Cleanable { + /** + * Implementations must implement this cleanup method + */ void cleanup(); } diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataInput.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataInput.java index d122e5cfa13..7930d04d101 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataInput.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataInput.java @@ -19,7 +19,7 @@ import java.io.IOException; /** - * Data input. + * Basic data type input interface. */ public interface DataInput { diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataOutput.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataOutput.java index 36577240427..58973271542 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataOutput.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/DataOutput.java @@ -19,7 +19,7 @@ import java.io.IOException; /** - * Data output. + * Basic data type output interface. */ public interface DataOutput { @@ -98,9 +98,9 @@ public interface DataOutput { /** * Write byte array. * - * @param v value. - * @param off offset. - * @param len length. + * @param v value. + * @param off the start offset in the data. + * @param len the number of bytes that are written. * @throws IOException */ void writeBytes(byte[] v, int off, int len) throws IOException; diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectInput.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectInput.java index 81207cb720a..1d8646e880e 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectInput.java @@ -20,30 +20,37 @@ import java.lang.reflect.Type; /** - * Object input. + * Object input interface. */ public interface ObjectInput extends DataInput { /** - * read object. + * read object * - * @return object. + * @return object + * @throws IOException if an I/O error occurs + * @throws ClassNotFoundException if an ClassNotFoundException occurs */ Object readObject() throws IOException, ClassNotFoundException; /** - * read object. + * read object * - * @param cls object type. - * @return object. + * @param cls object class + * @return object + * @throws IOException if an I/O error occurs + * @throws ClassNotFoundException if an ClassNotFoundException occurs */ T readObject(Class cls) throws IOException, ClassNotFoundException; /** - * read object. + * read object * - * @param cls object type. - * @return object. + * @param cls object class + * @param type object type + * @return object + * @throws IOException if an I/O error occurs + * @throws ClassNotFoundException if an ClassNotFoundException occurs */ T readObject(Class cls, Type type) throws IOException, ClassNotFoundException; diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectOutput.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectOutput.java index bf50167d810..73fa3b61fd5 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/ObjectOutput.java @@ -19,7 +19,7 @@ import java.io.IOException; /** - * Object output. + * Object output interface. */ public interface ObjectOutput extends DataOutput { diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Serialization.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Serialization.java index eb9a72e98fd..0c09df99a3d 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Serialization.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/Serialization.java @@ -25,30 +25,35 @@ import java.io.OutputStream; /** - * Serialization. (SPI, Singleton, ThreadSafe) + * Serialization strategy interface that specifies a serializer. (SPI, Singleton, ThreadSafe) + * + * The default extension is hessian2 and the default serialization implementation of the dubbo protocol. + *
    + *     e.g. <dubbo:protocol serialization="xxx" />
    + * 
    */ @SPI("hessian2") public interface Serialization { /** - * get content type id + * Get content type unique id, recommended that custom implementations use values greater than 20. * * @return content type id */ byte getContentTypeId(); /** - * get content type + * Get content type * * @return content type */ String getContentType(); /** - * create serializer + * Get a serialization implementation instance * - * @param url - * @param output + * @param url URL address for the remote service + * @param output the underlying output stream * @return serializer * @throws IOException */ @@ -56,10 +61,10 @@ public interface Serialization { ObjectOutput serialize(URL url, OutputStream output) throws IOException; /** - * create deserializer + * Get a deserialization implementation instance * - * @param url - * @param input + * @param url URL address for the remote service + * @param input the underlying input stream * @return deserializer * @throws IOException */ diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java index 2ebb3a3c7fd..22de45d5c74 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializableClassRegistry.java @@ -21,6 +21,10 @@ import java.util.LinkedHashMap; import java.util.Map; +/** + * Provide a unified serialization registry, this class used for {@code dubbo-serialization-fst} + * and {@code dubbo-serialization-kryo}, it will register some classes at startup time (for example {@link AbstractKryoFactory#create}) + */ public abstract class SerializableClassRegistry { @@ -28,6 +32,8 @@ public abstract class SerializableClassRegistry { /** * only supposed to be called at startup time + * + * @param clazz object type */ public static void registerClass(Class clazz) { registerClass(clazz, null); @@ -35,6 +41,9 @@ public static void registerClass(Class clazz) { /** * only supposed to be called at startup time + * + * @param clazz object type + * @param serializer object serializer */ public static void registerClass(Class clazz, Serializer serializer) { if (clazz == null) { @@ -43,6 +52,11 @@ public static void registerClass(Class clazz, Serializer serializer) { registrations.put(clazz, serializer); } + /** + * get registered classes + * + * @return class serializer + * */ public static Map getRegisteredClasses() { return registrations; } diff --git a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializationOptimizer.java b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializationOptimizer.java index 7085f2de89a..b043f3448f8 100644 --- a/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializationOptimizer.java +++ b/dubbo-serialization/dubbo-serialization-api/src/main/java/org/apache/dubbo/common/serialize/support/SerializationOptimizer.java @@ -19,10 +19,14 @@ import java.util.Collection; /** - * This class can be replaced with the contents in config file, but for now I think the class is easier to write - * + * Interface defining serialization optimizer, there are nothing implementations for now. */ public interface SerializationOptimizer { + /** + * Get serializable classes + * + * @return serializable classes + * */ Collection getSerializableClasses(); } diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java index 96824fd58cf..1a38f277dc7 100644 --- a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectInput.java @@ -29,6 +29,9 @@ import java.io.Reader; import java.lang.reflect.Type; +/** + * FastJson object input implementation + */ public class FastJsonObjectInput implements ObjectInput { private final BufferedReader reader; diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java index d0e4ed546e9..3f9ec2083da 100644 --- a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonObjectOutput.java @@ -28,6 +28,9 @@ import java.io.PrintWriter; import java.io.Writer; +/** + * FastJson object output implementation + */ public class FastJsonObjectOutput implements ObjectOutput { private final PrintWriter writer; diff --git a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java index 189ef0b0b86..097587132c7 100644 --- a/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java +++ b/dubbo-serialization/dubbo-serialization-fastjson/src/main/java/org/apache/dubbo/common/serialize/fastjson/FastJsonSerialization.java @@ -25,6 +25,13 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * FastJson serialization implementation + * + *
    + *     e.g. <dubbo:protocol serialization="fastjson" />
    + * 
    + */ public class FastJsonSerialization implements Serialization { @Override diff --git a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstFactory.java b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstFactory.java index b0830332b52..e41c358b43e 100644 --- a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstFactory.java +++ b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstFactory.java @@ -25,6 +25,9 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * Fst object input/output factory + */ public class FstFactory { private static final FstFactory factory = new FstFactory(); diff --git a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectInput.java b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectInput.java index b94a85f2fd8..51e8340a988 100644 --- a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectInput.java @@ -24,7 +24,9 @@ import java.io.InputStream; import java.lang.reflect.Type; - +/** + * Fst object input implementation + */ public class FstObjectInput implements ObjectInput { private FSTObjectInput input; diff --git a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectOutput.java b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectOutput.java index 46fee0b3aa0..a2c40e5d0da 100644 --- a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstObjectOutput.java @@ -23,7 +23,9 @@ import java.io.IOException; import java.io.OutputStream; - +/** + * Fst object output implementation + */ public class FstObjectOutput implements ObjectOutput { private FSTObjectOutput output; diff --git a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java index 89881df3969..e8b984c8bba 100644 --- a/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java +++ b/dubbo-serialization/dubbo-serialization-fst/src/main/java/org/apache/dubbo/common/serialize/fst/FstSerialization.java @@ -25,6 +25,13 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * Fst serialization implementation + * + *
    + *     e.g. <dubbo:protocol serialization="fst" />
    + * 
    + */ public class FstSerialization implements Serialization { @Override diff --git a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectInput.java b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectInput.java index 348d04d9913..d1ef21402c7 100644 --- a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectInput.java @@ -25,7 +25,7 @@ import java.lang.reflect.Type; /** - * Hessian2 Object input. + * Hessian2 object input implementation */ public class Hessian2ObjectInput implements ObjectInput { private final Hessian2Input mH2i; diff --git a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectOutput.java b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectOutput.java index fec356a668a..38fd3db0b27 100644 --- a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectOutput.java @@ -24,7 +24,7 @@ import java.io.OutputStream; /** - * Hessian2 Object output. + * Hessian2 object output implementation */ public class Hessian2ObjectOutput implements ObjectOutput { private final Hessian2Output mH2o; diff --git a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java index 71c6233659c..225df10908a 100644 --- a/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java +++ b/dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2Serialization.java @@ -25,6 +25,13 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * Hessian2 serialization implementation, hessian2 is the default serialization protocol for dubbo + * + *
    + *     e.g. <dubbo:protocol serialization="hessian2" />
    + * 
    + */ public class Hessian2Serialization implements Serialization { public static final byte ID = 2; diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java index 9573ed77891..8222ac45091 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedJavaSerialization.java @@ -25,6 +25,13 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * Compacted java serialization implementation + * + *
    + *     e.g. <dubbo:protocol serialization="compactedjava" />
    + * 
    + */ public class CompactedJavaSerialization implements Serialization { @Override diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectInputStream.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectInputStream.java index a6bda0aca99..2ed71f814ec 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectInputStream.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectInputStream.java @@ -26,7 +26,7 @@ import java.io.StreamCorruptedException; /** - * Compacted java object input stream. + * Compacted java object input implementation */ public class CompactedObjectInputStream extends ObjectInputStream { private ClassLoader mClassLoader; diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectOutputStream.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectOutputStream.java index 2bbf42e97eb..56847e5e254 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectOutputStream.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/CompactedObjectOutputStream.java @@ -22,7 +22,7 @@ import java.io.OutputStream; /** - * Compacted java object output stream. + * Compacted java object output implementation */ public class CompactedObjectOutputStream extends ObjectOutputStream { public CompactedObjectOutputStream(OutputStream out) throws IOException { diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectInput.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectInput.java index 00e712e6e97..936ab265063 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectInput.java @@ -24,7 +24,7 @@ import java.lang.reflect.Type; /** - * Java Object input. + * Java object input implementation */ public class JavaObjectInput extends NativeJavaObjectInput { public final static int MAX_BYTE_ARRAY_LENGTH = 8 * 1024 * 1024; diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectOutput.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectOutput.java index 49a4b45123f..0e78747c919 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaObjectOutput.java @@ -23,7 +23,7 @@ import java.io.OutputStream; /** - * Java Object output. + * Java object output implementation */ public class JavaObjectOutput extends NativeJavaObjectOutput { public JavaObjectOutput(OutputStream os) throws IOException { diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java index 72d9ef3a94d..bf98818fd43 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/java/JavaSerialization.java @@ -25,6 +25,13 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * Java serialization implementation + * + *
    + *     e.g. <dubbo:protocol serialization="java" />
    + * 
    + */ public class JavaSerialization implements Serialization { @Override diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectInput.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectInput.java index a01f1ebaa73..c791250f7af 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectInput.java @@ -25,6 +25,9 @@ import java.io.ObjectInputStream; import java.lang.reflect.Type; +/** + * Native java object input implementation + */ public class NativeJavaObjectInput implements ObjectInput { private final ObjectInputStream inputStream; diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectOutput.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectOutput.java index 89f8145a68f..2ff82f76c36 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaObjectOutput.java @@ -24,6 +24,9 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; +/** + * Native java object output implementation + */ public class NativeJavaObjectOutput implements ObjectOutput { private final ObjectOutputStream outputStream; diff --git a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java index 3b692487445..55198690607 100644 --- a/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java +++ b/dubbo-serialization/dubbo-serialization-jdk/src/main/java/org/apache/dubbo/common/serialize/nativejava/NativeJavaSerialization.java @@ -26,6 +26,13 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * Native java serialization implementation + * + *
    + *     e.g. <dubbo:protocol serialization="nativejava" />
    + * 
    + */ public class NativeJavaSerialization implements Serialization { public static final String NAME = "nativejava"; diff --git a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectInput.java b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectInput.java index fcfc91a4fe5..91648e5c628 100644 --- a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectInput.java @@ -28,6 +28,9 @@ import java.io.InputStream; import java.lang.reflect.Type; +/** + * Kryo object input implementation, kryo object can be clean + */ public class KryoObjectInput implements ObjectInput, Cleanable { private Kryo kryo; diff --git a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectOutput.java b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectOutput.java index ef2f219acd7..dd127005fe8 100644 --- a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoObjectOutput.java @@ -26,6 +26,9 @@ import java.io.IOException; import java.io.OutputStream; +/** + * Kryo object output implementation, kryo object can be clean + */ public class KryoObjectOutput implements ObjectOutput, Cleanable { private Output output; diff --git a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java index 7ff6617a704..aa10df4af90 100644 --- a/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java +++ b/dubbo-serialization/dubbo-serialization-kryo/src/main/java/org/apache/dubbo/common/serialize/kryo/KryoSerialization.java @@ -28,6 +28,9 @@ /** * TODO for now kryo serialization doesn't deny classes that don't implement the serializable interface * + *
    + *     e.g. <dubbo:protocol serialization="kryo" />
    + * 
    */ public class KryoSerialization implements Serialization { diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java index 0202762cfa2..6284d6a6777 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectInput.java @@ -29,6 +29,9 @@ import java.io.InputStream; import java.lang.reflect.Type; +/** + * Protostuff object input implementation + */ public class ProtostuffObjectInput implements ObjectInput { private DataInputStream dis; diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java index 2e91d17ef6f..3e54282a6b4 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java @@ -29,6 +29,9 @@ import java.io.IOException; import java.io.OutputStream; +/** + * Protostuff object output implementation + */ public class ProtostuffObjectOutput implements ObjectOutput { private LinkedBuffer buffer = LinkedBuffer.allocate(); diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java index aaf5bddc36d..acdeaeaff4c 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffSerialization.java @@ -26,6 +26,13 @@ import java.io.InputStream; import java.io.OutputStream; +/** + * Protostuff serialization implementation + * + *
    + *     e.g. <dubbo:protocol serialization="protostuff" />
    + * 
    + */ public class ProtostuffSerialization implements Serialization { @Override public byte getContentTypeId() { diff --git a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/delegate/TimeDelegate.java b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/delegate/TimeDelegate.java index 8cc33c7d0be..6ead01827e2 100644 --- a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/delegate/TimeDelegate.java +++ b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/delegate/TimeDelegate.java @@ -26,6 +26,9 @@ import java.io.IOException; import java.sql.Time; +/** + * Custom {@link Time} delegate + */ public class TimeDelegate implements Delegate