格式化

This commit is contained in:
redkale
2024-09-07 09:29:11 +08:00
parent 21b9239c8d
commit ea01415b5f
21 changed files with 119 additions and 69 deletions

View File

@@ -42,7 +42,8 @@ public final class ApiDocCommand {
private static final java.lang.reflect.Type TYPE_RETRESULT_LONG = new TypeToken<RetResult<Long>>() {}.getType();
private final Application app; // Application全局对象
// Application全局对象
private final Application app;
public ApiDocCommand(Application app) {
this.app = app;

View File

@@ -43,27 +43,38 @@ public final class ClassFilter<T> {
private Predicate<String> expectPredicate;
private boolean refused; // 是否拒绝所有数据,设置true则其他规则失效,都是拒绝.
// 是否拒绝所有数据,设置true则其他规则失效,都是拒绝.
private boolean refused;
private Class superClass; // 符合的父类型。不为空时扫描结果的class必须是superClass的子类
// 符合的父类型。不为空时扫描结果的class必须是superClass的子类
private Class superClass;
private Class[] excludeSuperClasses; // 不符合的父类型。
// 不符合的父类型。
private Class[] excludeSuperClasses;
private Class<? extends Annotation> annotationClass; // 符合的注解。不为空时扫描结果的class必须包含该注解
// 符合的注解。不为空时扫描结果的class必须包含该注解
private Class<? extends Annotation> annotationClass;
private Pattern[] includePatterns; // 符合的className正则表达式
// 符合的className正则表达式
private Pattern[] includePatterns;
private Pattern[] excludePatterns; // 拒绝的className正则表达式
// 拒绝的className正则表达式
private Pattern[] excludePatterns;
private Set<String> privilegeIncludes; // 特批符合条件的className
// 特批符合条件的className
private Set<String> privilegeIncludes;
private Set<String> privilegeExcludes; // 特批拒绝条件的className
// 特批拒绝条件的className
private Set<String> privilegeExcludes;
private List<ClassFilter> ors; // 或关系的其他ClassFilter
// 或关系的其他ClassFilter
private List<ClassFilter> ors;
private List<ClassFilter> ands; // 与关系的其他ClassFilter
// 与关系的其他ClassFilter
private List<ClassFilter> ands;
private AnyValue conf; // 基本配置信息, 当符合条件时将conf的属性赋值到FilterEntry中去。
// 基本配置信息, 当符合条件时将conf的属性赋值到FilterEntry中去。
private AnyValue conf;
private final ClassLoader classLoader;

View File

@@ -28,7 +28,8 @@ public abstract class LoggingBaseHandler extends Handler {
public static final String FORMATTER_FORMAT3 =
"[%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%tL] [%7$s] %8$s %4$s %2$s\r\n%5$s%6$s\r\n";
static boolean traceEnable = false; // 防止设置system.property前调用Traces类导致enable提前初始化
// 防止设置system.property前调用Traces类导致enable提前初始化
static boolean traceEnable = false;
/** 默认的日志时间格式化类 与SimpleFormatter的区别在于level不使用本地化 */
public static class LoggingFormater extends Formatter {

View File

@@ -73,19 +73,24 @@ public class LoggingFileHandler extends LoggingBaseHandler {
protected String pattern;
protected String patternDateFormat; // 需要时间格式化
// 需要时间格式化
protected String patternDateFormat;
protected String unusual; // 不为null表示将 WARNING、SEVERE 级别的日志写入单独的文件中
// 不为null表示将 WARNING、SEVERE 级别的日志写入单独的文件中
protected String unusual;
protected String unusualDateFormat; // 需要时间格式化
// 需要时间格式化
protected String unusualDateFormat;
private int limit; // 文件大小限制
// 文件大小限制
private int limit;
private final AtomicInteger logIndex = new AtomicInteger();
private final AtomicInteger logUnusualIndex = new AtomicInteger();
private int count = 1; // 文件限制
// 文件限制
private int count = 1;
private long tomorrow;

View File

@@ -34,9 +34,11 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
protected final AtomicInteger retryCount = new AtomicInteger(3);
protected String tag = DEFAULT_TABLE_NAME; // 用于表前缀, 默认是
// 用于表前缀, 默认是
protected String tag = DEFAULT_TABLE_NAME;
protected String tagDateFormat; // 需要时间格式化
// 需要时间格式化
protected String tagDateFormat;
protected String pattern;

View File

@@ -34,7 +34,8 @@ import org.redkale.watch.*;
@NodeProtocol("HTTP")
public class NodeHttpServer extends NodeServer {
protected final boolean rest; // 是否加载REST服务 为true加载rest节点信息并将所有可REST化的Service生成RestServlet
// 是否加载REST服务 为true加载rest节点信息并将所有可REST化的Service生成RestServlet
protected final boolean rest;
protected final HttpServer httpServer;

View File

@@ -22,17 +22,22 @@ import org.redkale.util.Attribute;
@SuppressWarnings("unchecked")
public final class DeMember<R extends Reader, T, F> {
final Field field; // 对应类成员的Field 也可能为null
// 对应类成员的Field 也可能为null
final Field field;
final Method method; // 对应类成员的Method也可能为null
// 对应类成员的Method也可能为null
final Method method;
final String comment;
protected int index; // 从1开始
// 从1开始
protected int index;
protected int position; // 从1开始
// 从1开始
protected int position;
protected int tag; // 主要给protobuf使用 从1开始
// 主要给protobuf使用 从1开始
protected int tag;
protected final Attribute<T, F> attribute;
@@ -42,7 +47,6 @@ public final class DeMember<R extends Reader, T, F> {
this.attribute = attribute;
this.tag = tag;
this.index = tag;
this.position = position;
this.decoder = decoder;
this.comment = "";
this.field = null;

View File

@@ -38,17 +38,23 @@ public final class EnMember<W extends Writer, T, F> {
final byte[] jsonFieldNameBytes;
final Field field; // 对应类成员的Field也可能为null
// 对应类成员的Field也可能为null
final Field field;
final Method method; // 对应类成员的Method也可能为null
// 对应类成员的Method也可能为null
final Method method;
final BiFunction<String, Object, Object> fieldFunc; // 一般为null
// 一般为null
final BiFunction<String, Object, Object> fieldFunc;
int index; // 从1开始
// 从1开始
int index;
int position; // 从1开始
// 从1开始
int position;
int tag; // 主要给protobuf使用 从1开始
// 主要给protobuf使用 从1开始
int tag;
public EnMember(Attribute<T, F> attribute, int tag, Encodeable<W, F> encoder) {
this.attribute = attribute;

View File

@@ -29,7 +29,8 @@ public abstract class Reader {
public static final short SIGN_NOLENGTH = -2;
public static final short SIGN_NOLENBUTBYTES = -3; // 目前只适合于protobuf的boolean[]...double[]类型
// 目前只适合于protobuf的boolean[]...double[]类型
public static final short SIGN_NOLENBUTBYTES = -3;
/**
* 设置Reader的内容通常结合对象池使用

View File

@@ -41,9 +41,11 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
protected volatile boolean writePending;
private Map<String, Object> attributes; // 用于存储绑定在Connection上的对象集合
// 用于存储绑定在Connection上的对象集合
private Map<String, Object> attributes;
private Object subobject; // 用于存储绑定在Connection上的对象 同attributes 只绑定单个对象时尽量使用subobject而非attributes
// 用于存储绑定在Connection上的对象 同attributes 只绑定单个对象时尽量使用subobject而非attributes
private Object subobject;
protected final AsyncIOGroup ioGroup;

View File

@@ -220,17 +220,17 @@ public class AsyncIOGroup extends AsyncGroup {
AsyncIOThread currThread = AsyncIOThread.currentAsyncIOThread();
if (currThread != null) {
if (this.ioReadThreads[0].getThreadGroup() == currThread.getThreadGroup()) {
for (int i = 0; i < this.ioReadThreads.length; i++) {
if (this.ioReadThreads[i].index() == currThread.index()) {
readThread = this.ioReadThreads[i];
for (AsyncIOThread ioReadThread : this.ioReadThreads) {
if (ioReadThread.index() == currThread.index()) {
readThread = ioReadThread;
break;
}
}
}
if (this.ioWriteThreads[0].getThreadGroup() == currThread.getThreadGroup()) {
for (int i = 0; i < this.ioWriteThreads.length; i++) {
if (this.ioWriteThreads[i].index() == currThread.index()) {
writeThread = this.ioWriteThreads[i];
for (AsyncIOThread ioWriteThread : this.ioWriteThreads) {
if (ioWriteThread.index() == currThread.index()) {
writeThread = ioWriteThread;
break;
}
}
@@ -299,15 +299,15 @@ public class AsyncIOGroup extends AsyncGroup {
AsyncIOThread writeThread = null;
AsyncIOThread currThread = AsyncIOThread.currentAsyncIOThread();
if (currThread != null) {
for (int i = 0; i < this.ioReadThreads.length; i++) {
if (this.ioReadThreads[i].index() == currThread.index()) {
readThread = this.ioReadThreads[i];
for (AsyncIOThread ioReadThread : this.ioReadThreads) {
if (ioReadThread.index() == currThread.index()) {
readThread = ioReadThread;
break;
}
}
for (int i = 0; i < this.ioWriteThreads.length; i++) {
if (this.ioWriteThreads[i].index() == currThread.index()) {
writeThread = this.ioWriteThreads[i];
for (AsyncIOThread ioWriteThread : this.ioWriteThreads) {
if (ioWriteThread.index() == currThread.index()) {
writeThread = ioWriteThread;
break;
}
}

View File

@@ -52,7 +52,9 @@ public abstract class Request<C extends Context> {
protected AsyncConnection channel;
/** propertiesattributes 的区别在于:调用recycle时 attributes会被清空而properties会保留; properties 通常存放需要永久绑定在request里的一些对象 */
// propertiesattributes的区别在于
// 调用recycle时 attributes会被清空而properties会保留;
// properties 通常存放需要永久绑定在request里的一些对象
private final Map<String, Object> properties = new HashMap<>();
/** 每次新请求都会清空 */

View File

@@ -28,9 +28,11 @@ public abstract class Response<C extends Context, R extends Request<C>> {
protected final C context;
protected Supplier<Response> responseSupplier; // 虚拟构建的Response可能不存在responseSupplier
// 虚拟构建的Response可能不存在responseSupplier
protected Supplier<Response> responseSupplier;
protected Consumer<Response> responseConsumer; // 虚拟构建的Response可能不存在responseConsumer
// 虚拟构建的Response可能不存在responseConsumer
protected Consumer<Response> responseConsumer;
protected final ExecutorService workExecutor;
@@ -44,7 +46,8 @@ public abstract class Response<C extends Context, R extends Request<C>> {
protected boolean inNonBlocking = true;
protected Object output; // 输出的结果对象
// 输出的结果对象
protected Object output;
protected BiConsumer<R, Response<C, R>> recycleListener;

View File

@@ -20,9 +20,11 @@ import org.redkale.util.AnyValue;
*/
public abstract class Servlet<C extends Context, R extends Request<C>, P extends Response<C, R>> {
AnyValue _conf; // 当前Servlet的配置
// 当前Servlet的配置
AnyValue _conf;
protected boolean _nonBlocking; // 当前Servlet.execute方法是否为非阻塞模式
// 当前Servlet.execute方法是否为非阻塞模式
protected boolean _nonBlocking;
// Server执行start时运行此方法
public void init(C context, AnyValue config) {}

View File

@@ -22,9 +22,11 @@ public class WorkThread extends Thread implements Executor {
protected final ExecutorService workExecutor;
private final int index; // WorkThread下标从0开始
// WorkThread下标从0开始
private final int index;
private final int threads; // WorkThread个数
// WorkThread个数
private final int threads;
public WorkThread(
ThreadGroup g, String name, int index, int threads, ExecutorService workExecutor, Runnable target) {

View File

@@ -37,9 +37,11 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
protected final String name;
protected final AsyncGroup group; // 连接构造器
// 连接构造器
protected final AsyncGroup group;
protected final boolean tcp; // 是否TCP协议
// 是否TCP协议
protected final boolean tcp;
protected final ScheduledThreadPoolExecutor timeoutScheduler;
@@ -55,17 +57,19 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
private final AtomicBoolean closed = new AtomicBoolean();
// 不可protected、public
private final ClientAddress address; // 连接的地址
// 连接的地址
private final ClientAddress address;
// 连随机地址模式
private final int connLimit; // 最大连接数
// 连随机地址模式,最大连接数
private final int connLimit;
// 连指定地址模式
private final ConcurrentHashMap<SocketAddress, AddressConnEntry[]> connAddrEntrys = new ConcurrentHashMap<>();
protected ScheduledFuture timeoutFuture;
protected int maxPipelines = DEFAULT_MAX_PIPELINES; // 单个连接最大并行处理数
// 单个连接最大并行处理数
protected int maxPipelines = DEFAULT_MAX_PIPELINES;
protected int connectTimeoutSeconds;

View File

@@ -83,9 +83,11 @@ public abstract class ClientConnection<R extends ClientRequest, P extends Client
// pauseWriting=true此字段才会有值; pauseWriting=false此字段值为null
ClientFuture currHalfWriteFuture;
Iterator<ClientFuture<R, P>> currRespIterator; // 必须在调用decodeMessages之前重置为null
// 必须在调用decodeMessages之前重置为null
Iterator<ClientFuture<R, P>> currRespIterator;
private int maxPipelines; // 最大并行处理数
// 最大并行处理数
private int maxPipelines;
private boolean authenticated;

View File

@@ -18,8 +18,9 @@ import org.redkale.annotation.Nullable;
*/
public class ClientResponse<R extends ClientRequest, P extends ClientResult> {
// 服务端返回一个不存在的requestid可能为null
@Nullable
protected R request; // 服务端返回一个不存在的requestid可能为null
protected R request;
protected P message;

View File

@@ -157,7 +157,8 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
private boolean respHeadContainsConnection;
private int headWritedSize = -1; // 0表示跳过header正数表示header的字节长度。
// 0表示跳过header正数表示header的字节长度。
private int headWritedSize = -1;
private BiConsumer<HttpResponse, byte[]> cacheHandler;

View File

@@ -5,8 +5,6 @@
*/
package org.redkale.net.http;
import static org.redkale.boot.Application.RESNAME_SERVER_RESFACTORY;
import java.io.*;
import java.lang.reflect.*;
import java.net.InetSocketAddress;
@@ -21,6 +19,7 @@ import java.util.zip.*;
import org.redkale.annotation.*;
import org.redkale.annotation.Comment;
import org.redkale.boot.Application;
import static org.redkale.boot.Application.RESNAME_SERVER_RESFACTORY;
import org.redkale.convert.Convert;
import org.redkale.inject.Resourcable;
import org.redkale.inject.ResourceFactory;

View File

@@ -36,7 +36,7 @@ public class ByteBufferPool extends ObjectPool<ByteBuffer> {
max,
(Object... params) -> ByteBuffer.allocateDirect(bufferCapacity),
null,
(e) -> {
e -> {
if (e == null || e.isReadOnly() || e.capacity() != bufferCapacity) {
return false;
}