From ebecb83c0527e439a8a417e4cd979f5852c91b11 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Sat, 13 Feb 2021 11:11:14 +0800 Subject: [PATCH 1/4] update at 2021-02-13 11:11:14 by ehlxr --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2172ba1..e19fdfd 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 1.8 1.8 - 1.0.2-SNAPSHOT + 1.1.0-SNAPSHOT 4.1.58.Final 1.1.7 From b864ec81615428652576683e9f976df2e22ad2f2 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Sat, 13 Feb 2021 11:56:06 +0800 Subject: [PATCH 2/4] add HessianSerializer --- .../java/io/github/ehlxr/did/common/Code.java | 24 +++++++ .../io/github/ehlxr/did/common/Constants.java | 24 +++++++ .../io/github/ehlxr/did/common/JsonUtils.java | 24 +++++++ .../io/github/ehlxr/did/common/NettyUtil.java | 24 +++++++ .../io/github/ehlxr/did/common/Result.java | 24 +++++++ did-core/pom.xml | 6 ++ .../java/io/github/ehlxr/did/SdkProto.java | 24 +++++++ .../io/github/ehlxr/did/adapter/Message.java | 39 +++++++---- .../ehlxr/did/adapter/MessageDecoder.java | 1 + .../ehlxr/did/adapter/MessageEncoder.java | 8 ++- .../ehlxr/did/serializer/Serializer.java | 24 +++++++ .../did/serializer/SerializerHolder.java | 25 ++++++- .../serializer/impl/HessianSerializer.java | 70 +++++++++++++++++++ .../serializer/{ => impl}/JdkSerializer.java | 3 +- .../{ => impl}/ProtostuffSerializer.java | 3 +- .../io.github.ehlxr.did.serializer.Serializer | 7 +- .../ehlxr/did/client/AbstractClient.java | 24 +++++++ .../io/github/ehlxr/did/client/Client.java | 25 ++++++- .../ehlxr/did/client/InvokeCallback.java | 24 +++++++ .../ehlxr/did/client/ResponseFuture.java | 24 +++++++ .../io/github/ehlxr/did/client/SdkClient.java | 24 +++++++ .../did/client/handler/SdkClientHandler.java | 5 +- .../io/github/ehlxr/did/DidSdkPressTest.java | 24 +++++++ .../java/io/github/ehlxr/did/DidSdkTest.java | 40 +++++++++-- .../io/github/ehlxr/did/ServerStarter.java | 24 +++++++ .../github/ehlxr/did/generator/SnowFlake.java | 24 +++++++ .../github/ehlxr/did/server/BaseServer.java | 24 +++++++ .../io/github/ehlxr/did/server/Server.java | 24 +++++++ .../ehlxr/did/server/http/HttpServer.java | 24 +++++++ .../did/server/http/HttpServerHandler.java | 24 +++++++ .../ehlxr/did/server/sdk/SdkServer.java | 24 +++++++ .../did/server/sdk/SdkServerHandler.java | 26 ++++++- pom.xml | 8 +++ 33 files changed, 687 insertions(+), 35 deletions(-) create mode 100644 did-core/src/main/java/io/github/ehlxr/did/serializer/impl/HessianSerializer.java rename did-core/src/main/java/io/github/ehlxr/did/serializer/{ => impl}/JdkSerializer.java (95%) rename did-core/src/main/java/io/github/ehlxr/did/serializer/{ => impl}/ProtostuffSerializer.java (96%) diff --git a/did-common/src/main/java/io/github/ehlxr/did/common/Code.java b/did-common/src/main/java/io/github/ehlxr/did/common/Code.java index 13afc5d..3eab87d 100644 --- a/did-common/src/main/java/io/github/ehlxr/did/common/Code.java +++ b/did-common/src/main/java/io/github/ehlxr/did/common/Code.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.common; /** diff --git a/did-common/src/main/java/io/github/ehlxr/did/common/Constants.java b/did-common/src/main/java/io/github/ehlxr/did/common/Constants.java index 74c6d1d..ab8355f 100644 --- a/did-common/src/main/java/io/github/ehlxr/did/common/Constants.java +++ b/did-common/src/main/java/io/github/ehlxr/did/common/Constants.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.common; import java.util.Map; diff --git a/did-common/src/main/java/io/github/ehlxr/did/common/JsonUtils.java b/did-common/src/main/java/io/github/ehlxr/did/common/JsonUtils.java index 45f3841..407e187 100644 --- a/did-common/src/main/java/io/github/ehlxr/did/common/JsonUtils.java +++ b/did-common/src/main/java/io/github/ehlxr/did/common/JsonUtils.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.common; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/did-common/src/main/java/io/github/ehlxr/did/common/NettyUtil.java b/did-common/src/main/java/io/github/ehlxr/did/common/NettyUtil.java index 284e141..86e93cf 100644 --- a/did-common/src/main/java/io/github/ehlxr/did/common/NettyUtil.java +++ b/did-common/src/main/java/io/github/ehlxr/did/common/NettyUtil.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.common; import io.netty.channel.Channel; diff --git a/did-common/src/main/java/io/github/ehlxr/did/common/Result.java b/did-common/src/main/java/io/github/ehlxr/did/common/Result.java index db527fd..aa49d79 100644 --- a/did-common/src/main/java/io/github/ehlxr/did/common/Result.java +++ b/did-common/src/main/java/io/github/ehlxr/did/common/Result.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.common; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/did-core/pom.xml b/did-core/pom.xml index 99a913a..cef3a7b 100644 --- a/did-core/pom.xml +++ b/did-core/pom.xml @@ -25,6 +25,12 @@ io.protostuff protostuff-runtime + + + com.caucho + hessian + + diff --git a/did-core/src/main/java/io/github/ehlxr/did/SdkProto.java b/did-core/src/main/java/io/github/ehlxr/did/SdkProto.java index 0120af1..8b65c8b 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/SdkProto.java +++ b/did-core/src/main/java/io/github/ehlxr/did/SdkProto.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did; import io.github.ehlxr.did.common.JsonUtils; diff --git a/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java b/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java index b9f1827..70f83c8 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java +++ b/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java @@ -24,9 +24,6 @@ package io.github.ehlxr.did.adapter; -import io.github.ehlxr.did.common.Try; -import io.github.ehlxr.did.serializer.SerializerHolder; - import java.io.Serializable; /** @@ -56,12 +53,6 @@ public class Message implements Serializable { */ private T content; - public Message(byte type, byte flag, T content) { - this.type = type; - this.flag = flag; - this.content = content; - } - public Message() { } @@ -86,20 +77,31 @@ public class Message implements Serializable { } public int getLength() { - return getContent().length; + return length; } - public byte[] getContent() { - return Try.of(SerializerHolder.get()::serializer).apply(content).get(); + public void setLength(int length) { + this.length = length; } + public T getContent() { + return content; + } + // public int getLength() { + // return getContent().length; + // } + + // public byte[] getContent() { + // return Try.of(SerializerHolder.get()::serializer).apply(content).get(); + // } + public void setContent(T content) { this.content = content; } - public T content(Class clazz) { - return SerializerHolder.get().deserializer(getContent(), clazz); - } + // public T content(Class clazz) { + // return SerializerHolder.get().deserializer(getContent(), clazz); + // } @Override public String toString() { @@ -114,6 +116,7 @@ public class Message implements Serializable { public static final class MessageBuilder { private byte type; private byte flag; + private int length; private T content; private MessageBuilder() { @@ -129,6 +132,11 @@ public class Message implements Serializable { return this; } + public MessageBuilder length(int length) { + this.length = length; + return this; + } + public MessageBuilder content(T content) { this.content = content; return this; @@ -138,6 +146,7 @@ public class Message implements Serializable { Message message = new Message<>(); message.setType(type); message.setFlag(flag); + message.setLength(length); message.setContent(content); return message; } diff --git a/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageDecoder.java b/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageDecoder.java index 0f16b5c..541a225 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageDecoder.java +++ b/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageDecoder.java @@ -91,6 +91,7 @@ public class MessageDecoder extends LengthFieldBasedFrameDecoder { return Message.newBuilder() .type(type) .flag(flag) + .length(bytes.length) .content(SerializerHolder.get().deserializer(bytes, SdkProto.class)) .build(); } diff --git a/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageEncoder.java b/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageEncoder.java index ab557ec..fa67f71 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageEncoder.java +++ b/did-core/src/main/java/io/github/ehlxr/did/adapter/MessageEncoder.java @@ -25,6 +25,8 @@ package io.github.ehlxr.did.adapter; import io.github.ehlxr.did.SdkProto; +import io.github.ehlxr.did.common.Try; +import io.github.ehlxr.did.serializer.SerializerHolder; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; @@ -40,11 +42,13 @@ public class MessageEncoder extends MessageToByteEncoder> { @Override protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) { Objects.requireNonNull(msg, "encode failed 'cause of recive message is null"); + SdkProto content = msg.getContent(); + byte[] bytes = Try.of(SerializerHolder.get()::serializer).apply(content).get(); out.writeByte(msg.getType()); out.writeByte(msg.getFlag()); - out.writeInt(msg.getLength()); - out.writeBytes(msg.getContent()); + out.writeInt(bytes.length); + out.writeBytes(bytes); } } diff --git a/did-core/src/main/java/io/github/ehlxr/did/serializer/Serializer.java b/did-core/src/main/java/io/github/ehlxr/did/serializer/Serializer.java index f6878aa..0ef6fd0 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/serializer/Serializer.java +++ b/did-core/src/main/java/io/github/ehlxr/did/serializer/Serializer.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.serializer; import io.github.ehlxr.did.extension.SPI; diff --git a/did-core/src/main/java/io/github/ehlxr/did/serializer/SerializerHolder.java b/did-core/src/main/java/io/github/ehlxr/did/serializer/SerializerHolder.java index 0647d29..b287a17 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/serializer/SerializerHolder.java +++ b/did-core/src/main/java/io/github/ehlxr/did/serializer/SerializerHolder.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.serializer; import io.github.ehlxr.did.common.Constants; @@ -7,7 +31,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Objects; -import java.util.Set; /** * @author ehlxr diff --git a/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/HessianSerializer.java b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/HessianSerializer.java new file mode 100644 index 0000000..6cee25a --- /dev/null +++ b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/HessianSerializer.java @@ -0,0 +1,70 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package io.github.ehlxr.did.serializer.impl; + +import com.caucho.hessian.io.HessianInput; +import com.caucho.hessian.io.HessianOutput; +import io.github.ehlxr.did.common.Try; +import io.github.ehlxr.did.serializer.Serializer; +import io.protostuff.LinkedBuffer; +import io.protostuff.ProtostuffIOUtil; +import io.protostuff.Schema; +import io.protostuff.runtime.RuntimeSchema; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author ehlxr + * @since 2021-02-09 11:07. + */ +public class HessianSerializer implements Serializer { + @Override + public byte[] serializer(T obj) { + return Try.of(o -> { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + HessianOutput ho = new HessianOutput(bos); + ho.writeObject(obj); + ho.flush(); + + return bos.toByteArray(); + }).trap(Throwable::printStackTrace).apply(obj).get(); + } + + @Override + public T deserializer(byte[] bytes, Class clazz) { + return Try.of(bs -> { + ByteArrayInputStream bis = new ByteArrayInputStream(bs); + HessianInput hi = new HessianInput(bis); + + Object o = hi.readObject(); + return clazz.isInstance(o) ? clazz.cast(o) : null; + }).trap(Throwable::printStackTrace).apply(bytes).get(); + } +} diff --git a/did-core/src/main/java/io/github/ehlxr/did/serializer/JdkSerializer.java b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/JdkSerializer.java similarity index 95% rename from did-core/src/main/java/io/github/ehlxr/did/serializer/JdkSerializer.java rename to did-core/src/main/java/io/github/ehlxr/did/serializer/impl/JdkSerializer.java index 531c27b..12a0dc5 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/serializer/JdkSerializer.java +++ b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/JdkSerializer.java @@ -22,9 +22,10 @@ * THE SOFTWARE. */ -package io.github.ehlxr.did.serializer; +package io.github.ehlxr.did.serializer.impl; import io.github.ehlxr.did.common.Try; +import io.github.ehlxr.did.serializer.Serializer; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; diff --git a/did-core/src/main/java/io/github/ehlxr/did/serializer/ProtostuffSerializer.java b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/ProtostuffSerializer.java similarity index 96% rename from did-core/src/main/java/io/github/ehlxr/did/serializer/ProtostuffSerializer.java rename to did-core/src/main/java/io/github/ehlxr/did/serializer/impl/ProtostuffSerializer.java index 58fa472..7c54ec5 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/serializer/ProtostuffSerializer.java +++ b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/ProtostuffSerializer.java @@ -22,9 +22,10 @@ * THE SOFTWARE. */ -package io.github.ehlxr.did.serializer; +package io.github.ehlxr.did.serializer.impl; import io.github.ehlxr.did.common.Try; +import io.github.ehlxr.did.serializer.Serializer; import io.protostuff.LinkedBuffer; import io.protostuff.ProtostuffIOUtil; import io.protostuff.Schema; diff --git a/did-core/src/main/resources/META-INF/extensions/internal/io.github.ehlxr.did.serializer.Serializer b/did-core/src/main/resources/META-INF/extensions/internal/io.github.ehlxr.did.serializer.Serializer index b5c1096..52b1c72 100644 --- a/did-core/src/main/resources/META-INF/extensions/internal/io.github.ehlxr.did.serializer.Serializer +++ b/did-core/src/main/resources/META-INF/extensions/internal/io.github.ehlxr.did.serializer.Serializer @@ -1,3 +1,4 @@ -#protostuff1=io.github.ehlxr.did.serializer.ProtostuffSerializer -protostuff=io.github.ehlxr.did.serializer.ProtostuffSerializer -io.github.ehlxr.did.serializer.JdkSerializer \ No newline at end of file +#protostuff1=io.github.ehlxr.did.serializer.impl.ProtostuffSerializer +protostuff=io.github.ehlxr.did.serializer.impl.ProtostuffSerializer +io.github.ehlxr.did.serializer.impl.JdkSerializer +io.github.ehlxr.did.serializer.impl.HessianSerializer \ No newline at end of file diff --git a/did-sdk/src/main/java/io/github/ehlxr/did/client/AbstractClient.java b/did-sdk/src/main/java/io/github/ehlxr/did/client/AbstractClient.java index 341c1c4..ee6f71e 100644 --- a/did-sdk/src/main/java/io/github/ehlxr/did/client/AbstractClient.java +++ b/did-sdk/src/main/java/io/github/ehlxr/did/client/AbstractClient.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.client; import io.github.ehlxr.did.SdkProto; diff --git a/did-sdk/src/main/java/io/github/ehlxr/did/client/Client.java b/did-sdk/src/main/java/io/github/ehlxr/did/client/Client.java index 7cdf582..b58c86b 100644 --- a/did-sdk/src/main/java/io/github/ehlxr/did/client/Client.java +++ b/did-sdk/src/main/java/io/github/ehlxr/did/client/Client.java @@ -1,5 +1,28 @@ -package io.github.ehlxr.did.client; +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package io.github.ehlxr.did.client; import io.github.ehlxr.did.SdkProto; import io.github.ehlxr.did.common.Result; diff --git a/did-sdk/src/main/java/io/github/ehlxr/did/client/InvokeCallback.java b/did-sdk/src/main/java/io/github/ehlxr/did/client/InvokeCallback.java index a5573a9..ff9e52d 100644 --- a/did-sdk/src/main/java/io/github/ehlxr/did/client/InvokeCallback.java +++ b/did-sdk/src/main/java/io/github/ehlxr/did/client/InvokeCallback.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.client; /** diff --git a/did-sdk/src/main/java/io/github/ehlxr/did/client/ResponseFuture.java b/did-sdk/src/main/java/io/github/ehlxr/did/client/ResponseFuture.java index d3569fe..fb097dc 100644 --- a/did-sdk/src/main/java/io/github/ehlxr/did/client/ResponseFuture.java +++ b/did-sdk/src/main/java/io/github/ehlxr/did/client/ResponseFuture.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.client; import io.github.ehlxr.did.SdkProto; diff --git a/did-sdk/src/main/java/io/github/ehlxr/did/client/SdkClient.java b/did-sdk/src/main/java/io/github/ehlxr/did/client/SdkClient.java index 4987b12..d377633 100644 --- a/did-sdk/src/main/java/io/github/ehlxr/did/client/SdkClient.java +++ b/did-sdk/src/main/java/io/github/ehlxr/did/client/SdkClient.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.client; import io.github.ehlxr.did.adapter.MessageDecoder; diff --git a/did-sdk/src/main/java/io/github/ehlxr/did/client/handler/SdkClientHandler.java b/did-sdk/src/main/java/io/github/ehlxr/did/client/handler/SdkClientHandler.java index b3306b8..2b7d290 100644 --- a/did-sdk/src/main/java/io/github/ehlxr/did/client/handler/SdkClientHandler.java +++ b/did-sdk/src/main/java/io/github/ehlxr/did/client/handler/SdkClientHandler.java @@ -46,10 +46,7 @@ public class SdkClientHandler extends SimpleChannelInboundHandler message) { logger.debug("sdk client handler receive message {}", message); - SdkProto sdkProto = Try., SdkProto>of(m -> m.content(SdkProto.class)) - .apply(message) - .get(); - + SdkProto sdkProto = message.getContent(); final int rqid = sdkProto.getRqid(); final ResponseFuture responseFuture = Client.REPONSE_MAP.get(rqid); if (responseFuture != null) { diff --git a/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkPressTest.java b/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkPressTest.java index 5ac4e04..29ec1ec 100644 --- a/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkPressTest.java +++ b/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkPressTest.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did; import io.github.ehlxr.did.client.SdkClient; diff --git a/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkTest.java b/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkTest.java index c94d8a0..83ed2f8 100644 --- a/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkTest.java +++ b/did-sdk/src/test/java/io/github/ehlxr/did/DidSdkTest.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did; import io.github.ehlxr.did.client.SdkClient; @@ -5,6 +29,8 @@ import io.github.ehlxr.did.common.Try; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -14,6 +40,8 @@ import java.util.stream.IntStream; * @author ehlxr */ public class DidSdkTest { + private static final Logger logger = LoggerFactory.getLogger(DidSdkTest.class); + private static final int NUM = 10; SdkClient client; @@ -34,26 +62,26 @@ public class DidSdkTest { // 测试同步请求 IntStream.range(0, NUM).parallel().forEach(i -> System.out.println(client.invokeSync())); - System.out.println("invokeync test finish"); + logger.info("invokeync test finish"); // 测试异步请求 final CountDownLatch countDownLatch = new CountDownLatch(NUM); IntStream.range(0, NUM).parallel().forEach(i -> Try.of(() -> client.invokeAsync(responseFuture -> { - System.out.println(responseFuture.getSdkProto()); + logger.info("{}", responseFuture.getSdkProto()); countDownLatch.countDown(); })).trap(Throwable::printStackTrace).run()); //noinspection ResultOfMethodCallIgnored countDownLatch.await(10, TimeUnit.SECONDS); - System.out.println("invokeAsync test finish"); + logger.info("invokeAsync test finish"); } @Test public void testInvoke() { - // System.out.println(client.invoke()); + // logger.info("{}", client.invoke()); - client.setTimeoutMillis(3000); - System.out.println(client.invoke()); + client.setTimeoutMillis(30000); + logger.info("{}", client.invoke()); } } diff --git a/did-server/src/main/java/io/github/ehlxr/did/ServerStarter.java b/did-server/src/main/java/io/github/ehlxr/did/ServerStarter.java index 547c3e7..1f3cd66 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/ServerStarter.java +++ b/did-server/src/main/java/io/github/ehlxr/did/ServerStarter.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did; import io.github.ehlxr.did.common.Constants; diff --git a/did-server/src/main/java/io/github/ehlxr/did/generator/SnowFlake.java b/did-server/src/main/java/io/github/ehlxr/did/generator/SnowFlake.java index 0a5b3b8..37cdbdb 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/generator/SnowFlake.java +++ b/did-server/src/main/java/io/github/ehlxr/did/generator/SnowFlake.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.generator; /** diff --git a/did-server/src/main/java/io/github/ehlxr/did/server/BaseServer.java b/did-server/src/main/java/io/github/ehlxr/did/server/BaseServer.java index 27760ef..f61cd94 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/server/BaseServer.java +++ b/did-server/src/main/java/io/github/ehlxr/did/server/BaseServer.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.server; import io.github.ehlxr.did.generator.SnowFlake; diff --git a/did-server/src/main/java/io/github/ehlxr/did/server/Server.java b/did-server/src/main/java/io/github/ehlxr/did/server/Server.java index 1704687..2b4abdb 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/server/Server.java +++ b/did-server/src/main/java/io/github/ehlxr/did/server/Server.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.server; /** diff --git a/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServer.java b/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServer.java index f3d215d..ef76682 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServer.java +++ b/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServer.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.server.http; import io.github.ehlxr.did.generator.SnowFlake; diff --git a/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServerHandler.java b/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServerHandler.java index db70791..ca12ab4 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServerHandler.java +++ b/did-server/src/main/java/io/github/ehlxr/did/server/http/HttpServerHandler.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.server.http; import io.github.ehlxr.did.SdkProto; diff --git a/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServer.java b/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServer.java index c6aba63..045f8cd 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServer.java +++ b/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServer.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.server.sdk; import io.github.ehlxr.did.generator.SnowFlake; diff --git a/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServerHandler.java b/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServerHandler.java index 48e17ae..0eb8791 100644 --- a/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServerHandler.java +++ b/did-server/src/main/java/io/github/ehlxr/did/server/sdk/SdkServerHandler.java @@ -1,3 +1,27 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + package io.github.ehlxr.did.server.sdk; import io.github.ehlxr.did.SdkProto; @@ -37,7 +61,7 @@ public class SdkServerHandler extends SimpleChannelInboundHandler4.13.1 2.10.3 1.7.2 + 4.0.65 @@ -82,6 +83,13 @@ protostuff-runtime ${protostuff.version} + + + com.caucho + hessian + ${hessian.version} + + From 101cbf4ce0e8f15f610387cfc12591bd01d5e121 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Sat, 13 Feb 2021 12:33:14 +0800 Subject: [PATCH 3/4] add each serializer test --- did-core/pom.xml | 6 ++ .../io/github/ehlxr/did/adapter/Message.java | 11 --- .../serializer/impl/ProtostuffSerializer.java | 4 +- .../io/github/ehlxr/did/SerializerTest.java | 92 +++++++++++++++++++ 4 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 did-core/src/test/java/io/github/ehlxr/did/SerializerTest.java diff --git a/did-core/pom.xml b/did-core/pom.xml index cef3a7b..b704604 100644 --- a/did-core/pom.xml +++ b/did-core/pom.xml @@ -31,6 +31,12 @@ hessian + + junit + junit + test + + diff --git a/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java b/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java index 70f83c8..ca02654 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java +++ b/did-core/src/main/java/io/github/ehlxr/did/adapter/Message.java @@ -87,22 +87,11 @@ public class Message implements Serializable { public T getContent() { return content; } - // public int getLength() { - // return getContent().length; - // } - - // public byte[] getContent() { - // return Try.of(SerializerHolder.get()::serializer).apply(content).get(); - // } public void setContent(T content) { this.content = content; } - // public T content(Class clazz) { - // return SerializerHolder.get().deserializer(getContent(), clazz); - // } - @Override public String toString() { return "Message{" + diff --git a/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/ProtostuffSerializer.java b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/ProtostuffSerializer.java index 7c54ec5..14316a7 100644 --- a/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/ProtostuffSerializer.java +++ b/did-core/src/main/java/io/github/ehlxr/did/serializer/impl/ProtostuffSerializer.java @@ -58,9 +58,7 @@ public class ProtostuffSerializer implements Serializer { return ProtostuffIOUtil.toByteArray(obj, schema, buffer); }).apply(buffer).trap(e -> { throw new IllegalStateException(e.getMessage(), e); - }).andFinally(b -> { - ((LinkedBuffer) b).clear(); - }).get(); + }).andFinally(b -> ((LinkedBuffer) b).clear()).get(); } @Override diff --git a/did-core/src/test/java/io/github/ehlxr/did/SerializerTest.java b/did-core/src/test/java/io/github/ehlxr/did/SerializerTest.java new file mode 100644 index 0000000..3f7b3d3 --- /dev/null +++ b/did-core/src/test/java/io/github/ehlxr/did/SerializerTest.java @@ -0,0 +1,92 @@ +/* + * The MIT License (MIT) + * + * Copyright © 2020 xrv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package io.github.ehlxr.did; + +import io.github.ehlxr.did.extension.ExtensionLoader; +import io.github.ehlxr.did.serializer.Serializer; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author ehlxr + * @since 2021-02-13 11:59. + */ +public class SerializerTest { + private static final Logger logger = LoggerFactory.getLogger(SerializerTest.class); + private SdkProto message; + + @Before + public void init() { + message = SdkProto.newBuilder().did(238231232112121L).build(); + message.rqid(); + } + + @Test + public void jdkTest() { + Serializer serializer = ExtensionLoader.getExtensionLoader(Serializer.class).getExtension("jdk"); + + long b1 = System.currentTimeMillis(); + byte[] bytes = serializer.serializer(message); + long e1 = System.currentTimeMillis(); + logger.info("jdk serialize result length = {}, cost time:{}", bytes.length, (e1 - b1)); + + long b2 = System.currentTimeMillis(); + SdkProto data = serializer.deserializer(bytes, SdkProto.class); + long e2 = System.currentTimeMillis(); + logger.info("jdk deserialize result:{}, cost time:{}", data, (e2 - b2)); + } + + @Test + public void hessianTest() { + Serializer serializer = ExtensionLoader.getExtensionLoader(Serializer.class).getExtension("hessian"); + + long b1 = System.currentTimeMillis(); + byte[] bytes = serializer.serializer(message); + long e1 = System.currentTimeMillis(); + logger.info("hessian serialize result length = {}, cost time:{}", bytes.length, (e1 - b1)); + + long b2 = System.currentTimeMillis(); + SdkProto data = serializer.deserializer(bytes, SdkProto.class); + long e2 = System.currentTimeMillis(); + logger.info("hessian deserialize result:{}, cost time:{}", data, (e2 - b2)); + } + + @Test + public void protostuffTest() { + Serializer serializer = ExtensionLoader.getExtensionLoader(Serializer.class).getExtension("protostuff"); + + long b1 = System.currentTimeMillis(); + byte[] bytes = serializer.serializer(message); + long e1 = System.currentTimeMillis(); + logger.info("protostuff serialize result length = {}, cost time:{}", bytes.length, (e1 - b1)); + + long b2 = System.currentTimeMillis(); + SdkProto data = serializer.deserializer(bytes, SdkProto.class); + long e2 = System.currentTimeMillis(); + logger.info("protostuff deserialize result:{}, cost time:{}", data, (e2 - b2)); + } +} From 2c4a1d92c9cf47246209bb975df209cd9db0faa4 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Sat, 13 Feb 2021 12:34:46 +0800 Subject: [PATCH 4/4] update version --- did-common/pom.xml | 2 +- did-core/pom.xml | 2 +- did-sdk/pom.xml | 2 +- did-server/pom.xml | 2 +- pom.xml | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/did-common/pom.xml b/did-common/pom.xml index ca5a733..c71c915 100644 --- a/did-common/pom.xml +++ b/did-common/pom.xml @@ -5,7 +5,7 @@ did-parent io.github.ehlxr - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 4.0.0 diff --git a/did-core/pom.xml b/did-core/pom.xml index b704604..f239a7b 100644 --- a/did-core/pom.xml +++ b/did-core/pom.xml @@ -5,7 +5,7 @@ did-parent io.github.ehlxr - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 4.0.0 diff --git a/did-sdk/pom.xml b/did-sdk/pom.xml index 83b4655..1932ff3 100644 --- a/did-sdk/pom.xml +++ b/did-sdk/pom.xml @@ -5,7 +5,7 @@ did-parent io.github.ehlxr - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 4.0.0 diff --git a/did-server/pom.xml b/did-server/pom.xml index f3342e6..5942fa4 100644 --- a/did-server/pom.xml +++ b/did-server/pom.xml @@ -5,7 +5,7 @@ did-parent io.github.ehlxr - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index b74acc8..ddc0353 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ io.github.ehlxr did-parent pom - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT did-server did-sdk @@ -23,7 +23,7 @@ 1.8 1.8 - 1.1.0-SNAPSHOT + 1.1.1-SNAPSHOT 4.1.58.Final 1.1.7