Skip to content

Commit

Permalink
optimize NotifySubscriberRequest (alibaba#7545)
Browse files Browse the repository at this point in the history
  • Loading branch information
hujun-w-2 authored Jan 7, 2022
1 parent fb43bad commit cdd83e2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.alibaba.nacos.api.common.Constants.Naming.NAMING_MODULE;

/**
* Notify subscriber response.
* Notify subscriber request.
*
* @author xiweng.yy
*/
Expand All @@ -44,22 +44,12 @@ public String getModule() {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testRequestReply() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public PushExecutorRpcImpl(RpcPushService pushService) {

@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());
}

Expand Down

0 comments on commit cdd83e2

Please sign in to comment.