optimize NotifySubscriberRequest (#7545)

This commit is contained in:
胡俊 2022-01-07 18:08:22 +08:00 committed by GitHub
parent fb43badea1
commit cdd83e2117
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 17 deletions

View File

@ -22,7 +22,7 @@ import com.alibaba.nacos.api.remote.request.ServerRequest;
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;
/**
* Notify subscriber response.
* Notify subscriber request.
*
* @author xiweng.yy
*/
@ -44,22 +44,12 @@ public class NotifySubscriberRequest extends ServerRequest {
return NAMING_MODULE;
}
private NotifySubscriberRequest(ServiceInfo serviceInfo, String message) {
private NotifySubscriberRequest(ServiceInfo serviceInfo) {
this.serviceInfo = serviceInfo;
}
public static NotifySubscriberRequest buildSuccessResponse(ServiceInfo serviceInfo) {
return new NotifySubscriberRequest(serviceInfo, "success");
}
/**
* Build fail response.
*
* @param message error message
* @return fail response
*/
public static NotifySubscriberRequest buildFailResponse(String message) {
return new NotifySubscriberRequest();
public static NotifySubscriberRequest buildNotifySubscriberRequest(ServiceInfo serviceInfo) {
return new NotifySubscriberRequest(serviceInfo);
}
public ServiceInfo getServiceInfo() {

View File

@ -39,7 +39,7 @@ public class NamingPushRequestHandlerTest {
ServiceInfoHolder holder = mock(ServiceInfoHolder.class);
NamingPushRequestHandler handler = new NamingPushRequestHandler(holder);
ServiceInfo info = new ServiceInfo("name", "cluster1");
Request req = NotifySubscriberRequest.buildSuccessResponse(info);
Request req = NotifySubscriberRequest.buildNotifySubscriberRequest(info);
//when
Response response = handler.requestReply(req);
//then

View File

@ -42,12 +42,12 @@ public class PushExecutorRpcImpl implements PushExecutor {
@Override
public void doPush(String clientId, Subscriber subscriber, PushDataWrapper data) {
pushService.pushWithoutAck(clientId, NotifySubscriberRequest.buildSuccessResponse(getServiceInfo(data, subscriber)));
pushService.pushWithoutAck(clientId, NotifySubscriberRequest.buildNotifySubscriberRequest(getServiceInfo(data, subscriber)));
}
@Override
public void doPushWithCallback(String clientId, Subscriber subscriber, PushDataWrapper data, PushCallBack callBack) {
pushService.pushWithCallback(clientId, NotifySubscriberRequest.buildSuccessResponse(getServiceInfo(data, subscriber)),
pushService.pushWithCallback(clientId, NotifySubscriberRequest.buildNotifySubscriberRequest(getServiceInfo(data, subscriber)),
callBack, GlobalExecutor.getCallbackExecutor());
}