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

response model optimize #3357

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


/**
* ConfigChangeListenRequest.
* @author liuzunfei
* @version $Id: ConfigChangeListenRequest.java, v 0.1 2020年07月13日 9:01 PM liuzunfei Exp $
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.alibaba.nacos.api.config.remote.response;

import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.response.ResponseCode;

/**
* ConfigChangeListenResponse.
Expand All @@ -26,13 +27,37 @@
*/
public class ConfigChangeListenResponse extends Response {


public ConfigChangeListenResponse() {
super();
}

public ConfigChangeListenResponse(int resultCode, String message) {
super(ConfigResponseTypeConstants.CONFIG_CHANGE, resultCode, message);
@Override
public String getType() {
return ConfigResponseTypeConstants.CONFIG_CHANGE;
}

/**
* build sucess response.
*
* @return
*/
public static ConfigChangeListenResponse buildSucessResponse() {
ConfigChangeListenResponse response = new ConfigChangeListenResponse();
response.setResultCode(ResponseCode.SUCCESS.getCode());
return response;
}

/**
* build fail response.
*
* @param errorMessage errorMessage.
* @return
*/
public static ConfigChangeListenResponse buildFailResponse(String errorMessage) {
ConfigChangeListenResponse response = new ConfigChangeListenResponse();
response.setResultCode(ResponseCode.FAIL.getCode());
response.setMessage(errorMessage);
return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.api.config.remote.response;

import com.alibaba.nacos.api.remote.response.Response;
Expand All @@ -25,17 +26,18 @@
public class ConfigChangeNotifyResponse extends Response {

private String dataId;

private String group;

private String tenant;

public ConfigChangeNotifyResponse() {

}

public ConfigChangeNotifyResponse(int resultCode, String message) {
super(ConfigResponseTypeConstants.CONFIG_CHANGE_NOTIFY, resultCode, message);
@Override
public String getType() {
return ConfigResponseTypeConstants.CONFIG_CHANGE_NOTIFY;
}

/**
Expand All @@ -47,8 +49,7 @@ public ConfigChangeNotifyResponse(int resultCode, String message) {
* @return ConfigChangeNotifyResponse
*/
public static ConfigChangeNotifyResponse buildSuccessResponse(String dataId, String group, String tenant) {
ConfigChangeNotifyResponse response = new ConfigChangeNotifyResponse(ResponseCode.SUCCESS.getCode(),
"data changed");
ConfigChangeNotifyResponse response = new ConfigChangeNotifyResponse();
response.setDataId(dataId);
response.setGroup(group);
response.setTenant(tenant);
Expand All @@ -63,7 +64,7 @@ public static ConfigChangeNotifyResponse buildSuccessResponse(String dataId, Str
public String getDataId() {
return dataId;
}

/**
* Setter method for property <tt>dataId</tt>.
*
Expand All @@ -72,7 +73,7 @@ public String getDataId() {
public void setDataId(String dataId) {
this.dataId = dataId;
}

/**
* Getter method for property <tt>group</tt>.
*
Expand All @@ -81,7 +82,7 @@ public void setDataId(String dataId) {
public String getGroup() {
return group;
}

/**
* Setter method for property <tt>group</tt>.
*
Expand All @@ -90,7 +91,7 @@ public String getGroup() {
public void setGroup(String group) {
this.group = group;
}

/**
* Getter method for property <tt>tenant</tt>.
*
Expand All @@ -99,7 +100,7 @@ public void setGroup(String group) {
public String getTenant() {
return tenant;
}

/**
* Setter method for property <tt>tenant</tt>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public ConfigPubishResponse() {
super();
}

public ConfigPubishResponse(int resultCode, String message) {
super(ConfigResponseTypeConstants.CONFIG_PUBLISH, resultCode, message);
@Override
public String getType() {
return ConfigResponseTypeConstants.CONFIG_PUBLISH;
}

/**
Expand All @@ -41,7 +42,7 @@ public ConfigPubishResponse(int resultCode, String message) {
* @return
*/
public static ConfigPubishResponse buildSuccessResponse() {
return new ConfigPubishResponse(ResponseCode.SUCCESS.getCode(), "");
return new ConfigPubishResponse();
}

/**
Expand All @@ -50,6 +51,9 @@ public static ConfigPubishResponse buildSuccessResponse() {
* @return
*/
public static ConfigPubishResponse buildFailResponse(String errorMsg) {
return new ConfigPubishResponse(ResponseCode.FAIL.getCode(), errorMsg);
ConfigPubishResponse configPubishResponse = new ConfigPubishResponse();
configPubishResponse.setResultCode(ResponseCode.FAIL.getCode());
configPubishResponse.setMessage(errorMsg);
return configPubishResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ public class ConfigQueryResponse extends Response {
Map<String, String> labels = new HashMap<String, String>();

public ConfigQueryResponse() {
super(ConfigResponseTypeConstants.CONFIG_QUERY);
}

@Override
public String getType() {
return ConfigResponseTypeConstants.CONFIG_QUERY;
}

/**
* add label to this response.
*
* @param key
* @param value
* @param key key.
* @param value value.
*/
public void addLabel(String key, String value) {
this.labels.put(key, value);
Expand All @@ -62,19 +66,21 @@ public void addLabel(String key, String value) {
* @return
*/
public static ConfigQueryResponse buildFailResponse(int errorCode, String message) {
ConfigQueryResponse response = new ConfigQueryResponse(ResponseCode.FAIL.getCode(), message);
ConfigQueryResponse response = new ConfigQueryResponse();
response.setResultCode(ResponseCode.FAIL.getCode());
response.setErrorCode(errorCode);
response.setMessage(message);
return response;
}

/**
* Buidl success resposne.
*
* @param content.
* @param content content.
* @return
*/
public static ConfigQueryResponse buildSuccessResponse(String content) {
ConfigQueryResponse response = new ConfigQueryResponse(ResponseCode.SUCCESS.getCode(), "");
ConfigQueryResponse response = new ConfigQueryResponse();
response.setContent(content);
return response;
}
Expand Down Expand Up @@ -115,10 +121,6 @@ public void setContent(String content) {
this.content = content;
}

public ConfigQueryResponse(int resultCode, String message) {
super(ConfigResponseTypeConstants.CONFIG_QUERY, resultCode, message);
}

/**
* Getter method for property <tt>contentType</tt>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public ConfigRemoveResponse() {
super();
}

public ConfigRemoveResponse(int resultCode, String message) {
super(ConfigResponseTypeConstants.CONFIG_REMOVE, resultCode, message);
@Override
public String getType() {
return ConfigResponseTypeConstants.CONFIG_REMOVE;
}

/**
Expand All @@ -41,7 +42,7 @@ public ConfigRemoveResponse(int resultCode, String message) {
* @return
*/
public static ConfigRemoveResponse buildSuccessResponse() {
return new ConfigRemoveResponse(ResponseCode.SUCCESS.getCode(), "");
return new ConfigRemoveResponse();
}

/**
Expand All @@ -50,6 +51,9 @@ public static ConfigRemoveResponse buildSuccessResponse() {
* @return
*/
public static ConfigRemoveResponse buildFailResponse(String errorMsg) {
return new ConfigRemoveResponse(ResponseCode.FAIL.getCode(), errorMsg);
ConfigRemoveResponse removeResponse = new ConfigRemoveResponse();
removeResponse.setResultCode(ResponseCode.FAIL.getCode());
removeResponse.setMessage(errorMsg);
return removeResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
*/
public class InstanceResponse extends Response {

private String type;

public InstanceResponse() {
}

public InstanceResponse(int resultCode, String message, String type) {
this(resultCode, 0, message, type);
@Override
public String getType() {
return this.type;
}

public InstanceResponse(int resultCode, int errorCode, String message, String type) {
super(type, resultCode, message);
setErrorCode(errorCode);
public InstanceResponse(String type) {
this.type = type;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.alibaba.nacos.api.naming.remote.NamingRemoteConstants;
import com.alibaba.nacos.api.remote.response.Response;
import com.alibaba.nacos.api.remote.response.ResponseCode;

/**
* Nacos naming query request.
Expand All @@ -30,16 +31,28 @@ public class ServiceQueryResponse extends Response {
private ServiceInfo serviceInfo;

public ServiceQueryResponse() {
setType(NamingRemoteConstants.QUERY_SERVICE);
}

@Override
public String getType() {
return NamingRemoteConstants.QUERY_SERVICE;
}

public ServiceQueryResponse(ServiceInfo serviceInfo) {
this(200, "success");
this.serviceInfo = serviceInfo;
}

public ServiceQueryResponse(int resultCode, String message) {
super(NamingRemoteConstants.QUERY_SERVICE, resultCode, message);
public static ServiceQueryResponse buildSuccessResponse(ServiceInfo serviceInfo) {
ServiceQueryResponse serviceQueryResponse = new ServiceQueryResponse();
serviceQueryResponse.setServiceInfo(serviceInfo);
return serviceQueryResponse;
}

public static ServiceQueryResponse buildFailResponse(String message) {
ServiceQueryResponse serviceQueryResponse = new ServiceQueryResponse();
serviceQueryResponse.setResultCode(ResponseCode.FAIL.getCode());
serviceQueryResponse.setMessage(message);
return serviceQueryResponse;
}

public ServiceInfo getServiceInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.alibaba.nacos.api.remote.response.ConnectResetResponse;
import com.alibaba.nacos.api.remote.response.HeartBeatResponse;
import com.alibaba.nacos.api.remote.response.ResponseTypeConstants;
import com.alibaba.nacos.api.remote.response.UnKnowResponse;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -47,6 +48,7 @@ public class ResponseRegistry {
//internal response regitry
REGISTRY_RESPONSES.put(ResponseTypeConstants.HEART_BEAT, HeartBeatResponse.class);
REGISTRY_RESPONSES.put(ResponseTypeConstants.CONNECT_SWITCH, ConnectResetResponse.class);
REGISTRY_RESPONSES.put(ResponseTypeConstants.UNKNOW, UnKnowResponse.class);

//config response registry
REGISTRY_RESPONSES.put(ConfigResponseTypeConstants.CONFIG_CHANGE, ConfigChangeListenResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
*/
public class ConnectResetResponse extends Response {

public ConnectResetResponse(int resultCode, String message) {
super(ResponseTypeConstants.CONNECT_SWITCH, resultCode, message);
@Override
public String getType() {
return ResponseTypeConstants.CONNECT_SWITCH;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
*/
public class HeartBeatResponse extends Response {

public HeartBeatResponse(int resultCode, String message) {
super(ResponseTypeConstants.HEART_BEAT, resultCode, message);
@Override
public String getType() {
return ResponseTypeConstants.HEART_BEAT;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public PlainBodyResponse() {

}

public PlainBodyResponse(int resultCode, String message) {
super(ResponseTypeConstants.PLAIN_BODY_STRING, resultCode, message);
@Override
public String getType() {
return ResponseTypeConstants.PLAIN_BODY_STRING;
}

/**
Expand Down
Loading