rest优化

This commit is contained in:
redkale
2023-03-17 18:42:26 +08:00
parent 9cab0c6443
commit e168c1368c
3 changed files with 37 additions and 24 deletions

View File

@@ -8,33 +8,33 @@ package org.redkale.boot;
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
import java.net.http.HttpClient;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.net.http.*;
import java.nio.*;
import java.nio.channels.*;
import java.nio.charset.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.concurrent.locks.*;
import java.util.function.*;
import java.util.logging.*;
import javax.net.ssl.SSLContext;
import org.redkale.annotation.Resource;
import javax.net.ssl.*;
import org.redkale.annotation.*;
import org.redkale.boot.ClassFilter.FilterEntry;
import org.redkale.cluster.*;
import org.redkale.convert.Convert;
import org.redkale.convert.bson.BsonFactory;
import org.redkale.convert.*;
import org.redkale.convert.bson.*;
import org.redkale.convert.json.*;
import org.redkale.mq.*;
import org.redkale.net.*;
import org.redkale.net.http.*;
import org.redkale.net.sncp.*;
import org.redkale.service.Service;
import org.redkale.service.*;
import org.redkale.source.*;
import org.redkale.util.AnyValue.DefaultAnyValue;
import org.redkale.util.*;
import org.redkale.watch.WatchServlet;
import org.redkale.watch.*;
/**
*
@@ -1607,15 +1607,17 @@ public final class Application {
}
logger.info("MessageAgent(names=" + JsonConvert.root().convertTo(names) + ") start in " + (System.currentTimeMillis() - s) + " ms");
}
for (ApplicationListener listener : this.listeners) {
listener.postStart(this);
}
long intms = System.currentTimeMillis() - startTime;
String ms = String.valueOf(intms);
int repeat = ms.length() > 7 ? 0 : (7 - ms.length()) / 2;
logger.info(colorMessage(logger, 36, 1, "-".repeat(repeat) + "------------------------ Redkale started in " + ms + " ms " + (ms.length() / 2 == 0 ? " " : "") + "-".repeat(repeat) + "------------------------") + "\r\n");
LoggingBaseHandler.traceFlag = true;
for (ApplicationListener listener : this.listeners) {
listener.postStart(this);
}
if (!singletonMode && !compileMode) {
this.shutdownLatch.await();
}
@@ -2410,6 +2412,7 @@ public final class Application {
}
public void shutdown() throws Exception {
long f = System.currentTimeMillis();
for (ApplicationListener listener : this.listeners) {
try {
listener.preShutdown(this);
@@ -2506,6 +2509,13 @@ public final class Application {
logger.info("AsyncGroup destroy in " + (System.currentTimeMillis() - s) + " ms");
}
this.sncpTransportFactory.shutdownNow();
long intms = System.currentTimeMillis() - f;
String ms = String.valueOf(intms);
int repeat = ms.length() > 7 ? 0 : (7 - ms.length()) / 2;
logger.info(colorMessage(logger, 36, 1, "-".repeat(repeat) + "------------------------ Redkale shutdown in " + ms + " ms " + (ms.length() / 2 == 0 ? " " : "") + "-".repeat(repeat) + "------------------------") + "\r\n" + "\r\n");
LoggingBaseHandler.traceFlag = true;
}
public ExecutorService getWorkExecutor() {

View File

@@ -633,7 +633,7 @@ public class HttpRequest extends Request<HttpContext> {
if (remain-- < 1) {
this.params.clear();
buffer.clear();
buffer.put((byte) '\r');
buffer.put(b);
return 1;
}
if (buffer.get() != '\n') {

View File

@@ -1730,13 +1730,6 @@ public final class Rest {
av0.visitEnd();
fv.visitEnd();
}
{ //注入 @Resource(name = "APP_HOME") private File _redkale_home;
fv = cw.visitField(ACC_PRIVATE, "_redkale_home", Type.getDescriptor(File.class), null, null);
av0 = fv.visitAnnotation(resDesc, true);
av0.visit("name", "APP_HOME");
av0.visitEnd();
fv.visitEnd();
}
{ //_servicemap字段 Map<String, XXXService>
fv = cw.visitField(ACC_PRIVATE, REST_SERVICEMAP_FIELD_NAME, "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;" + serviceDesc + ">;", null);
fv.visitEnd();
@@ -1771,6 +1764,7 @@ public final class Rest {
final Map<String, List<String>> asmParamMap = namePresent ? null : MethodParamClassVisitor.getMethodParamNames(new HashMap<>(), serviceType);
Map<String, byte[]> innerClassBytesMap = new LinkedHashMap<>();
boolean containsMupload = false;
for (final MappingEntry entry : entrys) {
RestUploadFile mupload = null;
Class muploadType = null;
@@ -2322,6 +2316,7 @@ public final class Rest {
}
int uploadLocal = 0;
if (mupload != null) { //存在文件上传
containsMupload = true;
if (muploadType == byte[].class) {
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getMultiContext", "()" + multiContextDesc, false);
@@ -3282,6 +3277,14 @@ public final class Rest {
}
} // end for each
if (containsMupload) { //注入 @Resource(name = "APP_HOME") private File _redkale_home;
fv = cw.visitField(ACC_PRIVATE, "_redkale_home", Type.getDescriptor(File.class), null, null);
av0 = fv.visitAnnotation(resDesc, true);
av0.visit("name", "APP_HOME");
av0.visitEnd();
fv.visitEnd();
}
// HashMap<String, ActionEntry> _createRestActionEntry() {
// HashMap<String, ActionEntry> map = new HashMap<>();
// map.put("asyncfind3", new ActionEntry(100000,200000,"asyncfind3", new String[]{},null,false,false,0, new _Dync_asyncfind3_HttpServlet()));