update at 2021-02-07 22:11:59 by ehlxr
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-02-07 22:11:59 +08:00
parent 5c8712914b
commit e929cd180f
16 changed files with 230 additions and 96 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>did-parent</artifactId>

View File

@@ -91,6 +91,20 @@ public class SnowFlake {
this.machineId = machineId;
}
public static void main(String[] args) {
SnowFlake snowFlake = new SnowFlake(2, 3);
long start = System.currentTimeMillis();
for (int i = 0; i < (1 << 18); i++) {
System.out.println(i + ": " + snowFlake.nextId());
}
long end = System.currentTimeMillis();
System.out.println(end - start);
}
public static SnowFlakeBuilder newBuilder() {
return new SnowFlakeBuilder();
}
/**
* 产生下一个ID
*/
@@ -130,20 +144,6 @@ public class SnowFlake {
return System.currentTimeMillis();
}
public static void main(String[] args) {
SnowFlake snowFlake = new SnowFlake(2, 3);
long start = System.currentTimeMillis();
for (int i = 0; i < (1 << 18); i++) {
System.out.println(i + ": " + snowFlake.nextId());
}
long end = System.currentTimeMillis();
System.out.println(end - start);
}
public static SnowFlakeBuilder newBuilder() {
return new SnowFlakeBuilder();
}
public static final class SnowFlakeBuilder {
private long datacenterId;
private long machineId;

View File

@@ -31,7 +31,7 @@ public class SdkServerDecoder extends FixedLengthFrameDecoder {
} catch (Exception e) {
logger.error("decode exception, " + NettyUtil.parseRemoteAddr(ctx.channel()), e);
NettyUtil.closeChannel(ctx.channel());
}finally {
} finally {
if (buf != null) {
buf.release();
}
@@ -42,7 +42,7 @@ public class SdkServerDecoder extends FixedLengthFrameDecoder {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
Channel channel = ctx.channel();
logger.error("SdkServerDecoder channel [{}] error and will be closed", NettyUtil.parseRemoteAddr(channel),cause);
logger.error("SdkServerDecoder channel [{}] error and will be closed", NettyUtil.parseRemoteAddr(channel), cause);
NettyUtil.closeChannel(channel);
}
}

View File

@@ -38,9 +38,8 @@ public class SdkServerHandler extends SimpleChannelInboundHandler<SdkProto> {
semaphore.release();
} else {
String info = String.format("SdkServerHandler tryAcquire semaphore timeout, %dms, waiting thread " + "nums: %d availablePermit: %d",
logger.error("tryAcquire timeout after {}ms, {} threads waiting to acquire, {} permits available in this semaphore",
Constants.ACQUIRE_TIMEOUTMILLIS, this.semaphore.getQueueLength(), this.semaphore.availablePermits());
logger.error(info);
}
ctx.channel().