提交 3639efa6 编写于 作者: I Ian Luo

issue#1056: I18N effort for dubbo code base: dubbo-common

上级 ed68823d
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common;
import java.lang.annotation.Documented;
......@@ -22,32 +24,34 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 扩展点接口的标识。
* Marker for extension interface
* <p/>
* 扩展点声明配置文件,格式修改。<br />
* 以Protocol示例,配置文件META-INF/dubbo/com.xxx.Protocol内容:<br />
* 由<br/>
* <pre><code>com.foo.XxxProtocol
* com.foo.YyyProtocol</code></pre><br/>
* 改成使用KV格式<br/>
* <pre><code>xxx=com.foo.XxxProtocol
* yyy=com.foo.YyyProtocol
* </code></pre>
* Changes on extension configuration file <br/>
* Use <code>Protocol</code> as an example, its configuration file 'META-INF/dubbo/com.xxx.Protocol' is changes from: <br/>
* <pre>
* com.foo.XxxProtocol
* com.foo.YyyProtocol
* </pre>
* <p>
* to key-value pair <br/>
* <pre>
* xxx=com.foo.XxxProtocol
* yyy=com.foo.YyyProtocol
* </pre>
* <br/>
* 原因:<br/>
* 当扩展点的static字段或方法签名上引用了三方库,
* 如果三方库不存在,会导致类初始化失败,
* Extension标识Dubbo就拿不到了,异常信息就和配置对应不起来。
* <br/>
* 比如:
* Extension("mina")加载失败,
* 当用户配置使用mina时,就会报找不到扩展点,
* 而不是报加载扩展点失败,以及失败原因。
* The reason for this change is:
* <p>
* If there's third party library referenced by static field or by method in extension implementation, its class will
* fail to initialize if the third party library doesn't exist. In this case, dubbo cannot figure out extension's id
* therefore cannot be able to map the exception information with the extension, if the previous format is used.
* <p/>
* For example:
* <p>
* Fails to load Extension("mina"). When user configure to use mina, dubbo will complain the extension cannot be loaded,
* instead of reporting which extract extension implementation fails and the extract reason.
* </p>
*
* @author william.liangf
* @author ding.lid
* @export
* @deprecated 因为含义广泛废弃,改用功 {@link com.alibaba.dubbo.common.extension.SPI}
* @deprecated because it's too general, switch to use {@link com.alibaba.dubbo.common.extension.SPI}
*/
@Deprecated
@Documented
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -17,8 +18,6 @@ package com.alibaba.dubbo.common;
/**
* Node. (API/SPI, Prototype, ThreadSafe)
*
* @author william.liangf
*/
public interface Node {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -27,9 +28,8 @@ import java.util.HashMap;
import java.util.Map;
/**
* 兼容2.0.5之前版本
* Parameters for backward compatibility for version prior to 2.0.5
*
* @author tony.chenl
* @deprecated
*/
@Deprecated
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -17,8 +18,6 @@ package com.alibaba.dubbo.common;
/**
* Resetable.
*
* @author william.liangf
*/
public interface Resetable {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -64,8 +65,6 @@ import java.util.concurrent.ConcurrentHashMap;
* for this case, url protocol = null, url host = home, url path = user1/router.js
* </ul>
*
* @author william.liangf
* @author ding.lid
* @see java.net.URL
* @see java.net.URI
*/
......@@ -306,15 +305,12 @@ public final class URL implements Serializable {
}
/**
* 获取IP地址.
* <p>
* 请注意:
* 如果和Socket的地址对比,
* 或用地址作为Map的Key查找,
* 请使用IP而不是Host,
* 否则配置域名会有问题
* Fetch IP address for this URL.
*
* Pls. note that IP should be used instead of Host when to compare with socket's address or to search in a map
* which use address as its key.
*
* @return ip
* @return ip in string format
*/
public String getIp() {
if (ip == null) {
......@@ -445,14 +441,14 @@ public final class URL implements Serializable {
}
private Map<String, Number> getNumbers() {
if (numbers == null) { // 允许并发重复创建
if (numbers == null) { // concurrent initialization is tolerant
numbers = new ConcurrentHashMap<String, Number>();
}
return numbers;
}
private Map<String, URL> getUrls() {
if (urls == null) { // 允许并发重复创建
if (urls == null) { // concurrent initialization is tolerant
urls = new ConcurrentHashMap<String, URL>();
}
return urls;
......@@ -929,7 +925,7 @@ public final class URL implements Serializable {
|| value == null || value.length() == 0) {
return this;
}
// 如果没有修改,直接返回。
// if value doesn't change, return immediately
if (value.equals(getParameters().get(key))) { // value != null
return this;
}
......@@ -955,7 +951,7 @@ public final class URL implements Serializable {
/**
* Add parameters to a new url.
*
* @param parameters
* @param parameters parameters in key-value pairs
* @return A new URL
*/
public URL addParameters(Map<String, String> parameters) {
......@@ -978,7 +974,7 @@ public final class URL implements Serializable {
}
}
}
// 如果没有修改,直接返回。
// return immediately if there's no change
if (hasAndEqual) return this;
Map<String, String> map = new HashMap<String, String>(getParameters());
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -27,8 +28,6 @@ import java.util.Set;
/**
* Version
*
* @author william.liangf
*/
public final class Version {
......@@ -38,7 +37,7 @@ public final class Version {
private static final boolean COMPATIBLE = hasResource("com/taobao/remoting/impl/ConnectionRequest.class");
static {
// 检查是否存在重复的jar包
// check if there's duplicated jar
Version.checkDuplicate(Version.class);
}
......@@ -67,13 +66,13 @@ public final class Version {
public static String getVersion(Class<?> cls, String defaultVersion) {
try {
// 首先查找MANIFEST.MF规范中的版本号
// find version info from MANIFEST.MF first
String version = cls.getPackage().getImplementationVersion();
if (version == null || version.length() == 0) {
version = cls.getPackage().getSpecificationVersion();
}
if (version == null || version.length() == 0) {
// 如果规范中没有版本号,基于jar包名获取版本号
// guess version fro jar file name if nothing's found from MANIFEST.MF
CodeSource codeSource = cls.getProtectionDomain().getCodeSource();
if (codeSource == null) {
logger.info("No codeSource for class " + cls.getName() + " when getVersion, use default version " + defaultVersion);
......@@ -101,10 +100,10 @@ public final class Version {
}
}
}
// 返回版本号,如果为空返回缺省版本号
// return default version if no version info is found
return version == null || version.length() == 0 ? defaultVersion : version;
} catch (Throwable e) { // 防御性容错
// 忽略异常,返回缺省版本号
} catch (Throwable e) {
// return default version when any exception is thrown
logger.error("return default version, ignore exception " + e.getMessage(), e);
return defaultVersion;
}
......@@ -120,7 +119,7 @@ public final class Version {
public static void checkDuplicate(String path, boolean failOnError) {
try {
// 在ClassPath搜文件
// search in caller's classloader
Enumeration<URL> urls = ClassHelper.getCallerClassLoader(Version.class).getResources(path);
Set<String> files = new HashSet<String>();
while (urls.hasMoreElements()) {
......@@ -132,7 +131,7 @@ public final class Version {
}
}
}
// 如果有多个,就表示重复
// duplicated jar is found
if (files.size() > 1) {
String error = "Duplicate class " + path + " in " + files.size() + " jar " + files;
if (failOnError) {
......@@ -141,7 +140,7 @@ public final class Version {
logger.error(error);
}
}
} catch (Throwable e) { // 防御性容错
} catch (Throwable e) {
logger.error(e.getMessage(), e);
}
}
......
/*
* Copyright 1999-2012 Alibaba Group.
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -15,9 +16,6 @@
*/
package com.alibaba.dubbo.common.beanutil;
/**
* @author <a href="mailto:gang.lvg@taobao.com">kimi</a>
*/
public enum JavaBeanAccessor {
/**
......
/*
* Copyright 1999-2012 Alibaba Group.
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -21,9 +22,6 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author <a href="mailto:gang.lvg@taobao.com">kimi</a>
*/
public final class JavaBeanDescriptor implements Serializable, Iterable<Map.Entry<Object, Object>> {
public static final int TYPE_CLASS = 1;
......
/*
* Copyright 1999-2012 Alibaba Group.
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
......@@ -30,9 +31,6 @@ import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
/**
* @author <a href="mailto:gang.lvg@taobao.com">kimi</a>
*/
public final class JavaBeanSerializeUtil {
private static final Logger logger = LoggerFactory.getLogger(JavaBeanSerializeUtil.class);
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -44,10 +45,7 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* ClassGenerator
*
* @author qian.lei
*/
public final class ClassGenerator {
private static final AtomicLong CLASS_NAME_COUNTER = new AtomicLong(0);
private static final String SIMPLE_NAME_TAG = "<init>";
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -26,10 +27,7 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* Mixin
*
* @author qian.lei
*/
public abstract class Mixin {
private static final String PACKAGE_NAME = Mixin.class.getPackage().getName();
private static AtomicLong MIXIN_CLASS_COUNTER = new AtomicLong(0);
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -17,8 +18,6 @@ package com.alibaba.dubbo.common.bytecode;
/**
* NoSuchMethodException.
*
* @author qian.lei
*/
public class NoSuchMethodException extends RuntimeException {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -17,8 +18,6 @@ package com.alibaba.dubbo.common.bytecode;
/**
* NoSuchPropertyException.
*
* @author qian.lei
*/
public class NoSuchPropertyException extends RuntimeException {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -34,8 +35,6 @@ import java.util.concurrent.atomic.AtomicLong;
/**
* Proxy.
*
* @author qian.lei
*/
public abstract class Proxy {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -33,10 +34,7 @@ import java.util.regex.Matcher;
/**
* Wrapper.
*
* @author qian.lei
*/
public abstract class Wrapper {
private static final Map<Class<?>, Wrapper> WRAPPER_MAP = new ConcurrentHashMap<Class<?>, Wrapper>(); //class wrapper map
private static final String[] EMPTY_STRING_ARRAY = new String[0];
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -20,8 +21,6 @@ import com.alibaba.dubbo.common.extension.SPI;
/**
* Compiler. (SPI, Singleton, ThreadSafe)
*
* @author william.liangf
*/
@SPI("javassist")
public interface Compiler {
......@@ -30,7 +29,7 @@ public interface Compiler {
* Compile java source code.
*
* @param code Java source code
* @param classLoader TODO
* @param classLoader classloader
* @return Compiled class
*/
Class<?> compile(String code, ClassLoader classLoader);
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -23,8 +24,6 @@ import java.util.regex.Pattern;
/**
* Abstract compiler. (SPI, Prototype, ThreadSafe)
*
* @author william.liangf
*/
public abstract class AbstractCompiler implements Compiler {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -22,8 +23,6 @@ import com.alibaba.dubbo.common.extension.ExtensionLoader;
/**
* AdaptiveCompiler. (SPI, Singleton, ThreadSafe)
*
* @author william.liangf
*/
@Adaptive
public class AdaptiveCompiler implements Compiler {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -30,8 +31,6 @@ import java.util.Map;
/**
* ClassUtils. (Tool, Static, ThreadSafe)
*
* @author william.liangf
*/
public class ClassUtils {
......@@ -113,11 +112,12 @@ public class ClassUtils {
try {
return arrayForName(className);
} catch (ClassNotFoundException e) {
if (className.indexOf('.') == -1) { // 尝试java.lang包
// try to load from java.lang package
if (className.indexOf('.') == -1) {
try {
return arrayForName("java.lang." + className);
} catch (ClassNotFoundException e2) {
// 忽略尝试异常, 抛出原始异常
// ignore, let the original exception be thrown
}
}
throw e;
......@@ -259,9 +259,9 @@ public class ClassUtils {
try {
ParameterizedType parameterizedType = ((ParameterizedType) cls.getGenericInterfaces()[0]);
Object genericClass = parameterizedType.getActualTypeArguments()[i];
if (genericClass instanceof ParameterizedType) { // 处理多级泛型
if (genericClass instanceof ParameterizedType) {
return (Class<?>) ((ParameterizedType) genericClass).getRawType();
} else if (genericClass instanceof GenericArrayType) { // 处理数组泛型
} else if (genericClass instanceof GenericArrayType) {
return (Class<?>) ((GenericArrayType) genericClass).getGenericComponentType();
} else if (genericClass != null) {
return (Class<?>) genericClass;
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -33,8 +34,6 @@ import java.util.regex.Pattern;
/**
* JavassistCompiler. (SPI, Singleton, ThreadSafe)
*
* @author william.liangf
*/
public class JavassistCompiler extends AbstractCompiler {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -51,8 +52,6 @@ import java.util.Set;
/**
* JdkCompiler. (SPI, Singleton, ThreadSafe)
*
* @author william.liangf
*/
public class JdkCompiler extends AbstractCompiler {
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common.concurrent;
import com.alibaba.dubbo.common.logger.Logger;
......@@ -22,10 +38,6 @@ import java.util.concurrent.TimeUnit;
* RejectedExecutionException} or an exception thrown by {@linkplain
* MoreExecutors#sameThreadExecutor inline execution}) will be caught and
* logged.
*
* @author Nishant Thakkar
* @author Sven Mawson
* @since 1.0
*/
public final class ExecutionList {
// Logger to log exceptions caught when running runnables.
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common.concurrent;
import java.util.concurrent.Executor;
......@@ -62,10 +78,6 @@ import java.util.concurrent.RejectedExecutionException;
* impossible to change the return type. For this case, we provide a more
* expensive workaround in {@code JdkFutureAdapters}. However, when possible, it
* is more efficient and reliable to create a {@code ListenableFuture} directly.
*
* @author Sven Mawson
* @author Nishant Thakkar
* @since 1.0
*/
public interface ListenableFuture<V> extends Future<V> {
/**
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common.concurrent;
import java.util.concurrent.Callable;
......@@ -9,11 +25,6 @@ import java.util.concurrent.FutureTask;
* interface. Unlike {@code FutureTask}, {@code ListenableFutureTask} does not
* provide an overrideable {@link FutureTask#done() done()} method. For similar
* functionality, call {@link #addListener}.
* <p>
* <p>
*
* @author Sven Mawson
* @since 1.0
*/
public class ListenableFutureTask<V> extends FutureTask<V>
implements ListenableFuture<V> {
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -15,6 +16,8 @@
*/
package com.alibaba.dubbo.common.extension;
import com.alibaba.dubbo.common.URL;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
......@@ -22,62 +25,64 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Activate
* <p/>
* 对于可以被框架中自动激活加载扩展,此Annotation用于配置扩展被自动激活加载条件。
* 比如,过滤扩展,有多个实现,使用Activate Annotation的扩展可以根据条件被自动加载。
* Activate. This annotation is useful for automatically activate certain extensions with the given criteria,
* for examples: <code>@Activate</code> can be used to load certain <code>Filter</code> extension when there are
* multiple implementations.
* <ol>
* <li>{@link Activate#group()}生效的Group。具体的有哪些Group值由框架SPI给出。
* <li>{@link Activate#value()}在{@link com.alibaba.dubbo.common.URL}中Key集合中有,则生效。
* <li>{@link Activate#group()} specifies group criteria. Framework SPI defines the valid group values.
* <li>{@link Activate#value()} specifies parameter key in {@link URL} criteria.
* </ol>
* <p>
* <p/>
* 底层框架SPI提供者通过{@link com.alibaba.dubbo.common.extension.ExtensionLoader}的{@link ExtensionLoader#getActivateExtension}方法
* 获得条件的扩展。
* SPI provider can call {@link ExtensionLoader#getActivateExtension(URL, String, String)} to find out all activated
* extensions with the given criteria.
*
* @author william.liangf
* @author ding.lid
* @export
* @see SPI
* @see URL
* @see ExtensionLoader
* @see ExtensionLoader#getActivateExtension(com.alibaba.dubbo.common.URL, String[], String)
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Activate {
/**
* Group过滤条件。
* <br />
* 包含{@link ExtensionLoader#getActivateExtension}的group参数给的值,则返回扩展。
* <br />
* 如没有Group设置,则不过滤。
* Activate the current extension when one of the groups matches. The group passed into
* {@link ExtensionLoader#getActivateExtension(URL, String, String)} will be used for matching.
*
* @return group names to match
* @see ExtensionLoader#getActivateExtension(URL, String, String)
*/
String[] group() default {};
/**
* Key过滤条件。包含{@link ExtensionLoader#getActivateExtension}的URL的参数Key中有,则返回扩展。
* <p/>
* 示例:<br/>
* 注解的值 <code>@Activate("cache,validatioin")</code>,
* 则{@link ExtensionLoader#getActivateExtension}的URL的参数有<code>cache</code>Key,或是<code>validatioin</code>则返回扩展。
* <br/>
* 如没有设置,则不过滤。
* Activate the current extension when the specified keys appear in the URL's parameters.
* <p>
* For example, given <code>@Activate("cache, validation")</code>, the current extension will be return only when
* there's either <code>cache</code> or <code>validation</code> key appeared in the URL's parameters.
* </p>
*
* @return URL parameter keys
* @see ExtensionLoader#getActivateExtension(URL, String)
* @see ExtensionLoader#getActivateExtension(URL, String, String)
*/
String[] value() default {};
/**
* 排序信息,可以不提供。
* Relative ordering info, optional
*
* @return extension list which should be put before the current one
*/
String[] before() default {};
/**
* 排序信息,可以不提供。
* Relative ordering info, optional
*
* @return extension list which should be put after the current one
*/
String[] after() default {};
/**
* 排序信息,可以不提供。
* Absolute ordering info, optional
*
* @return absolute ordering info
*/
int order() default 0;
}
\ No newline at end of file
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -24,10 +25,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 在{@link ExtensionLoader}生成Extension的Adaptive Instance时,为{@link ExtensionLoader}提供信息。
* Provide helpful information for {@link ExtensionLoader} to inject dependency extension instance.
*
* @author ding.lid
* @export
* @see ExtensionLoader
* @see URL
*/
......@@ -35,23 +34,26 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Adaptive {
/**
* 从{@link URL}的Key名,对应的Value作为要Adapt成的Extension名。
* Decide which target extension to be injected. The name of the target extension is decided by the parameter passed
* in the URL, and the parameter names are given by this method.
* <p>
* 如果{@link URL}这些Key都没有Value,使用 用 缺省的扩展(在接口的{@link SPI}中设定的值)。<br>
* 比如,<code>String[] {"key1", "key2"}</code>,表示
* If the specified parameters are not found from {@link URL}, then the default extension will be used for
* dependency injection (specified in its interface's {@link SPI}).
* <p>
* For examples, given <code>String[] {"key1", "key2"}</code>:
* <ol>
* <li>先在URL上找key1的Value作为要Adapt成的Extension名;
* <li>key1没有Value,则使用key2的Value作为要Adapt成的Extension名。
* <li>key2没有Value,使用缺省的扩展。
* <li>如果没有设定缺省扩展,则方法调用会抛出{@link IllegalStateException}。
* <li>find parameter 'key1' in URL, use its value as the extension's name</li>
* <li>try 'key2' for extension's name if 'key1' is not found (or its value is empty) in URL</li>
* <li>use default extension if 'key2' doesn't appear either</li>
* <li>otherwise, throw {@link IllegalStateException}</li>
* </ol>
* <p>
* 如果不设置则缺省使用Extension接口类名的点分隔小写字串。<br>
* 即对于Extension接口{@code com.alibaba.dubbo.xxx.YyyInvokerWrapper}的缺省值为<code>String[] {"yyy.invoker.wrapper"}</code>
* If default extension's name is not give on interface's {@link SPI}, then a name is generated from interface's
* class name with the rule: divide classname from capital char into several parts, and separate the parts with
* dot '.', for example: for {@code com.alibaba.dubbo.xxx.YyyInvokerWrapper}, its default name is
* <code>String[] {"yyy.invoker.wrapper"}</code>. This name will be used to search for parameter from URL.
*
* @see SPI#value()
* @return parameter key names in URL
*/
String[] value() default {};
......
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -17,9 +18,6 @@ package com.alibaba.dubbo.common.extension;
/**
* ExtensionFactory
*
* @author william.liangf
* @export
*/
@SPI
public interface ExtensionFactory {
......
......@@ -43,16 +43,14 @@ import java.util.concurrent.ConcurrentMap;
import java.util.regex.Pattern;
/**
* Dubbo使用的扩展点获取。<p>
* Load dubbo extensions
* <ul>
* <li>自动注入关联扩展点。</li>
* <li>自动Wrap上扩展点的Wrap类。</li>
* <li>缺省获得的的扩展点是一个Adaptive Instance。
* <li>auto inject dependency extension </li>
* <li>auto wrap extension in wrapper </li>
* <li>default extension is an adaptive instance</li>
* </ul>
*
* @author william.liangf
* @author ding.lid
* @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Service%20Provider">JDK5.0的自动发现机制实现</a>
* @see <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Service%20Provider">Service Provider in Java 5</a>
* @see com.alibaba.dubbo.common.extension.SPI
* @see com.alibaba.dubbo.common.extension.Adaptive
* @see com.alibaba.dubbo.common.extension.Activate
......@@ -136,9 +134,7 @@ public class ExtensionLoader<T> {
}
/**
* This is equivalent to <pre>
* getActivateExtension(url, key, null);
* </pre>
* This is equivalent to {@code getActivateExtension(url, key, null)}
*
* @param url url
* @param key url parameter key which used to get extension point names
......@@ -150,9 +146,7 @@ public class ExtensionLoader<T> {
}
/**
* This is equivalent to <pre>
* getActivateExtension(url, values, null);
* </pre>
* This is equivalent to {@code getActivateExtension(url, values, null)}
*
* @param url url
* @param values extension point names
......@@ -164,9 +158,7 @@ public class ExtensionLoader<T> {
}
/**
* This is equivalent to <pre>
* getActivateExtension(url, url.getParameter(key).split(","), null);
* </pre>
* This is equivalent to {@code getActivateExtension(url, url.getParameter(key).split(","), null)}
*
* @param url url
* @param key url parameter key which used to get extension point names
......@@ -262,9 +254,10 @@ public class ExtensionLoader<T> {
}
/**
* 返回扩展点实例,如果没有指定的扩展点或是还没加载(即实例化)则返回<code>null</code>。注意:此方法不会触发扩展点的加载。
* <p/>
* 一般应该调用{@link #getExtension(String)}方法获得扩展,这个方法会触发扩展点加载。
* Get extension's instance. Return <code>null</code> if extension is not found or is not initialized. Pls. note
* that this method will not trigger extension load.
* <p>
* In order to trigger extension load, call {@link #getExtension(String)} instead.
*
* @see #getExtension(String)
*/
......@@ -281,9 +274,9 @@ public class ExtensionLoader<T> {
}
/**
* 返回已经加载的扩展点的名字。
* <p/>
* 一般应该调用{@link #getSupportedExtensions()}方法获得扩展,这个方法会返回所有的扩展点。
* Return the list of extensions which are already loaded.
* <p>
* Usually {@link #getSupportedExtensions()} should be called in order to get all extensions.
*
* @see #getSupportedExtensions()
*/
......@@ -292,10 +285,8 @@ public class ExtensionLoader<T> {
}
/**
* 返回指定名字的扩展。如果指定名字的扩展不存在,则抛异常 {@link IllegalStateException}.
*
* @param name
* @return
* Find the extension with the given name. If the specified name is not found, then {@link IllegalStateException}
* will be thrown.
*/
@SuppressWarnings("unchecked")
public T getExtension(String name) {
......@@ -323,7 +314,7 @@ public class ExtensionLoader<T> {
}
/**
* 返回缺省的扩展,如果没有设置则返回<code>null</code>。
* Return default extension, return <code>null</code> if it's not configured.
*/
public T getDefaultExtension() {
getExtensionClasses();
......@@ -350,7 +341,7 @@ public class ExtensionLoader<T> {
}
/**
* 返回缺省的扩展点名,如果没有设置缺省则返回<code>null</code>。
* Return default extension name, return <code>null</code> if not configured.
*/
public String getDefaultExtensionName() {
getExtensionClasses();
......@@ -358,11 +349,11 @@ public class ExtensionLoader<T> {
}
/**
* 编程方式添加新扩展点。
* Register new extension via API
*
* @param name 扩展点名
* @param clazz 扩展点类
* @throws IllegalStateException 要添加扩展点名已经存在。
* @param name extension name
* @param clazz extension class
* @throws IllegalStateException when extension with the same name has already been registered.
*/
public void addExtension(String name, Class<?> clazz) {
getExtensionClasses(); // load classes
......@@ -397,12 +388,12 @@ public class ExtensionLoader<T> {
}
/**
* 编程方式添加替换已有扩展点。
* Replace the existing extension via API
*
* @param name 扩展点名
* @param clazz 扩展点类
* @throws IllegalStateException 要添加扩展点名已经存在。
* @deprecated 不推荐应用使用,一般只在测试时可以使用
* @param name extension name
* @param clazz extension class
* @throws IllegalStateException when extension to be placed doesn't exist
* @deprecated not recommended any longer, and use only when test
*/
@Deprecated
public void replaceExtension(String name, Class<?> clazz) {
......@@ -567,7 +558,7 @@ public class ExtensionLoader<T> {
return classes;
}
// 此方法已经getExtensionClasses方法同步过。
// synchronized in getExtensionClasses
private Map<String, Class<?>> loadExtensionClasses() {
final SPI defaultAnnotation = type.getAnnotation(SPI.class);
if (defaultAnnotation != null) {
......@@ -744,7 +735,7 @@ public class ExtensionLoader<T> {
break;
}
}
// 完全没有Adaptive方法,则不需要生成Adaptive类
// no need to generate adaptive class since there's no adaptive method found.
if (!hasAdaptiveAnnotation)
throw new IllegalStateException("No adaptive method on extension " + type.getName() + ", refuse to create the adaptive class!");
......@@ -771,7 +762,7 @@ public class ExtensionLoader<T> {
break;
}
}
// 有类型为URL的参数
// found parameter in URL type
if (urlTypeIndex != -1) {
// Null Point check
String s = String.format("\nif (arg%d == null) throw new IllegalArgumentException(\"url == null\");",
......@@ -781,11 +772,11 @@ public class ExtensionLoader<T> {
s = String.format("\n%s url = arg%d;", URL.class.getName(), urlTypeIndex);
code.append(s);
}
// 参数没有URL类型
// did not find parameter in URL type
else {
String attribMethod = null;
// 找到参数的URL属性
// find URL getter method
LBL_PTS:
for (int i = 0; i < pts.length; ++i) {
Method[] ms = pts[i].getMethods();
......@@ -803,7 +794,7 @@ public class ExtensionLoader<T> {
}
}
if (attribMethod == null) {
throw new IllegalStateException("fail to create adative class for interface " + type.getName()
throw new IllegalStateException("fail to create adaptive class for interface " + type.getName()
+ ": not found url parameter or url attribute in parameters of method " + method.getName());
}
......@@ -820,7 +811,7 @@ public class ExtensionLoader<T> {
}
String[] value = adaptiveAnnotation.value();
// 没有设置Key,则使用“扩展点接口名的点分隔 作为Key
// value is not set, use the value generated from class name as the key
if (value.length == 0) {
char[] charArray = type.getSimpleName().toCharArray();
StringBuilder sb = new StringBuilder(128);
......
/*
* Copyright 1999-2011 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.common.extension;
import java.lang.annotation.Documented;
......@@ -22,31 +24,32 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* 扩展点接口的标识。
* Marker for extension interface
* <p/>
* 扩展点声明配置文件,格式修改。<br />
* 以Protocol示例,配置文件META-INF/dubbo/com.xxx.Protocol内容:<br />
* 由<br/>
* <pre><code>com.foo.XxxProtocol
* com.foo.YyyProtocol</code></pre><br/>
* 改成使用KV格式<br/>
* <pre><code>xxx=com.foo.XxxProtocol
* yyy=com.foo.YyyProtocol
* </code></pre>
* Changes on extension configuration file <br/>
* Use <code>Protocol</code> as an example, its configuration file 'META-INF/dubbo/com.xxx.Protocol' is changes from: <br/>
* <pre>
* com.foo.XxxProtocol
* com.foo.YyyProtocol
* </pre>
* <p>
* to key-value pair <br/>
* <pre>
* xxx=com.foo.XxxProtocol
* yyy=com.foo.YyyProtocol
* </pre>
* <br/>
* 原因:<br/>
* 当扩展点的static字段或方法签名上引用了三方库,
* 如果三方库不存在,会导致类初始化失败,
* Extension标识Dubbo就拿不到了,异常信息就和配置对应不起来。
* <br/>
* 比如:
* Extension("mina")加载失败,
* 当用户配置使用mina时,就会报找不到扩展点,
* 而不是报加载扩展点失败,以及失败原因。
*
* @author william.liangf
* @author ding.lid
* @export
* The reason for this change is:
* <p>
* If there's third party library referenced by static field or by method in extension implementation, its class will
* fail to initialize if the third party library doesn't exist. In this case, dubbo cannot figure out extension's id
* therefore cannot be able to map the exception information with the extension, if the previous format is used.
* <p/>
* For example:
* <p>
* Fails to load Extension("mina"). When user configure to use mina, dubbo will complain the extension cannot be loaded,
* instead of reporting which extract extension implementation fails and the extract reason.
* </p>
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
......@@ -54,7 +57,7 @@ import java.lang.annotation.Target;
public @interface SPI {
/**
* 缺省扩展点名。
* default extension name
*/
String value() default "";
......
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -25,8 +26,6 @@ import java.util.List;
/**
* AdaptiveExtensionFactory
*
* @author william.liangf
*/
@Adaptive
public class AdaptiveExtensionFactory implements ExtensionFactory {
......
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -21,8 +22,6 @@ import com.alibaba.dubbo.common.extension.SPI;
/**
* SpiExtensionFactory
*
* @author william.liangf
*/
public class SpiExtensionFactory implements ExtensionFactory {
......
/*
* Copyright 1999-2012 Alibaba Group.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
......@@ -23,8 +24,6 @@ import java.util.Comparator;
/**
* OrderComparetor
*
* @author william.liangf
*/
public class ActivateComparator implements Comparator<Object> {
......@@ -79,7 +78,8 @@ public class ActivateComparator implements Comparator<Object> {
}
int n1 = a1 == null ? 0 : a1.order();
int n2 = a2 == null ? 0 : a2.order();
return n1 > n2 ? 1 : -1; // 就算n1 == n2也不能返回0,否则在HashSet等集合中,会被认为是同一值而覆盖
// never return 0 even if n1 equals n2, otherwise, o1 and o2 will override each other in collection like HashSet
return n1 > n2 ? 1 : -1;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册