fix StyleCheck Errors. (#1288)

* fix checkType errors about module hippo4j-threadpool-adapter-web

* fix checkType errors about module hippo4j-threadpool-spring-boot-starter-adapter-web

* fix checkType errors about module hippo4j-threadpool-rpc.
pull/1302/head
Xin Chen 2 years ago committed by GitHub
parent f80f50c82a
commit 95cd53af35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -50,6 +50,9 @@ import javax.servlet.Servlet;
@Configuration(proxyBeanMethods = false)
public class WebThreadPoolHandlerConfiguration {
/**
* embedded tomcat
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({Servlet.class, Tomcat.class, UpgradeProtocol.class})
@ConditionalOnBean(value = ConfigurableTomcatWebServerFactory.class, search = SearchStrategy.CURRENT)
@ -67,6 +70,9 @@ public class WebThreadPoolHandlerConfiguration {
}
}
/**
* embedded jetty
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({Servlet.class, Server.class, Loader.class, WebAppContext.class})
@ConditionalOnBean(value = ConfigurableJettyWebServerFactory.class, search = SearchStrategy.CURRENT)
@ -84,6 +90,9 @@ public class WebThreadPoolHandlerConfiguration {
}
}
/**
* embedded undertow
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({Servlet.class, Undertow.class, SslClientAuthMode.class})
@ConditionalOnBean(value = ConfigurableUndertowWebServerFactory.class, search = SearchStrategy.CURRENT)

@ -55,6 +55,7 @@ public class UndertowWebThreadPoolHandlerSupport implements IWebThreadPoolHandle
this.executor = executor;
}
private final long noRejectCount = -1L;
@Override
public ThreadPoolBaseInfo simpleInfo() {
ThreadPoolBaseInfo poolBaseInfo = new ThreadPoolBaseInfo();
@ -122,7 +123,7 @@ public class UndertowWebThreadPoolHandlerSupport implements IWebThreadPoolHandle
stateInfo.setPeakLoad(peakLoad);
long rejectCount = fieldObject instanceof DynamicThreadPoolExecutor
? ((DynamicThreadPoolExecutor) fieldObject).getRejectCountNum()
: -1L;
: -noRejectCount;
stateInfo.setRejectCount(rejectCount);
stateInfo.setClientLastRefreshTime(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
stateInfo.setTimestamp(System.currentTimeMillis());

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

@ -34,7 +34,8 @@ import java.io.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
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");
}
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);
}
/**
* handler entity
* @param <T>
*/
@Getter
@AllArgsConstructor
class HandlerEntity<T> implements Comparable<HandlerEntity<T>> {

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

@ -84,10 +84,12 @@ public class DefaultResponse implements Response {
@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DefaultResponse that = (DefaultResponse) o;
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;
ChannelFuture future;
Channel channel;
private final int maxPortNum = 65535;
public NettyServerConnection(EventLoopGroup leader, EventLoopGroup worker, List<ChannelHandler> handlers) {
super(handlers);
@ -80,7 +81,7 @@ public class NettyServerConnection extends AbstractNettyHandlerManager implement
@Override
public void bind(ServerPort port) {
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");
}
ServerBootstrap server = new ServerBootstrap();

Loading…
Cancel
Save