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 phase7 #3288

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -19,7 +19,7 @@
import java.util.concurrent.atomic.AtomicLong;

/**
* Accumulate Stat Count
* Accumulate Stat Count.
*
* @author Nacos
*/
Expand All @@ -33,6 +33,11 @@ public long increase() {
return total.incrementAndGet();
}

/**
* accumulate stat.
*
* @return
*/
public long stat() {
long tmp = total.get() - lastStatValue;
lastStatValue += tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.io.File;

/**
* App util
* App util.
*
* @author Nacos
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.concurrent.TimeUnit;

/**
* Config executor.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public final class ConfigExecutor {
Expand All @@ -33,11 +35,11 @@ public final class ConfigExecutor {
.newFixedExecutorService(Config.class.getCanonicalName(), 1,
new NameThreadFactory("nacos.config.embedded.dump"));

private static ScheduledExecutorService TIMER_EXECUTOR = ExecutorFactory
private static final ScheduledExecutorService TIMER_EXECUTOR = ExecutorFactory
.newScheduledExecutorService(Config.class.getCanonicalName(), 10,
new NameThreadFactory("com.alibaba.nacos.server.Timer"));

static public void scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
public static void scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
TIMER_EXECUTOR.scheduleWithFixedDelay(command, initialDelay, delay, unit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@
import static com.alibaba.nacos.config.server.constant.Constants.WORD_SEPARATOR;

/**
* Content utils
* Content utils.
*
* @author Nacos
*/
public class ContentUtils {


/**
* verify the pub config content.
*
* @param content content
*/
public static void verifyIncrementPubContent(String content) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check indent in this file

if (content == null || content.length() == 0) {
throw new IllegalArgumentException("发布/删除内容不能为空");
}
Expand All @@ -42,23 +47,28 @@ public static void verifyIncrementPubContent(String content) {
}
}
}

public static String getContentIdentity(String content) {
int index = content.indexOf(WORD_SEPARATOR);
if (index == -1) {
throw new IllegalArgumentException("内容没有包含分隔符");
}
return content.substring(0, index);
}

public static String getContent(String content) {
int index = content.indexOf(WORD_SEPARATOR);
if (index == -1) {
throw new IllegalArgumentException("内容没有包含分隔符");
}
return content.substring(index + 1);
}


/**
* Truncate the content.
* @param content content
* @return
*/
public static String truncateContent(String content) {
if (content == null) {
return "";
Expand All @@ -68,6 +78,6 @@ public static String truncateContent(String content) {
return content.substring(0, 100) + "...";
}
}
private final static int LIMIT_CONTENT_SIZE = 100;

private static final int LIMIT_CONTENT_SIZE = 100;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.regex.Pattern;

/**
* Derby util.
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public final class DerbyUtils {
Expand All @@ -30,7 +32,7 @@ public final class DerbyUtils {

/**
* Because Derby's database table name is uppercase, you need to do a conversion to the insert statement that was
* inserted
* inserted.
*
* @param sql external database insert sql
* @return derby insert sql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,17 @@
import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
* 磁盘操作工具类。
* <p>
* 只有一个dump线程。
* Disk util.
*
* @author jiuRen
*/
Expand All @@ -52,64 +47,64 @@ public class DiskUtil {

static final String TENANT_TAG_DIR = File.separator + "data" + File.separator + "tag-beta-data";

static public void saveHeartBeatToDisk(String heartBeatTime) throws IOException {
public static void saveHeartBeatToDisk(String heartBeatTime) throws IOException {
FileUtils.writeStringToFile(heartBeatFile(), heartBeatTime, Constants.ENCODE);
}

/**
* 保存配置信息到磁盘
* Save configuration information to disk.
*/
static public void saveToDisk(String dataId, String group, String tenant, String content) throws IOException {
public static void saveToDisk(String dataId, String group, String tenant, String content) throws IOException {
File targetFile = targetFile(dataId, group, tenant);
FileUtils.writeStringToFile(targetFile, content, Constants.ENCODE);
}

/**
* 保存配置信息到磁盘
* Save beta information to disk.
*/
static public void saveBetaToDisk(String dataId, String group, String tenant, String content) throws IOException {
public static void saveBetaToDisk(String dataId, String group, String tenant, String content) throws IOException {
File targetFile = targetBetaFile(dataId, group, tenant);
FileUtils.writeStringToFile(targetFile, content, Constants.ENCODE);
}

/**
* 保存配置信息到磁盘
* Save tag information to disk.
*/
static public void saveTagToDisk(String dataId, String group, String tenant, String tag, String content)
public static void saveTagToDisk(String dataId, String group, String tenant, String tag, String content)
throws IOException {
File targetFile = targetTagFile(dataId, group, tenant, tag);
FileUtils.writeStringToFile(targetFile, content, Constants.ENCODE);
}

/**
* 删除磁盘上的配置文件
* Deletes configuration files on disk.
*/
static public void removeConfigInfo(String dataId, String group, String tenant) {
public static void removeConfigInfo(String dataId, String group, String tenant) {
FileUtils.deleteQuietly(targetFile(dataId, group, tenant));
}

/**
* 删除磁盘上的配置文件
* Deletes beta configuration files on disk.
*/
static public void removeConfigInfo4Beta(String dataId, String group, String tenant) {
public static void removeConfigInfo4Beta(String dataId, String group, String tenant) {
FileUtils.deleteQuietly(targetBetaFile(dataId, group, tenant));
}

/**
* 删除磁盘上的配置文件
* Deletes tag configuration files on disk.
*/
static public void removeConfigInfo4Tag(String dataId, String group, String tenant, String tag) {
public static void removeConfigInfo4Tag(String dataId, String group, String tenant, String tag) {
FileUtils.deleteQuietly(targetTagFile(dataId, group, tenant, tag));
}

static public void removeHeartHeat() {
public static void removeHeartHeat() {
FileUtils.deleteQuietly(heartBeatFile());
}

/**
* 返回服务端缓存文件的路径
* Returns the path of the server cache file.
*/
static public File targetFile(String dataId, String group, String tenant) {
public static File targetFile(String dataId, String group, String tenant) {
File file = null;
if (StringUtils.isBlank(tenant)) {
file = new File(ApplicationUtils.getNacosHome(), BASE_DIR);
Expand All @@ -123,9 +118,9 @@ static public File targetFile(String dataId, String group, String tenant) {
}

/**
* 返回服务端beta缓存文件的路径
* Returns the path of cache file in server.
*/
static public File targetBetaFile(String dataId, String group, String tenant) {
public static File targetBetaFile(String dataId, String group, String tenant) {
File file = null;
if (StringUtils.isBlank(tenant)) {
file = new File(ApplicationUtils.getNacosHome(), BETA_DIR);
Expand All @@ -139,9 +134,9 @@ static public File targetBetaFile(String dataId, String group, String tenant) {
}

/**
* 返回服务端Tag缓存文件的路径
* Returns the path of the tag cache file in server.
*/
static public File targetTagFile(String dataId, String group, String tenant, String tag) {
public static File targetTagFile(String dataId, String group, String tenant, String tag) {
File file = null;
if (StringUtils.isBlank(tenant)) {
file = new File(ApplicationUtils.getNacosHome(), TAG_DIR);
Expand All @@ -155,7 +150,7 @@ static public File targetTagFile(String dataId, String group, String tenant, Str
return file;
}

static public String getConfig(String dataId, String group, String tenant) throws IOException {
public static String getConfig(String dataId, String group, String tenant) throws IOException {
File file = targetFile(dataId, group, tenant);
if (file.exists()) {

Expand All @@ -169,19 +164,22 @@ static public String getConfig(String dataId, String group, String tenant) throw
}
}

static public String getLocalConfigMd5(String dataId, String group, String tenant) throws IOException {
public static String getLocalConfigMd5(String dataId, String group, String tenant) throws IOException {
return MD5Utils.md5Hex(getConfig(dataId, group, tenant), Constants.ENCODE);
}

static public File heartBeatFile() {
public static File heartBeatFile() {
return new File(ApplicationUtils.getNacosHome(), "status" + File.separator + "heartBeat.txt");
}

static public String relativePath(String dataId, String group) {
public static String relativePath(String dataId, String group) {
return BASE_DIR + "/" + dataId + "/" + group;
}

static public void clearAll() {
/**
* Clear all config file.
*/
public static void clearAll() {
File file = new File(ApplicationUtils.getNacosHome(), BASE_DIR);
if (FileUtils.deleteQuietly(file)) {
LogUtil.defaultLog.info("clear all config-info success.");
Expand All @@ -196,7 +194,10 @@ static public void clearAll() {
}
}

static public void clearAllBeta() {
/**
* Clear all beta config file.
*/
public static void clearAllBeta() {
File file = new File(ApplicationUtils.getNacosHome(), BETA_DIR);
if (FileUtils.deleteQuietly(file)) {
LogUtil.defaultLog.info("clear all config-info-beta success.");
Expand All @@ -211,7 +212,10 @@ static public void clearAllBeta() {
}
}

static public void clearAllTag() {
/**
* Clear all tag config file.
*/
public static void clearAllTag() {
File file = new File(ApplicationUtils.getNacosHome(), TAG_DIR);
if (FileUtils.deleteQuietly(file)) {
LogUtil.defaultLog.info("clear all config-info-tag success.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.apache.commons.lang3.StringUtils;

/**
* 合成dataId+groupId的形式。对dataId和groupId中的保留字符做转义。
* Synthesize dataId+groupId form. Escape reserved characters in dataId and groupId.
*
* @author jiuRen
*/
Expand All @@ -29,14 +29,14 @@ public static String getKey(String dataId, String group) {
return doGetKey(dataId, group, "");
}

public static String getKeyTenant(String dataId, String group, String tenant) {
return doGetKey(dataId, group, tenant);
}

public static String getKey(String dataId, String group, String datumStr) {
return doGetKey(dataId, group, datumStr);
}

public static String getKeyTenant(String dataId, String group, String tenant) {
return doGetKey(dataId, group, tenant);
}

private static String doGetKey(String dataId, String group, String datumStr) {
StringBuilder sb = new StringBuilder();
urlEncode(dataId, sb);
Expand All @@ -50,6 +50,9 @@ private static String doGetKey(String dataId, String group, String datumStr) {
return sb.toString();
}

/**
* Parse the group key.
*/
public static String[] parseKey(String groupKey) {
StringBuilder sb = new StringBuilder();
String dataId = null;
Expand Down Expand Up @@ -99,7 +102,7 @@ public static String[] parseKey(String groupKey) {
}

/**
* + -> %2B % -> %25
* + -> %2B % -> %25.
*/
static void urlEncode(String str, StringBuilder sb) {
for (int idx = 0; idx < str.length(); ++idx) {
Expand Down
Loading