Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the latest code #18

Merged
merged 22 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
216e750
Fix log4j pattern layout (#2802)
lonre Dec 6, 2018
628ad77
Optimize getExtensionClass method. (#2788)
carryxyh Dec 6, 2018
8a8650f
Close all ports after tests finish (#2906)
OrDTesters Dec 7, 2018
743da20
fix testCustomExecutor (#2904)
gudegg Dec 7, 2018
ea71adb
Graceful shutdown enhancement in Spring (#2901)
LiZhenNet Dec 7, 2018
5b000a3
Simplify the code logic of the method AbstractClusterInvoker#reselect…
code4wt Dec 7, 2018
e16e78f
create AbstractRouter (#2909)
Leishunyu Dec 7, 2018
f3e8be7
Added javadoc for dubbo-filter module dubbo github issue 2884 (#2921)
khanimteyaz Dec 8, 2018
107a0cc
Enhance unit test (#2920)
lixiaojiee Dec 8, 2018
6990134
Change Readme dubbo-sample hyperlink (#2927)
luchy0120 Dec 10, 2018
3a05378
Simply TagRouter (#2924)
kexianjun Dec 10, 2018
fe456d9
make telnet config work again (#2925)
kexianjun Dec 10, 2018
c2a4c8d
Remove the log to putRandomPort when one protocol use random port (#2…
tswstarplanet Dec 10, 2018
833ba03
Fix DubboShutdownHook Memory Leak (#2922)
LiZhenNet Dec 10, 2018
bb3216d
Improve UT grammar and remove unnecessary braces. (#2930)
ralf0131 Dec 10, 2018
38c2151
re-enable testCustomExecutor (#2917)
gudegg Dec 10, 2018
437c6ce
Fixing test-order dependency for FstObjectInputTest (#2815)
OrDTesters Dec 10, 2018
dabd428
re-enable testCustomExecutor (#2913)
biyuhao Dec 10, 2018
aa5637e
Resetting ExtensionLoader to remove test order dependencies in Sticky…
OrDTesters Dec 10, 2018
e508ad4
optimize the RondRobinLoadBalance and MockClusterInvoker (#2932)
lixiaojiee Dec 10, 2018
a03d487
[Dubbo-2864] Fix build failed with -Prelease (#2923)
biyuhao Dec 11, 2018
795a840
Fix telnet can not find method with enum type (#2803)
LiZhenNet Dec 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public interface GreetingService {
}
```

*See [api/GreetingService.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/com/alibaba/dubbo/samples/api/GreetingsService.java) on GitHub.*
*See [api/GreetingService.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java) on GitHub.*

### Implement service interface for the provider

Expand All @@ -73,7 +73,7 @@ public class GreetingServiceImpl implements GreetingService {
}
```

*See [provider/GreetingServiceImpl.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/com/alibaba/dubbo/samples/server/GreetingsServiceImpl.java) on GitHub.*
*See [provider/GreetingServiceImpl.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java) on GitHub.*

### Start service provider

Expand Down Expand Up @@ -101,7 +101,7 @@ public class Application {
}
```

*See [provider/Application.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/com/alibaba/dubbo/samples/provider/Application.java) on GitHub.*
*See [provider/Application.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java) on GitHub.*

### Build and run the provider

Expand Down Expand Up @@ -141,7 +141,7 @@ public class Application {

The consumer will print out `Hello world` on the screen.

*See [consumer/Application.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/com/alibaba/dubbo/samples/consumer/Application.java) on GitHub.*
*See [consumer/Application.java](https://github.com/dubbo/dubbo-samples/blob/master/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/consumer/Application.java) on GitHub.*

### Next steps

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,31 @@ public interface Router extends Comparable<Router> {
*/
<T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException;

/**
* priority
*
* @return
*/
int getPriority();

/**
* compare Router
*
* @param o
* @return
*/
@Override
default int compareTo(Router o) {
if (o == null) {
throw new IllegalArgumentException();
}
if (this.getPriority() == o.getPriority()) {
if (o.getUrl() == null) {
return -1;
}
return getUrl().toFullString().compareTo(o.getUrl().toFullString());
} else {
return getPriority() > o.getPriority() ? 1 : -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ protected <T> Invoker<T> doSelect(List<Invoker<T>> invokers, URL url, Invocation
weightedRoundRobin = new WeightedRoundRobin();
weightedRoundRobin.setWeight(weight);
map.putIfAbsent(identifyString, weightedRoundRobin);
weightedRoundRobin = map.get(identifyString);
}
if (weight != weightedRoundRobin.getWeight()) {
//weight changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
return invokers;
}

@Override
public int getPriority() {
return Integer.MAX_VALUE;
}

private <T> List<Invoker<T>> getMockedInvokers(final List<Invoker<T>> invokers) {
if (!hasMockProviders(invokers)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

/**
* ConditionRouter
*
*/
public class ConditionRouter implements Router {

Expand Down Expand Up @@ -178,17 +177,13 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}

@Override
public URL getUrl() {
return url;
public int getPriority() {
return priority;
}

@Override
public int compareTo(Router o) {
if (o == null || o.getClass() != ConditionRouter.class) {
return 1;
}
ConditionRouter c = (ConditionRouter) o;
return this.priority == c.priority ? url.toFullString().compareTo(c.url.toFullString()) : (this.priority > c.priority ? 1 : -1);
public URL getUrl() {
return url;
}

boolean matchWhen(URL url, Invocation invocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

/**
* ScriptRouter
*
*/
public class ScriptRouter implements Router {

Expand Down Expand Up @@ -114,13 +113,24 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}
}

@Override
public int getPriority() {
return priority;
}

@Override
public int compareTo(Router o) {
if (o == null || o.getClass() != ScriptRouter.class) {
return 1;
if (o == null) {
throw new IllegalArgumentException();
}
if (this.priority == o.getPriority()) {
if (o instanceof ScriptRouter) {
ScriptRouter c = (ScriptRouter) o;
return rule.compareTo(c.rule);
}
return 0;
} else {
return this.priority > o.getPriority() ? 1 : -1;
}
ScriptRouter c = (ScriptRouter) o;
return this.priority == c.priority ? rule.compareTo(c.rule) : (this.priority > c.priority ? 1 : -1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,10 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
result.add(invoker);
}
}
// If no invoker be selected, downgrade to normal invokers
if (result.isEmpty()) {
for (Invoker<T> invoker : invokers) {
if (StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))) {
result.add(invoker);
}
}
}
// Normal request
} else {
}
// If Constants.REQUEST_TAG_KEY unspecified or no invoker be selected, downgrade to normal invokers
if (result.isEmpty()) {
for (Invoker<T> invoker : invokers) {
// Can't access tag invoker,only normal invoker should be selected
if (StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY))) {
result.add(invoker);
}
Expand All @@ -98,11 +90,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation
}

@Override
public int compareTo(Router o) {
if (o == null || o.getClass() != TagRouter.class) {
return 1;
}
TagRouter c = (TagRouter) o;
return this.priority == c.priority ? url.toFullString().compareTo(c.url.toFullString()) : (this.priority > c.priority ? 1 : -1);
public int getPriority() {
return priority;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
Expand All @@ -44,8 +45,8 @@
*/
public abstract class AbstractClusterInvoker<T> implements Invoker<T> {

private static final Logger logger = LoggerFactory
.getLogger(AbstractClusterInvoker.class);
private static final Logger logger = LoggerFactory.getLogger(AbstractClusterInvoker.class);

protected final Directory<T> directory;

protected final boolean availablecheck;
Expand Down Expand Up @@ -110,25 +111,28 @@ public void destroy() {
* @return the invoker which will final to do invoke.
* @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()) {
protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {

if (CollectionUtils.isEmpty(invokers)) {
return null;
}
String methodName = invocation == null ? "" : invocation.getMethodName();
String methodName = invocation == null ? StringUtils.EMPTY : invocation.getMethodName();

boolean sticky = invokers.get(0).getUrl().getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);
{
//ignore overloaded method
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
stickyInvoker = null;
}
//ignore concurrency problem
if (sticky && stickyInvoker != null && (selected == null || !selected.contains(stickyInvoker))) {
if (availablecheck && stickyInvoker.isAvailable()) {
return stickyInvoker;
}
boolean sticky = invokers.get(0).getUrl()
.getMethodParameter(methodName, Constants.CLUSTER_STICKY_KEY, Constants.DEFAULT_CLUSTER_STICKY);

//ignore overloaded method
if (stickyInvoker != null && !invokers.contains(stickyInvoker)) {
stickyInvoker = null;
}
//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);

if (sticky) {
Expand All @@ -137,8 +141,10 @@ protected Invoker<T> select(LoadBalance loadbalance, Invocation invocation, List
return invoker;
}

private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation, List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {
if (invokers == null || invokers.isEmpty()) {
private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected) throws RpcException {

if (CollectionUtils.isEmpty(invokers)) {
return null;
}
if (invokers.size() == 1) {
Expand All @@ -158,7 +164,7 @@ private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation, List
int index = invokers.indexOf(invoker);
try {
//Avoid collision
invoker = index < invokers.size() - 1 ? invokers.get(index + 1) : invokers.get(0);
invoker = invokers.get((index + 1) % invokers.size());
} catch (Exception e) {
logger.warn(e.getMessage() + " may because invokers list dynamic change, ignore.", e);
}
Expand All @@ -171,7 +177,8 @@ private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation, List
}

/**
* Reselect, use invokers not in `selected` first, if all invokers are in `selected`, just pick an available one using loadbalance policy.
* Reselect, use invokers not in `selected` first, if all invokers are in `selected`,
* just pick an available one using loadbalance policy.
*
* @param loadbalance
* @param invocation
Expand All @@ -181,48 +188,40 @@ private Invoker<T> doSelect(LoadBalance loadbalance, Invocation invocation, List
* @throws RpcException
*/
private Invoker<T> reselect(LoadBalance loadbalance, Invocation invocation,
List<Invoker<T>> invokers, List<Invoker<T>> selected, boolean availablecheck)
throws RpcException {
List<Invoker<T>> invokers, List<Invoker<T>> selected, boolean availablecheck) throws RpcException {

//Allocating one in advance, this list is certain to be used.
List<Invoker<T>> reselectInvokers = new ArrayList<Invoker<T>>(invokers.size() > 1 ? (invokers.size() - 1) : invokers.size());

//First, try picking a invoker not in `selected`.
if (availablecheck) { // invoker.isAvailable() should be checked
for (Invoker<T> invoker : invokers) {
if (invoker.isAvailable()) {
if (selected == null || !selected.contains(invoker)) {
reselectInvokers.add(invoker);
}
}
}
if (!reselectInvokers.isEmpty()) {
return loadbalance.select(reselectInvokers, getUrl(), invocation);
}
} else { // do not check invoker.isAvailable()
for (Invoker<T> invoker : invokers) {
if (selected == null || !selected.contains(invoker)) {
reselectInvokers.add(invoker);
}
List<Invoker<T>> reselectInvokers = new ArrayList<>(
invokers.size() > 1 ? (invokers.size() - 1) : invokers.size());

// First, try picking a invoker not in `selected`.
for (Invoker<T> invoker : invokers) {
if (availablecheck && !invoker.isAvailable()) {
continue;
}
if (!reselectInvokers.isEmpty()) {
return loadbalance.select(reselectInvokers, getUrl(), invocation);

if (selected == null || !selected.contains(invoker)) {
reselectInvokers.add(invoker);
}
}

if (!reselectInvokers.isEmpty()) {
return loadbalance.select(reselectInvokers, getUrl(), invocation);
}

// Just pick an available invoker using loadbalance policy
{
if (selected != null) {
for (Invoker<T> invoker : selected) {
if ((invoker.isAvailable()) // available first
&& !reselectInvokers.contains(invoker)) {
reselectInvokers.add(invoker);
}
if (selected != null) {
for (Invoker<T> invoker : selected) {
if ((invoker.isAvailable()) // available first
&& !reselectInvokers.contains(invoker)) {
reselectInvokers.add(invoker);
}
}
if (!reselectInvokers.isEmpty()) {
return loadbalance.select(reselectInvokers, getUrl(), invocation);
}
}
if (!reselectInvokers.isEmpty()) {
return loadbalance.select(reselectInvokers, getUrl(), invocation);
}

return null;
}

Expand Down Expand Up @@ -257,7 +256,7 @@ public String toString() {
}

protected void checkInvokers(List<Invoker<T>> invokers, Invocation invocation) {
if (invokers == null || invokers.isEmpty()) {
if (CollectionUtils.isEmpty(invokers)) {
throw new RpcException("Failed to invoke the method "
+ invocation.getMethodName() + " in the service " + getInterface().getName()
+ ". No provider available for the service " + directory.getUrl().getServiceKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public FailbackClusterInvoker(Directory<T> directory) {
super(directory);
}

private void addFailed(Invocation invocation, AbstractClusterInvoker<?> router) {
private void addFailed(Invocation invocation, AbstractClusterInvoker<?> invoker) {
if (retryFuture == null) {
synchronized (this) {
if (retryFuture == null) {
Expand All @@ -84,11 +84,11 @@ public void run() {
}
}
}
failed.put(invocation, router);
failed.put(invocation, invoker);
}

void retryFailed() {
if (failed.size() == 0) {
if (failed.isEmpty()) {
return;
}
for (Map.Entry<Invocation, AbstractClusterInvoker<?>> entry : new HashMap<>(failed).entrySet()) {
Expand Down
Loading