Skip to content

Commit 9f00f9e

Browse files
committed
add file store
1 parent ef42a2b commit 9f00f9e

File tree

18 files changed

+342
-624
lines changed

18 files changed

+342
-624
lines changed

02nio/nio02/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<dependency>
3030
<groupId>io.netty</groupId>
3131
<artifactId>netty-all</artifactId>
32-
<version>4.1.45.Final</version>
32+
<version>4.1.104.Final</version>
3333
</dependency>
3434

3535
<dependency>

02nio/nio02/src/main/java/io/github/kimmking/gateway/NettyServerApplication.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33

44
import io.github.kimmking.gateway.inbound.HttpInboundServer;
5+
import io.netty.util.internal.PlatformDependent;
56

7+
import java.lang.reflect.Constructor;
8+
import java.nio.ByteBuffer;
69
import java.util.Arrays;
710

811
public class NettyServerApplication {
@@ -12,6 +15,13 @@ public class NettyServerApplication {
1215

1316
public static void main(String[] args) {
1417

18+
// sun.misc.Unsafe unsafe = sun.misc.Unsafe.getUnsafe();
19+
// System.out.println(unsafe.addressSize());
20+
21+
22+
System.out.println("PlatformDependent.hasUnsafe = " + PlatformDependent.javaVersion());
23+
System.out.println("PlatformDependent.hasUnsafe = " + PlatformDependent.hasUnsafe());
24+
1525
String proxyPort = System.getProperty("proxyPort","8888");
1626

1727
// 这是之前的单个后端url的例子
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
package io.github.kimmking.gateway.filter;
22

3+
import io.netty.buffer.ByteBuf;
4+
import io.netty.buffer.Unpooled;
35
import io.netty.handler.codec.http.FullHttpResponse;
6+
import io.netty.handler.codec.http.HttpResponseStatus;
47

58
public class HeaderHttpResponseFilter implements HttpResponseFilter {
69
@Override
710
public void filter(FullHttpResponse response) {
811
response.headers().set("kk", "java-1-nio");
12+
response.setStatus(HttpResponseStatus.CREATED);
13+
// byte[] array = response.content().array();
14+
// String content = new String(array);
15+
// System.out.println(content);
16+
// content = content + ",kimmking";
17+
byte[] bytes = "hello,kimm.".getBytes();
18+
//response.headers().setInt("Content-Length", bytes.length);
19+
ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
20+
ByteBuf content = response.content();
21+
content.clear();
22+
content.writeBytes(byteBuf);
923
}
1024
}

02nio/nio02/src/main/java/io/github/kimmking/gateway/inbound/HttpInboundHandler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
3939
// if (uri.contains("/test")) {
4040
// handlerTest(fullRequest, ctx);
4141
// }
42-
43-
handler.handle(fullRequest, ctx, filter);
44-
42+
43+
String uri = fullRequest.getUri();
44+
System.out.println(" uri ==>> " + uri);
45+
if(uri.contains("/netty/info")) {
46+
NettyInfoHandler.INSTANCE.handle(fullRequest, ctx);
47+
} else {
48+
handler.handle(fullRequest, ctx, filter);
49+
}
4550
} catch(Exception e) {
4651
e.printStackTrace();
4752
} finally {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package io.github.kimmking.gateway.inbound;
2+
3+
import io.netty.buffer.Unpooled;
4+
import io.netty.channel.ChannelFutureListener;
5+
import io.netty.channel.ChannelHandlerContext;
6+
import io.netty.handler.codec.http.DefaultFullHttpResponse;
7+
import io.netty.handler.codec.http.FullHttpRequest;
8+
import io.netty.handler.codec.http.FullHttpResponse;
9+
import io.netty.handler.codec.http.HttpUtil;
10+
import io.netty.util.internal.PlatformDependent;
11+
import lombok.SneakyThrows;
12+
13+
import java.lang.reflect.Field;
14+
import java.util.HashMap;
15+
import java.util.Map;
16+
import java.util.concurrent.atomic.AtomicLong;
17+
18+
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
19+
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
20+
21+
/**
22+
* Description for this class.
23+
*
24+
* @Author : kimmking(kimmking@apache.org)
25+
* @create 2024/5/31 下午7:13
26+
*/
27+
public class NettyInfoHandler {
28+
29+
public final static NettyInfoHandler INSTANCE = new NettyInfoHandler();
30+
31+
public void handle(final FullHttpRequest fullRequest, final ChannelHandlerContext ctx) {
32+
System.out.println("NettyInfoHandler.handle...");
33+
Map<String, String> infos = new HashMap<>();
34+
infos.put("netty.usedDirectMemory", ""+getNettyUsedDirectMemory());
35+
infos.put("netty.directMemoryLimit", ""+getNettyDirectMemoryLimit());
36+
StringBuilder sb = new StringBuilder();
37+
sb.append("{");
38+
infos.forEach((k, v) -> {
39+
sb.append("\"").append(k).append("\"")
40+
.append(":")
41+
.append("\"").append(v).append("\"").append(",");
42+
});
43+
if(sb.length()>1) {
44+
sb.deleteCharAt(sb.length()-1);
45+
}
46+
sb.append("}");
47+
48+
byte[] body = ("{\"code\":200,\"msg\":\"success\",\"data\":" + sb +"}").getBytes();
49+
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(body));
50+
51+
response.headers().set("Content-Type", "application/json");
52+
response.headers().setInt("Content-Length", body.length);
53+
response.headers().set("kk.gw.hanlder", "netty.info");
54+
55+
if (fullRequest != null) {
56+
if (!HttpUtil.isKeepAlive(fullRequest)) {
57+
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
58+
} else {
59+
//response.headers().set(CONNECTION, KEEP_ALIVE);
60+
ctx.write(response);
61+
}
62+
}
63+
ctx.flush();
64+
//ctx.close();
65+
66+
}
67+
68+
@SneakyThrows
69+
private static long getNettyUsedDirectMemory() {
70+
Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_COUNTER");
71+
field.setAccessible(true);
72+
AtomicLong o = (AtomicLong)field.get(null);
73+
return o.get();
74+
}
75+
76+
@SneakyThrows
77+
private static long getNettyDirectMemoryLimit() {
78+
Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_LIMIT");
79+
field.setAccessible(true);
80+
return (Long)field.get(null);
81+
}
82+
83+
}

09mq/kmq-core/.mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 0 additions & 118 deletions
This file was deleted.
-49.5 KB
Binary file not shown.

09mq/kmq-core/.mvn/wrapper/maven-wrapper.properties

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)