diff --git a/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/client/HttpClientHandler.java b/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/client/HttpClientHandler.java index 436f5be..6195476 100644 --- a/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/client/HttpClientHandler.java +++ b/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/client/HttpClientHandler.java @@ -6,7 +6,6 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; /** @@ -14,7 +13,6 @@ * @date 2018/7/19 */ @Slf4j -@AllArgsConstructor @ChannelHandler.Sharable public class HttpClientHandler extends ChannelInboundHandlerAdapter { private Client client; @@ -22,6 +20,11 @@ public class HttpClientHandler extends ChannelInboundHandlerAdapter { private static HttpClientHandler INSTANCE; + private HttpClientHandler(Client client, ClientMessageConverter converter) { + this.client = client; + this.converter = converter; + } + public synchronized static void init(Client client, ClientMessageConverter converter) { if (INSTANCE == null) { INSTANCE = new HttpClientHandler(client, converter); diff --git a/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/server/HttpServerHandler.java b/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/server/HttpServerHandler.java index 1435db9..76240b5 100644 --- a/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/server/HttpServerHandler.java +++ b/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/http/server/HttpServerHandler.java @@ -7,7 +7,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.codec.http.FullHttpRequest; -import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; /** @@ -15,7 +14,6 @@ * @date 2018/7/19 */ @Slf4j -@AllArgsConstructor @ChannelHandler.Sharable public class HttpServerHandler extends SimpleChannelInboundHandler { private Server server; @@ -23,6 +21,11 @@ public class HttpServerHandler extends SimpleChannelInboundHandler { private Client client; - - + + private ToyClientHandler(Client client) { + this.client = client; + } private static ToyClientHandler INSTANCE; public synchronized static void init(Client client) { diff --git a/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/toy/server/ToyServerHandler.java b/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/toy/server/ToyServerHandler.java index a7fcbdc..2f1e30d 100644 --- a/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/toy/server/ToyServerHandler.java +++ b/toy-rpc-core/src/main/java/com/sinjinsong/toy/transport/toy/server/ToyServerHandler.java @@ -7,7 +7,6 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.handler.timeout.IdleStateEvent; -import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import static com.sinjinsong.toy.transport.api.domain.Message.PING; @@ -17,12 +16,15 @@ * Created by SinjinSong on 2017/7/29. * 实际的业务处理器,单例 */ -@AllArgsConstructor @Slf4j @ChannelHandler.Sharable public class ToyServerHandler extends SimpleChannelInboundHandler { private static ToyServerHandler INSTANCE; - + + private ToyServerHandler(Server server) { + this.server = server; + } + public synchronized static void init(Server server) { if(INSTANCE == null) { INSTANCE = new ToyServerHandler(server);