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

Resolve the issues of codestyle of nacos-config module for phase5. #3272

Merged
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 @@ -16,21 +16,16 @@

package com.alibaba.nacos.config.server.monitor;

import com.alibaba.nacos.config.server.service.ClientTrackService;
import com.alibaba.nacos.config.server.service.ConfigCacheService;
import com.alibaba.nacos.config.server.service.notify.AsyncNotifyService;
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;

/**
* Memory monitor
* Memory monitor.
*
* @author Nacos
*/
Expand All @@ -57,41 +52,4 @@ public void clear() {
MetricsMonitor.getConfigMonitor().set(0);
MetricsMonitor.getPublishMonitor().set(0);
}
}

class PrintGetConfigResponeTask implements Runnable {

@Override
public void run() {
memoryLog.info(ResponseMonitor.getStringForPrint());
}
}

class PrintMemoryTask implements Runnable {

@Override
public void run() {
int groupCount = ConfigCacheService.groupCount();
int subClientCount = ClientTrackService.subscribeClientCount();
long subCount = ClientTrackService.subscriberCount();
memoryLog.info("groupCount={}, subscriberClientCount={}, subscriberCount={}", groupCount, subClientCount,
subCount);
MetricsMonitor.getConfigCountMonitor().set(groupCount);
}
}

class NotifyTaskQueueMonitorTask implements Runnable {

final private AsyncNotifyService notifySingleService;

NotifyTaskQueueMonitorTask(AsyncNotifyService notifySingleService) {
this.notifySingleService = notifySingleService;
}

@Override
public void run() {
int size = ((ScheduledThreadPoolExecutor) notifySingleService.getExecutor()).getQueue().size();
memoryLog.info("toNotifyTaskSize={}", size);
MetricsMonitor.getNotifyTaskMonitor().set(size);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

package com.alibaba.nacos.config.server.monitor;

import io.micrometer.core.instrument.*;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.ImmutableTag;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Timer;
import io.micrometer.core.instrument.Counter;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
* Metrics Monitor
* Metrics Monitor.
*
* @author Nacos
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 1999-2018 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.config.server.monitor;

import com.alibaba.nacos.config.server.service.notify.AsyncNotifyService;

import java.util.concurrent.ScheduledThreadPoolExecutor;

import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;

/**
* NotifyTaskQueueMonitorTask.
*
* @author zongtanghu
*/
public class NotifyTaskQueueMonitorTask implements Runnable {

private final AsyncNotifyService notifySingleService;

NotifyTaskQueueMonitorTask(AsyncNotifyService notifySingleService) {
this.notifySingleService = notifySingleService;
}

@Override
public void run() {
int size = ((ScheduledThreadPoolExecutor) notifySingleService.getExecutor()).getQueue().size();
memoryLog.info("toNotifyTaskSize = {}", size);
MetricsMonitor.getNotifyTaskMonitor().set(size);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 1999-2018 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.config.server.monitor;

import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;

/**
* PrintGetConfigResponeTask.
*
* @author zongtanghu
*/
public class PrintGetConfigResponeTask implements Runnable {
@Override
public void run() {
memoryLog.info(ResponseMonitor.getStringForPrint());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 1999-2018 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.config.server.monitor;

import com.alibaba.nacos.config.server.service.ClientTrackService;
import com.alibaba.nacos.config.server.service.ConfigCacheService;

import static com.alibaba.nacos.config.server.utils.LogUtil.memoryLog;

/**
* @author zongtanghu
*/
public class PrintMemoryTask implements Runnable {

@Override
public void run() {
int groupCount = ConfigCacheService.groupCount();
int subClientCount = ClientTrackService.subscribeClientCount();
long subCount = ClientTrackService.subscriberCount();
memoryLog.info("groupCount = {}, subscriberClientCount = {}, subscriberCount = {}", groupCount, subClientCount,
subCount);
MetricsMonitor.getConfigCountMonitor().set(groupCount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.concurrent.atomic.AtomicLong;

/**
* Response Monitory
* Response Monitory.
*
* @author Nacos
*/
Expand Down Expand Up @@ -48,12 +48,20 @@ public class ResponseMonitor {
refresh();
}

/**
* Refresh for getting configCountDetail.
*/
public static void refresh() {
for (int i = 0; i < getConfigCountDetail.length; i++) {
getConfigCountDetail[i] = new AtomicLong();
}
}

/**
* AddConfigTime.
*
* @param time config time which is added.
*/
public static void addConfigTime(long time) {
getConfigCount.incrementAndGet();
if (time < MS_50) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@
import org.springframework.util.Assert;

/**
* ResultBuilder.
*
* @author klw
* @ClassName: ResultBuilder
* @Description: util for generating {@link RestResult}
* @date 2019/6/28 14:47
*/
public class ResultBuilder {

/**
* BuildResult.
*
* @param resultCode resultCode.
* @param resultData resultData.
* @param <T> T.
* @return RestResult.
*/
public static <T extends Object> RestResult<T> buildResult(IResultCode resultCode, T resultData) {
Assert.notNull(resultCode, "the resultCode can not be null");
RestResult<T> rr = new RestResult<>(resultCode.getCode(), resultCode.getCodeMsg(), resultData);
Expand All @@ -39,6 +49,14 @@ public static <T extends Object> RestResult<T> buildSuccessResult(T resultData)
return buildResult(ResultCodeEnum.SUCCESS, resultData);
}

/**
* BuildSuccessResult.
*
* @param successMsg successMsg string value.
* @param resultData resultData.
* @param <T> T.
* @return RestResult.
*/
public static <T extends Object> RestResult<T> buildSuccessResult(String successMsg, T resultData) {
RestResult<T> rr = buildResult(ResultCodeEnum.SUCCESS, resultData);
rr.setMessage(successMsg);
Expand All @@ -49,6 +67,13 @@ public static <T extends Object> RestResult<T> buildSuccessResult() {
return buildResult(ResultCodeEnum.SUCCESS, null);
}

/**
* BuildSuccessResult.
*
* @param successMsg successMsg string value.
* @param <T> T.
* @return RestResult.
*/
public static <T extends Object> RestResult<T> buildSuccessResult(String successMsg) {
RestResult<T> rr = buildResult(ResultCodeEnum.SUCCESS, null);
rr.setMessage(successMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.alibaba.nacos.config.server.result.core.IResultCode;

/**
* ResultCodeEnum.
*
* @author klw
* @ClassName: ResultCodeEnum
* @Description: result code enum
Expand All @@ -27,13 +29,13 @@
public enum ResultCodeEnum implements IResultCode {

/**
* common code
* Common code.
**/
SUCCESS(200, "处理成功"),
ERROR(500, "服务器内部错误"),

/**
* config use 100001 ~ 100999
* Config use 100001 ~ 100999.
**/
NAMESPACE_NOT_EXIST(100001, "目标 namespace 不存在"),

Expand All @@ -45,9 +47,7 @@ public enum ResultCodeEnum implements IResultCode {

DATA_EMPTY(100005, "导入的文件数据为空"),

NO_SELECTED_CONFIG(100006, "没有选择任何配制"),

;
NO_SELECTED_CONFIG(100006, "没有选择任何配制");

private int code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.alibaba.nacos.config.server.result.core;

/**
* IResultCode.
*
* @author klw
* @ClassName: IResultCode
* @Description: result code enum needs to be implemented this interface
Expand All @@ -25,22 +27,16 @@
public interface IResultCode {

/**
* get the result code
* Get the result code.
*
* @return java.lang.String
* @author klw
* @Date 2019/6/28 14:56
* @Param []
* @return code value.
*/
int getCode();

/**
* get the result code's message
* Get the result code's message.
*
* @return java.lang.String
* @author klw
* @Date 2019/6/28 14:56
* @Param []
* @return code's message.
*/
String getCodeMsg();
}
Loading