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

translate docean #671

Merged
merged 1 commit into from
Sep 6, 2023
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 @@ -48,12 +48,12 @@ public class Bean implements Comparable<Bean>, Serializable {
private int type;

/**
* 被引用的次数
* Number of citations
*/
private int referenceCnt;

/**
* 依赖我的那些Bean
* The beans that depend on me.
*/
private List<String> dependenceList = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@
public class MvcConfig implements Serializable {

/**
* 是否使用cglib
* Whether to use cglib
*/
private boolean useCglib;

/**
* 是否允许跨域
* Allow cross-origin
*/
private boolean allowCross;

/**
* 返回结果不包装
* The return result is not wrapped.
*/
private boolean responseOriginalValue;

private int poolSize = 200;

/**
* 是否支持下载
* Do you support downloading
*/
private boolean download;

/**
* 是否使用协程
* whether to use coroutines
*/
private boolean virtualThread;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
/**
* @Author [email protected]
* @Date 2021/6/7 10:03
*
* 用来加载框架的配置
* <p>
* Configuration for loading frameworks
*/
@Slf4j
public class DoceanConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ public static void runAndLog(ExRunnable runnable) {
}

/**
* 执行并记录Error,但不会抛出异常
* Execute and log the error, but do not throw an exception.
*
* @param callable
* @param defaultValue
* @return
* @param <T>
* @return
*/
public static <T> T callAndLog(ExCallable callable, T defaultValue) {
try {
return (T)callable.call();
return (T) callable.call();
} catch (Throwable ex) {
log.error(ex.getMessage(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public class HttpServerConfig {
private boolean cookie = true;

/**
* 允许上传文件
* Allow file upload
*/
private boolean upload;

/**
* 上传的路径
* Upload path
*/
private String uploadDir;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* @author [email protected]
* @date 2020/6/21
* <p>
* 一个简单的http服务器,为了支撑mvc
* rate limited or exceeded quota
*/
@Slf4j
public class DoceanHttpServer {
Expand Down Expand Up @@ -95,7 +95,7 @@ public void start() throws InterruptedException {
boolean useEpoll = NetUtils.useEpoll();
EventLoopGroup eventLoopGroupBoss = null;
EventLoopGroup eventLoopGroupWorker = null;
//是否使用原生的epoll
//Whether to use the native epoll.
int nThreads = Runtime.getRuntime().availableProcessors() * 2 + 1;
if (useEpoll) {
log.info("use epollEventLoopGroup nThreads:{}", nThreads);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public static String getBasePath(FullHttpRequest request) {

public static byte[] getRequestBody(FullHttpRequest request) {
String contentType = request.headers().get(CONTENT_TYPE, "").trim();
//支持form 表单提交
//Support form submission.
if (contentType.contains(X_WWW_FORM_URLENCODED) || contentType.contains(FORM_DATA)) {
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(false), request);
List<InterfaceHttpData> postData = decoder.getBodyHttpDatas();
Map<String,String> kv = new HashMap<>();
Map<String, String> kv = new HashMap<>();
for (InterfaceHttpData data : postData) {
if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
MemoryAttribute attribute = (MemoryAttribute) data;
Expand All @@ -88,7 +88,7 @@ public static byte[] getRequestBody(FullHttpRequest request) {
ByteBuf buf = request.content();
byte[] data = new byte[buf.readableBytes()];
buf.readBytes(data);
//使得下游继续可以读取
//Enable downstream to continue reading.
buf.readerIndex(0);
return data;
}
Expand All @@ -111,7 +111,7 @@ public static String getClientIp(FullHttpRequest request, Channel channel) {
}

/**
* 判断是否是内网
* Determine whether it is an intranet.
*
* @param request
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static FullHttpResponse create(FullHttpResponse res) {
}

/**
* 效率不高,谨慎使用
* rate limited or exceeded quota
*
* @param res
* @param content
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class MvcContext {
private String traceId;

/**
* 使用协程
* rate limited or exceeded quota
*/
private boolean virtualThread;

Expand All @@ -45,7 +45,7 @@ public class MvcContext {
private Map<String, String> headers;

/**
* 用户可以修改返回结果的headers
* Users can modify the headers of the returned results.
*/
private Map<String, String> resHeaders = new HashMap<>();

Expand All @@ -64,7 +64,7 @@ public class MvcContext {
private Object response;

/**
* 是否允许跨域
* rate limited or exceeded quota
*/
private boolean allowCross;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,27 @@ private void call() {
request.setPath(req.getPath());
request.setBody(new Gson().toJson(req.getParams()).getBytes());
}
//查找favicon.ioc 的直接返回找不到
//Directly returning not found when searching for favicon.ico.
if (isFaviconIco(request)) {
response.writeAndFlush(context, HttpResponseStatus.NOT_FOUND, "");
return;
}
String path = request.getPath();

//支持文件下载(/download) 并且必须开启下载
//Support file download (/download) and must enable downloads.
if (isDownload(path) && mvc.getMvcConfig().isDownload()) {
Download.download(context, request, response);
return;
}

//支持上传文件(/upload)
//Support uploading files (/upload)
if (isUpload(path)) {
MvcUpload.upload(mvc, request, response, context);
return;
}

HttpRequestMethod method = MethodFinder.find(path,this.requestMethodMap);
//支持指定path执行
HttpRequestMethod method = MethodFinder.find(path, this.requestMethodMap);
//rate limited or exceeded quota
if (null != method) {
mvc.callMethod(context, request, response, new MvcResult<>(), method);
return;
Expand All @@ -133,7 +133,7 @@ private void call() {
response.writeAndFlush(context, gson.toJson(result));
return;
}
//直接调用服务
//rate limited or exceeded quota
mvc.callService(context, request, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/**
* @author [email protected]
* 支持长连接
* rate limited or exceeded quota
*/
@Slf4j
public class TextWebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {
Expand All @@ -34,7 +34,7 @@ public class TextWebSocketHandler extends SimpleChannelInboundHandler<TextWebSoc
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt == WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) {
//移除http的操作
//Remove the operation of http.
ctx.pipeline().remove(HttpHandler.class);
} else {
super.userEventTriggered(ctx, evt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
/**
* @author [email protected]
* <p>
* 负责处理上传(优化的点是上传一部分就存储一部分,尽量少的占用内存)
* 如果用FullHttpRequest 代码会简单些,但这会占用大量内存,不可取
* 这里处理的并不是data-from那种标准的表单
* 现在默认没有开启(等未来遇到性能问题再开启)
* Responsible for handling uploads (the optimization point is to store a part of the upload as soon as possible, minimizing memory usage).
* If using FullHttpRequest code will be simpler, but it will consume a large amount of memory, which is not advisable.
* This is not dealing with the standard form like data-from.
* Currently, it is not enabled by default (it will be enabled in the future if there are performance issues).
*/
@Slf4j
public class HttpUploadHandler extends SimpleChannelInboundHandler<HttpObject> {
Expand Down Expand Up @@ -105,7 +105,7 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpObject httpObject) th
return;
}
DefaultHttpContent chunk = (DefaultHttpContent) httpObject;
//处理到这里,可能client 还在发送数据,所以这里需要有error 的处理逻辑
//rate limited or exceeded quota
if (!error) {
ByteBuf buf = chunk.content();
ByteBuffer buffer = buf.nioBuffer();
Expand All @@ -125,7 +125,7 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpObject httpObject) th
return;
}
} finally {
//改为自己手动释放
//rate limited or exceeded quota
int count = ReferenceCountUtil.refCnt(httpObject);
log.debug("ref count:{}", count);
if (count > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* @author [email protected]
* @date 2022/5/27
* 性能一般(但简单)
* rate limited or exceeded quota
*/
public class Upload {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ private ExceptionUtil() {
}

/**
* 拆解InvocationTargetException和UndeclaredThrowableException异常的包装,从而得到被包装的真正异常
* Unwrapping InvocationTargetException and UndeclaredThrowableException exceptions to obtain the underlying wrapped exception.
*
* @param wrapped 包装后的异常
* @return 拆解出的被包装异常
* @param wrapped Abnormal packaging
* @return Abnormal packaging of disassembled components.
*/
public static Throwable unwrapThrowable(Throwable wrapped) {
Throwable unwrapped = wrapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static HttpRequestMethod find(String path, ConcurrentHashMap<String, Http
return hrm;
}

//支持模糊匹配
//Support fuzzy matching.
String[] array = path.split("/");
if (array.length > 1) {
array[array.length - 1] = "*";
Expand All @@ -31,7 +31,7 @@ public static HttpRequestMethod find(String path, ConcurrentHashMap<String, Http
}
}

//多层次模糊匹配(/a/** 匹配 /a/b/c /a/b/d)
//rate limited or exceeded quota(/a/** match /a/b/c /a/b/d)
final String p = path;
Optional<Map.Entry<String, HttpRequestMethod>> optional = requestMethodMap.entrySet().stream().filter(it -> {
String key = it.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ default void init(Set<? extends Class<?>> classSet, Ioc ioc) {
}

/**
* 销毁操作
* Destroy operation
*
* @param ioc
*/
Expand All @@ -54,7 +54,7 @@ default void destory(Ioc ioc) {
}

/**
* 过滤的注解
* rate limited or exceeded quota
*
* @return
*/
Expand All @@ -67,7 +67,7 @@ default List<Class<? extends Annotation>> filterResourceAnnotations() {
}

/**
* 初始化需要被接管的bean
* Initialization requires the takeover of the bean.
*
* @param bean
* @return
Expand Down Expand Up @@ -103,7 +103,7 @@ default boolean after(Ioc ioc) {
}

/**
* plugin 启动操作(可以理解为依赖注入都完成后,想要完成的操作都可以放到这里)
* plugin Start operation (after all dependencies are injected, any desired operations can be placed here)
*
* @param ioc
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AopTest {


/**
* 底层使用cglib增强或者动态代理
* The bottom layer uses cglib enhancement or dynamic proxy.
*/
@Test
public void testAop() {
Expand Down
Loading