fix checkType errors about module hippo4j-threadpool-rpc.

pull/1288/head
DDDreame 2 years ago
parent 52131d282a
commit 2ca2c392a5

@ -49,6 +49,8 @@ public class NettyClientConnection implements ClientConnection {
* Obtain the connection timeout period. The default value is 30s * Obtain the connection timeout period. The default value is 30s
*/ */
long timeout = 30000L; long timeout = 30000L;
final int nanosPerMilliSecond = 1000000;
EventLoopGroup worker = new NioEventLoopGroup(); EventLoopGroup worker = new NioEventLoopGroup();
NettyConnectPool connectionPool; NettyConnectPool connectionPool;
ChannelFuture future; ChannelFuture future;
@ -74,7 +76,7 @@ public class NettyClientConnection implements ClientConnection {
} }
// Wait for execution to complete // Wait for execution to complete
ResultHolder.putThread(key, Thread.currentThread()); ResultHolder.putThread(key, Thread.currentThread());
LockSupport.parkNanos(timeout() * 1000000); LockSupport.parkNanos(timeout() * nanosPerMilliSecond);
response = ResultHolder.get(key); response = ResultHolder.get(key);
if (response == null) { if (response == null) {
throw new TimeOutException("Timeout waiting for server-side response"); throw new TimeOutException("Timeout waiting for server-side response");

@ -34,7 +34,8 @@ import java.io.Serializable;
*/ */
public class NettyEncoder extends MessageToByteEncoder<Serializable> { public class NettyEncoder extends MessageToByteEncoder<Serializable> {
private static final byte[] BYTE = new byte[4]; private static final int BYTE_LENGTH = 4;
private static final byte[] BYTE = new byte[BYTE_LENGTH];
@Override @Override
protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception {
@ -49,6 +50,6 @@ public class NettyEncoder extends MessageToByteEncoder<Serializable> {
throw new CoderException("The encoding is abnormal, which may be caused by the transfer object being unable to be serialized"); throw new CoderException("The encoding is abnormal, which may be caused by the transfer object being unable to be serialized");
} }
int endIndex = out.writerIndex(); int endIndex = out.writerIndex();
out.setInt(startIndex, endIndex - startIndex - 4); out.setInt(startIndex, endIndex - startIndex - BYTE_LENGTH);
} }
} }

@ -73,6 +73,10 @@ public interface HandlerManager<T> {
return new HandlerEntity<>(order, handler, name); return new HandlerEntity<>(order, handler, name);
} }
/**
* handler entity
* @param <T>
*/
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
class HandlerEntity<T> implements Comparable<HandlerEntity<T>> { class HandlerEntity<T> implements Comparable<HandlerEntity<T>> {

@ -71,10 +71,12 @@ public final class DefaultRequest implements Request {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o) {
return true; return true;
if (o == null || getClass() != o.getClass()) }
if (o == null || getClass() != o.getClass()) {
return false; return false;
}
DefaultRequest that = (DefaultRequest) o; DefaultRequest that = (DefaultRequest) o;
return Objects.equals(key, that.key) return Objects.equals(key, that.key)
&& Objects.equals(className, that.className) && Objects.equals(className, that.className)

@ -84,10 +84,12 @@ public class DefaultResponse implements Response {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) if (this == o) {
return true; return true;
if (o == null || getClass() != o.getClass()) }
if (o == null || getClass() != o.getClass()) {
return false; return false;
}
DefaultResponse that = (DefaultResponse) o; DefaultResponse that = (DefaultResponse) o;
return Objects.equals(key, that.key) && Objects.equals(cls, that.cls); return Objects.equals(key, that.key) && Objects.equals(cls, that.cls);
} }

@ -56,6 +56,7 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement
Class<? extends ServerChannel> socketChannelCls = NioServerSocketChannel.class; Class<? extends ServerChannel> socketChannelCls = NioServerSocketChannel.class;
ChannelFuture future; ChannelFuture future;
Channel channel; Channel channel;
private final int maxPortNum = 65535;
public NettyServerConnection(EventLoopGroup leader, EventLoopGroup worker, List<ChannelHandler> handlers) { public NettyServerConnection(EventLoopGroup leader, EventLoopGroup worker, List<ChannelHandler> handlers) {
super(handlers); super(handlers);
@ -80,7 +81,7 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement
@Override @Override
public void bind(ServerPort port) { public void bind(ServerPort port) {
int serverPort = port.getPort(); int serverPort = port.getPort();
if (serverPort < 0 || serverPort > 65535) { if (serverPort < 0 || serverPort > maxPortNum) {
throw new ConnectionException("The port number " + serverPort + " is outside 0~65535, which is not a legal port number"); throw new ConnectionException("The port number " + serverPort + " is outside 0~65535, which is not a legal port number");
} }
ServerBootstrap server = new ServerBootstrap(); ServerBootstrap server = new ServerBootstrap();

Loading…
Cancel
Save