Skip to content

Commit

Permalink
Merge branch '3.x-dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Aug 30, 2019
2 parents 9a9bf2a + 8e62405 commit 9f5cc83
Show file tree
Hide file tree
Showing 122 changed files with 4,728 additions and 1,210 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target/
*.zip
*.tar
*.tar.gz
.flattened-pom.xml

# eclipse ignore
.settings/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static <T> RouterChain<T> buildChain(URL url) {

private RouterChain(URL url) {
List<RouterFactory> extensionFactories = ExtensionLoader.getExtensionLoader(RouterFactory.class)
.getActivateExtension(url, (String[]) null);
.getActivateExtension(url, "router");

List<Router> routers = extensionFactories.stream()
.map(factory -> factory.getRouter(url))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public <T> List<Invoker<T>> route(final List<Invoker<T>> invokers,
if (invocation.getAttachments() == null) {
return getNormalInvokers(invokers);
} else {
String value = invocation.getAttachments().get(INVOCATION_NEED_MOCK);
String value = (String) invocation.getAttachments().get(INVOCATION_NEED_MOCK);
if (value == null) {
return getNormalInvokers(invokers);
} else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public <T> List<Invoker<T>> route(List<Invoker<T>> invokers, URL url, Invocation

List<Invoker<T>> result = invokers;
String tag = StringUtils.isEmpty(invocation.getAttachment(Constants.TAG_KEY)) ? url.getParameter(Constants.TAG_KEY) :
invocation.getAttachment(Constants.TAG_KEY);
(String) invocation.getAttachment(Constants.TAG_KEY);

// if we are requesting for a Provider with a specific tag
if (StringUtils.isNotEmpty(tag)) {
Expand Down Expand Up @@ -164,7 +164,7 @@ private <T> List<Invoker<T>> filterUsingStaticTag(List<Invoker<T>> invokers, URL
List<Invoker<T>> result = invokers;
// Dynamic param
String tag = StringUtils.isEmpty(invocation.getAttachment(Constants.TAG_KEY)) ? url.getParameter(Constants.TAG_KEY) :
invocation.getAttachment(Constants.TAG_KEY);
(String) invocation.getAttachment(Constants.TAG_KEY);
// Tag request
if (!StringUtils.isEmpty(tag)) {
result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(TAG_KEY)));
Expand All @@ -189,7 +189,7 @@ public boolean isForce() {
}

private boolean isForceUseTag(Invocation invocation) {
return Boolean.valueOf(invocation.getAttachment(FORCE_USE_TAG, url.getParameter(FORCE_USE_TAG, "false")));
return Boolean.valueOf((String) invocation.getAttachment(FORCE_USE_TAG, url.getParameter(FORCE_USE_TAG, "false")));
}

private <T> List<Invoker<T>> filterInvoker(List<Invoker<T>> invokers, Predicate<Invoker<T>> predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public Result invoke(final Invocation invocation) throws RpcException {
checkWhetherDestroyed();

// binding attachments into invocation.
Map<String, String> contextAttachments = RpcContext.getContext().getAttachments();
Map<String, Object> contextAttachments = RpcContext.getContext().getAttachments();
if (contextAttachments != null && contextAttachments.size() != 0) {
((RpcInvocation) invocation).addAttachments(contextAttachments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public Object[] getArguments() {
return new Object[]{"aa"};
}

public Map<String, String> getAttachments() {
Map<String, String> attachments = new HashMap<String, String>();
public Map<String, Object> getAttachments() {
Map<String, Object> attachments = new HashMap<String, Object>();
attachments.put(PATH_KEY, "dubbo");
attachments.put(GROUP_KEY, "dubbo");
attachments.put(VERSION_KEY, "1.0.0");
Expand All @@ -58,25 +58,40 @@ public Map<String, String> getAttachments() {
}

@Override
public void setAttachment(String key, String value) {
public void setAttachment(String key, Object value) {

}

@Override
public void setAttachmentIfAbsent(String key, String value) {
public void setAttachmentIfAbsent(String key, Object value) {

}

public Invoker<?> getInvoker() {
return null;
}

public String getAttachment(String key) {
@Override
public Object put(Object key, Object value) {
return null;
}

@Override
public Object get(Object key) {
return null;
}

@Override
public Map<Object, Object> getAttributes() {
return null;
}

public Object getAttachment(String key) {
return getAttachments().get(key);
}

public String getAttachment(String key, String defaultValue) {
public Object getAttachment(String key, Object defaultValue) {
return getAttachments().get(key);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ public void testBindingAttachment() {

// setup attachment
RpcContext.getContext().setAttachment(attachKey, attachValue);
Map<String, String> attachments = RpcContext.getContext().getAttachments();
Map<String, Object> attachments = RpcContext.getContext().getAttachments();
Assertions.assertTrue( attachments != null && attachments.size() == 1,"set attachment failed!");

cluster = new AbstractClusterInvoker(dic) {
@Override
protected Result doInvoke(Invocation invocation, List invokers, LoadBalance loadbalance)
throws RpcException {
// attachment will be bind to invocation
String value = invocation.getAttachment(attachKey);
String value = (String) invocation.getAttachment(attachKey);
Assertions.assertTrue(value != null && value.equals(attachValue),"binding attachment failed!");
return null;
}
Expand Down
Loading

0 comments on commit 9f5cc83

Please sign in to comment.