Skip to content

Commit

Permalink
Merge alibaba/dubbo/master to myself repo (#1)
Browse files Browse the repository at this point in the history
* @reference support annotate on annotation type

* Fixes apache#1303 TimeUnit conversion error

* Fixes apache#1289, use bind_port as mapping key

* Fixes apache#1313, remove destroy check in Registry.

* checkout .travis.yml from origin/master

* Fix hessian2 serialized short, byte is converted to int bug (apache#1232)

* Fix hessian2 serialized short, byte is converted to int bug

* Fix hessian2 serialized short, byte is converted to int bug

* adapt jdk1.5+

* fixed travis-ci failed because of test cases. (apache#1370)

* Merge pull request apache#1377, remove redundant arguments for StatItem.isAllowable()

* Merge pull request apache#1378, replace StringBuider with simple string concatenation in log.

* Merge pull request apache#1375, remove unnecessary boxing.

Fixes apache#1245

* Merge pull request apache#1331, add optional parameter to support hessian protocol method overload and request protocol version.

* Merge pull request apache#1376, do not instantiate load balance if there is no invokers

Fixes apache#1297

* Merge pull request apache#1384, fix build string bug.

* Merge pull request apache#1040, refactor: replace some deprecated methods related with jedis.

* Merge pull request apache#1242, remove redundant null check.

fixes apache#1231
  • Loading branch information
诣极 ( yì jí ) authored Feb 26, 2018
1 parent 16bac78 commit 0d7dfaa
Show file tree
Hide file tree
Showing 39 changed files with 763 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,18 @@ public void destroy() {

/**
* Select a invoker using loadbalance policy.</br>
* a)Firstly, select an invoker using loadbalance. If this invoker is in previously selected list, or, if this invoker is unavailable, then continue step b (reselect), otherwise return the first selected invoker</br>
* b)Reslection, the validation rule for reselection: selected > available. This rule guarantees that the selected invoker has the minimum chance to be one in the previously selected list, and also guarantees this invoker is available.
* a)Firstly, select an invoker using loadbalance. If this invoker is in previously selected list, or,
* if this invoker is unavailable, then continue step b (reselect), otherwise return the first selected invoker</br>
* b)Reslection, the validation rule for reselection: selected > available. This rule guarantees that
* the selected invoker has the minimum chance to be one in the previously selected list, and also
* guarantees this invoker is available.
*
* @param loadbalance load balance policy
* @param invocation
* @param invokers invoker candidates
* @param selected exclude selected invokers or not
* @return
* @throws RpcExceptione
* @throws RpcException
*/
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
if (invokers == null || invokers.isEmpty())
Expand All @@ -109,22 +112,22 @@ protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
stickyInvoker = null;
}
//ignore cucurrent problem
//ignore concurrency problem
if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) {
if (availablecheck && stickyInvoker.isAvailable()) {
return stickyInvoker;
}
}
}
Invoker<T> invoker = doselect(loadbalance, invocation, invokers, selected);
Invoker<T> invoker = doSelect(loadbalance, invocation, invokers, selected);

if (sticky) {
stickyInvoker = invoker;
}
return invoker;
}

private Invoker<T> doselect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
if (invokers == null || invokers.isEmpty())
return null;
if (invokers.size() == 1)
Expand All @@ -133,6 +136,9 @@ private Invoker<T> doselect(LoadBalance loadbalance, Invocation invocation, List
if (invokers.size() == 2 && selected != null && !selected.isEmpty()) {
return selected.get(0) == invokers.get(0) ? invokers.get(1) : invokers.get(0);
}
if (loadbalance == null) {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
}
Invoker<T> invoker = loadbalance.select(invokers, getUrl(), invocation);

//If the `invoker` is in the `selected` or invoker is unavailable && availablecheck is true, reselect.
Expand All @@ -153,7 +159,7 @@ private Invoker<T> doselect(LoadBalance loadbalance, Invocation invocation, List
}
}
} catch (Throwable t) {
logger.error("clustor relselect fail reason is :" + t.getMessage() + " if can not slove ,you can set cluster.availablecheck=false in url", t);
logger.error("cluster reselect fail reason is :" + t.getMessage() + " if can not solve, you can set cluster.availablecheck=false in url", t);
}
}
return invoker;
Expand Down Expand Up @@ -216,17 +222,12 @@ private Invoker<T> reselect(LoadBalance loadbalance, Invocation invocation,
}

public Result invoke(final Invocation invocation) throws RpcException {

checkWhetherDestroyed();

LoadBalance loadbalance;

LoadBalance loadbalance = null;
List<Invoker<T>> invokers = list(invocation);
if (invokers != null && !invokers.isEmpty()) {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
.getMethodParameter(invocation.getMethodName(), Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
} else {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
}
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
return doInvoke(invocation, invokers, loadbalance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,27 @@ public Result call() throws Exception {
.append(" ]")
.toString());
}
if (method != null) {
if (!Modifier.isPublic(method.getModifiers())) {
method.setAccessible(true);
}
result = resultList.remove(0).getValue();
try {
if (method.getReturnType() != void.class
&& method.getReturnType().isAssignableFrom(result.getClass())) {
for (Result r : resultList) {
result = method.invoke(result, r.getValue());
}
} else {
for (Result r : resultList) {
method.invoke(result, r.getValue());
}
if (!Modifier.isPublic(method.getModifiers())) {
method.setAccessible(true);
}
result = resultList.remove(0).getValue();
try {
if (method.getReturnType() != void.class
&& method.getReturnType().isAssignableFrom(result.getClass())) {
for (Result r : resultList) {
result = method.invoke(result, r.getValue());
}
} else {
for (Result r : resultList) {
method.invoke(result, r.getValue());
}
} catch (Exception e) {
throw new RpcException(
new StringBuilder(32)
.append("Can not merge result: ")
.append(e.getMessage()).toString(),
e);
}
} else {
} catch (Exception e) {
throw new RpcException(
new StringBuilder(32)
.append("Can not merge result because missing method [ ")
.append(merger)
.append(" ] in class [ ")
.append(returnType.getClass().getName())
.append(" ]")
.toString());
.append("Can not merge result: ")
.append(e.getMessage()).toString(),
e);
}
} else {
Merger resultMerger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,14 @@ public class Constants {
public static final String QOS_PORT = "qos.port";

public static final String ACCEPT_FOREIGN_IP = "qos.accept.foreign.ip";

public static final String HESSIAN2_REQUEST_KEY = "hessian2.request";

public static final boolean DEFAULT_HESSIAN2_REQUEST = false;

public static final String HESSIAN_OVERLOAD_METHOD_KEY = "hessian.overload.method";

public static final boolean DEFAULT_HESSIAN_OVERLOAD_METHOD = false;

/*
* private Constants(){ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public String setEnumNameProperty(String name) {

public String getEnumPropertyName() {
if (isEnumType()) {
Object result = getProperty(ENUM_PROPERTY_NAME).toString();
Object result = getProperty(ENUM_PROPERTY_NAME);
return result == null ? null : result.toString();
}
throw new IllegalStateException("The instance is not a enum wrapper");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ public boolean hasExtension(String name) {
if (name == null || name.length() == 0)
throw new IllegalArgumentException("Extension name == null");
try {
return getExtensionClass(name) != null;
this.getExtensionClass(name);
return true;
} catch (Throwable t) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static Map<String, String> split(List<String> list, String separator) {
return null;
}
Map<String, String> map = new HashMap<String, String>();
if (list == null || list.isEmpty()) {
if (list.isEmpty()) {
return map;
}
for (String item : list) {
Expand All @@ -113,7 +113,7 @@ public static List<String> join(Map<String, String> map, String separator) {
return null;
}
List<String> list = new ArrayList<String>();
if (map == null || map.size() == 0) {
if (map.size() == 0) {
return list;
}
for (Map.Entry<String, String> entry : map.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ && isPrimitive(method.getReturnType())) {
if (parameter == null || !parameter.attribute())
continue;
String key;
if (parameter != null && parameter.key() != null && parameter.key().length() > 0) {
if (parameter.key() != null && parameter.key().length() > 0) {
key = parameter.key();
} else {
int i = name.startsWith("get") ? 3 : 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1202,4 +1202,4 @@
</xsd:annotation>
</xsd:element>

</xsd:schema>
</xsd:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -76,8 +75,6 @@ public abstract class AbstractRegistry implements Registry {
// Local disk cache file
private File file;

private AtomicBoolean destroyed = new AtomicBoolean(false);

public AbstractRegistry(URL url) {
setUrl(url);
// Start file save timer
Expand Down Expand Up @@ -442,10 +439,6 @@ private void saveProperties(URL url) {
}

public void destroy() {
if (!destroyed.compareAndSet(false, true)) {
return;
}

if (logger.isInfoEnabled()) {
logger.info("Destroy registry:" + getUrl());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* FailbackRegistry. (SPI, Prototype, ThreadSafe)
Expand All @@ -58,8 +57,6 @@ public abstract class FailbackRegistry extends AbstractRegistry {

private final ConcurrentMap<URL, Map<NotifyListener, List<URL>>> failedNotified = new ConcurrentHashMap<URL, Map<NotifyListener, List<URL>>>();

private AtomicBoolean destroyed = new AtomicBoolean(false);

public FailbackRegistry(URL url) {
super(url);
int retryPeriod = url.getParameter(Constants.REGISTRY_RETRY_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RETRY_PERIOD);
Expand Down Expand Up @@ -125,9 +122,6 @@ private void removeFailedSubscribed(URL url, NotifyListener listener) {

@Override
public void register(URL url) {
if (destroyed.get()){
return;
}
super.register(url);
failedRegistered.remove(url);
failedUnregistered.remove(url);
Expand Down Expand Up @@ -158,9 +152,6 @@ public void register(URL url) {

@Override
public void unregister(URL url) {
if (destroyed.get()){
return;
}
super.unregister(url);
failedRegistered.remove(url);
failedUnregistered.remove(url);
Expand Down Expand Up @@ -191,9 +182,6 @@ public void unregister(URL url) {

@Override
public void subscribe(URL url, NotifyListener listener) {
if (destroyed.get()){
return;
}
super.subscribe(url, listener);
removeFailedSubscribed(url, listener);
try {
Expand Down Expand Up @@ -228,9 +216,6 @@ public void subscribe(URL url, NotifyListener listener) {

@Override
public void unsubscribe(URL url, NotifyListener listener) {
if (destroyed.get()){
return;
}
super.unsubscribe(url, listener);
removeFailedSubscribed(url, listener);
try {
Expand Down Expand Up @@ -448,9 +433,6 @@ protected void retry() {

@Override
public void destroy() {
if (!canDestroy()){
return;
}
super.destroy();
try {
retryFuture.cancel(true);
Expand All @@ -459,16 +441,6 @@ public void destroy() {
}
}

// TODO: 2017/8/30 to abstract this method
protected boolean canDestroy(){
if (destroyed.compareAndSet(false, true)) {
return true;
}else{
return false;
}
}


// ==== Template method ====

protected abstract void doRegister(URL url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ public List<URL> lookup(URL url) {
urls.addAll(values);
}
}
if (urls == null || urls.isEmpty()) {
if (urls.isEmpty()) {
List<URL> cacheUrls = getCacheUrls(url);
if (cacheUrls != null && !cacheUrls.isEmpty()) {
urls.addAll(cacheUrls);
}
}
if (urls == null || urls.isEmpty()) {
if (urls.isEmpty()) {
for (URL u : getRegistered()) {
if (UrlUtils.isMatch(url, u)) {
urls.add(u);
Expand Down
Loading

0 comments on commit 0d7dfaa

Please sign in to comment.