Skip to content

Commit

Permalink
optimize dumpService warning on starting up ; async request suppport …
Browse files Browse the repository at this point in the history
…in cluster rpc client proxy. (#3808)

* optimize  dumpService warning on starting up .

* async request suppport in cluster rpc client proxy.

* async request suppport in cluster rpc client proxy.
  • Loading branch information
shiyiyue1102 authored Sep 11, 2020
1 parent 721791a commit fac4879
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RemoteConstants {

public static final String LABEL_SOURCE_SDK = "sdk";

public static final String LABEL_SOURCE_NODE = "node";
public static final String LABEL_SOURCE_CLUSTER = "cluster";

public static final String LABEL_MODULE = "module";

Expand Down
86 changes: 86 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/remote/Requester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
*
* 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
*
* 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.nacos.api.remote;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.remote.request.Request;
import com.alibaba.nacos.api.remote.request.RequestMeta;
import com.alibaba.nacos.api.remote.response.Response;

import java.util.Map;

/**
* connection interface,define basic operation.
*
* @author liuzunfei
* @version $Id: Requester.java, v 0.1 2020年09月11日 4:05 PM liuzunfei Exp $
*/
public interface Requester {

/**
* send request. default time out 3 seconds.
*
* @param request request.
* @param requestMeta requestMeta.
* @return response.
* @throws NacosException exception throw.
*/
public Response request(Request request, RequestMeta requestMeta) throws NacosException;

/**
* send request.
*
* @param request request.
* @param requestMeta requestMeta.
* @param timeoutMills mills of timeouts.
* @return response response returned.
* @throws NacosException exception throw.
*/
public Response request(Request request, RequestMeta requestMeta, long timeoutMills) throws NacosException;

/**
* send request.
*
* @param request request.
* @param requestMeta meta of request.
* @return request future.
* @throws NacosException exception throw.
*/
public RequestFuture requestFuture(Request request, RequestMeta requestMeta) throws NacosException;

/**
* send aync request. = * @param request request.
*
* @param requestMeta meta of request.
* @param requestCallBack callback of request.
* @throws NacosException exception throw.
*/
public void asyncRequest(Request request, RequestMeta requestMeta, RequestCallBack requestCallBack)
throws NacosException;

/**
* get connection labels.
*
* @return labels.
*/
public Map<String, String> getLabels();

/**
* close connection.
*/
public void close();
}
48 changes: 26 additions & 22 deletions client/src/test/java/com/alibaba/nacos/client/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public class ConfigTest {
@Before
public void before() throws Exception {
Properties properties = new Properties();
//properties.setProperty(PropertyKeyConst.SERVER_ADDR, "11.160..148:8848,127.0.0.1:8848,127.0.0.1:8848");
//properties.setProperty(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
properties.setProperty(PropertyKeyConst.SERVER_ADDR, "11.160.144.149:8848,11.160.144.148:8848,127.0.0.1:8848");
properties.setProperty(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
//properties.setProperty(PropertyKeyConst.SERVER_ADDR, "11.160.144.148:8848");
//properties.setProperty(PropertyKeyConst.SERVER_ADDR, "11.160.144.149:8848,11.160.144.148:8848,127.0.0.1:8848");
//"11.239.114.187:8848,,11.239.113.204:8848,11.239.112.161:8848");
//"11.239.114.187:8848");
configService = NacosFactory.createConfigService(properties);
Expand All @@ -66,8 +66,8 @@ public void before() throws Exception {
@Test
public void test222() throws Exception {
Map<String, String> labels = new HashMap<String, String>();
labels.put(RemoteConstants.LABEL_SOURCE, RemoteConstants.LABEL_SOURCE_NODE);

labels.put(RemoteConstants.LABEL_SOURCE, RemoteConstants.LABEL_SOURCE_CLUSTER);
RpcClient client = RpcClientFactory.createClient("1234", ConnectionType.RSOCKET, labels);
client.init(new ServerListFactory() {
@Override
Expand Down Expand Up @@ -181,21 +181,27 @@ public void cleanup() throws Exception {

@Test
public void test2() throws Exception {
final String dataId = "xiaochun.xxc";
final String group = "xiaochun.xxc";
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.SERVER_ADDR, "11.160.144.148:8848,11.160.144.149:8848");
properties.setProperty(PropertyKeyConst.SERVER_ADDR, "11.160.144.149:8848");
//"
List<ConfigService> configServiceList = new ArrayList<ConfigService>();
for (int i = 0; i < 300; i++) {

ConfigService configService = NacosFactory.createConfigService(properties);
configService.addListener("test", "test", new AbstractListener() {

Listener listener = new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println("listener2:" + configInfo);
System.out.println(
"receiveConfigInfo1 content:" + (System.currentTimeMillis() - Long.valueOf(configInfo)));

}
});
configServiceList.add(configService);
};

configService.addListener(dataId, group, listener);

System.out.println(configServiceList.size());
}
System.out.println("2");
Expand All @@ -208,13 +214,10 @@ public void run() {
int times = 10000;
while (times > 0) {
try {
System.out.println("3");

boolean result = configService
.publishConfig("test", "test", "value" + System.currentTimeMillis());

boolean result = configService.publishConfig(dataId, group, "" + System.currentTimeMillis());

times--;
Thread.sleep(3000L);
Thread.sleep(1000L);
} catch (Exception e) {
e.printStackTrace();

Expand All @@ -223,7 +226,7 @@ public void run() {
}

});
//th.start();
th.start();

Thread.sleep(1000000L);
}
Expand All @@ -244,12 +247,12 @@ public void run() {
int times = 1000;
while (times > 0) {
try {
String content1 = "value" + System.currentTimeMillis();
System.out.println("publish content:" + content1);
String content1 = System.currentTimeMillis() + "";
//System.out.println("publish content:" + content1);
configService.publishConfig(dataId, group, content1);

times--;
Thread.sleep(2000L);
Thread.sleep(1000L);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -266,8 +269,9 @@ public void run() {
Listener listener = new AbstractListener() {
@Override
public void receiveConfigInfo(String configInfo) {
System.out.println("receiveConfigInfo1 content:" + configInfo + "," + System.currentTimeMillis());

System.out.println(
"receiveConfigInfo1 content:" + (System.currentTimeMillis() - Long.valueOf(configInfo)));

}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface HttpHeaderConsts {
String ACCEPT_CHARSET = "Accept-Charset";
String ACCEPT_ENCODING = "Accept-Encoding";
String CONTENT_ENCODING = "Content-Encoding";
String CONNECTION = "Connection";
String CONNECTION = "Requester";
String REQUEST_ID = "RequestId";
String REQUEST_MODULE = "Request-Module";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@

package com.alibaba.nacos.common.remote.client;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.remote.RequestCallBack;
import com.alibaba.nacos.api.remote.RequestFuture;
import com.alibaba.nacos.api.remote.request.Request;
import com.alibaba.nacos.api.remote.request.RequestMeta;
import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.Requester;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -33,7 +28,7 @@
* @version $Id: Connection.java, v 0.1 2020年08月09日 1:32 PM liuzunfei Exp $
*/
@SuppressWarnings("PMD.AbstractClassShouldStartWithAbstractNamingRule")
public abstract class Connection {
public abstract class Connection implements Requester {

private boolean abandon = false;

Expand All @@ -45,18 +40,6 @@ public Connection(RpcClient.ServerInfo serverInfo) {
this.serverInfo = serverInfo;
}

public String getLabel(String labelKey) {
return labels.get(labelKey);
}

public void putLabel(String labelKey, String labelValue) {
labels.put(labelKey, labelValue);
}

public void putLabels(Map<String, String> labels) {
labels.putAll(labels);
}

/**
* Getter method for property <tt>abandon</tt>.
*
Expand All @@ -67,8 +50,7 @@ public boolean isAbandon() {
}

/**
* Setter method for property <tt>abandon</tt>.
* connection event will be ignored if connection is abandoned.
* Setter method for property <tt>abandon</tt>. connection event will be ignored if connection is abandoned.
*
* @param abandon value to be assigned to property abandon
*/
Expand All @@ -77,49 +59,28 @@ public void setAbandon(boolean abandon) {
}

/**
* send request.
* default time out 3 seconds.
* @param request request.
* @param requestMeta requestMeta.
* @return response.
* @throws NacosException exception throw.
*/
public abstract Response request(Request request, RequestMeta requestMeta) throws NacosException;

/**
* send request.
* Getter method for property <tt>labels</tt>.
*
* @param request request.
* @param requestMeta requestMeta.
* @param timeoutMills mills of timeouts.
* @return response response returned.
* @throws NacosException exception throw.
* @return property value of labels
*/
public abstract Response request(Request request, RequestMeta requestMeta, long timeoutMills) throws NacosException;
@Override
public Map<String, String> getLabels() {
return labels;
}

/**
* send request.
* Setter method for property <tt>labels</tt>.
*
* @param request request.
* @param requestMeta meta of request.
* @return request future.
* @throws NacosException exception throw.
*/
public abstract RequestFuture requestFuture(Request request, RequestMeta requestMeta) throws NacosException;

/**
* send aync request.
= * @param request request.
* @param requestMeta meta of request.
* @param requestCallBack callback of request.
* @throws NacosException exception throw.
* @param labels value to be assigned to property labels
*/
public abstract void asyncRequest(Request request, RequestMeta requestMeta, RequestCallBack requestCallBack)
throws NacosException;
public void putLabels(Map<String, String> labels) {
this.labels = labels;
}

/**
* close connection.
* Setter method for property <tt>labels</tt>.
*/
public abstract void close();

public void putLabel(String labelName, String labelValue) {
this.labels.put(labelName, labelValue);
}
}
Loading

0 comments on commit fac4879

Please sign in to comment.