This commit is contained in:
redkale
2024-10-24 16:00:12 +08:00
parent 29ea1eb76b
commit ec17eea1e0
8 changed files with 81 additions and 100 deletions

View File

@@ -470,11 +470,8 @@ public abstract class NodeServer {
}
protected boolean acceptsComponent(Class<? extends Service> serviceImplClass) {
if (Modifier.isAbstract(serviceImplClass.getModifiers())
|| Modifier.isInterface(serviceImplClass.getModifiers())) {
return false;
}
return true;
return !(Modifier.isAbstract(serviceImplClass.getModifiers())
|| Modifier.isInterface(serviceImplClass.getModifiers()));
}
protected boolean interceptComponent(Service service) {

View File

@@ -202,10 +202,7 @@ public abstract class ClusterAgent {
}
}
ClusterEntry entry = new ClusterEntry(ns, protocol, service);
if (entry.serviceName.endsWith(".")) {
return false;
}
return true;
return !entry.serviceName.endsWith(".");
}
protected void afterDeregister(NodeServer ns, String protocol) {

View File

@@ -763,7 +763,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
Type[] ts = ((ParameterizedType) type).getActualTypeArguments();
if (ts.length == 1) {
Type t = ts[0];
if (t == Boolean.class
return t == Boolean.class
|| t == Byte.class
|| t == Short.class
|| t == Character.class
@@ -773,10 +773,7 @@ public abstract class ConvertFactory<R extends Reader, W extends Writer> {
|| t == Double.class
|| t == String.class
|| rootFactory().findEncoder(t) != null
|| ((t instanceof Class) && ((Class) t).isEnum())) {
return true;
}
return false;
|| ((t instanceof Class) && ((Class) t).isEnum());
}
}
return false;

View File

@@ -24,8 +24,6 @@ import org.redkale.util.*;
*/
public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
protected final Class typeClass;
protected final ObjectEncoder<ProtobufWriter, T> objectEncoderSelf;
// 动态字段: protected SimpledCoder xxxSimpledCoder;
@@ -34,7 +32,6 @@ public abstract class ProtobufDynEncoder<T> extends ProtobufObjectEncoder<T> {
protected ProtobufDynEncoder(ProtobufFactory factory, Type type, ProtobufObjectEncoder objectEncoderSelf) {
super((Class) type);
this.typeClass = (Class) type;
this.factory = factory;
this.objectEncoderSelf = objectEncoderSelf;
this.members = objectEncoderSelf.getMembers();

View File

@@ -1305,6 +1305,8 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
});
return;
}
default:
return;
}
}
}

View File

@@ -404,19 +404,17 @@ public abstract class Server<
final ProtocolServer oldServerChannel = this.serverChannel;
ProtocolServer newServerChannel = null;
InetSocketAddress addr0 = addr;
try {
newServerChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader);
this.resourceFactory.inject(newServerChannel);
newServerChannel.open(config);
newServerChannel.bind(addr, backlog);
SocketAddress localAddress = newServerChannel.getLocalAddress();
if (localAddress instanceof InetSocketAddress) {
addr0 = (InetSocketAddress) localAddress;
}
newServerChannel.accept(application, this);
} catch (IOException e) {
throw e;
newServerChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader);
this.resourceFactory.inject(newServerChannel);
newServerChannel.open(config);
newServerChannel.bind(addr, backlog);
SocketAddress localAddress = newServerChannel.getLocalAddress();
if (localAddress instanceof InetSocketAddress) {
addr0 = (InetSocketAddress) localAddress;
}
newServerChannel.accept(application, this);
context.updateServerAddress(addr0);
this.address = context.serverAddress;
this.serverChannel = newServerChannel;

View File

@@ -815,8 +815,6 @@ public class DataJdbcSource extends AbstractDataSqlSource {
int c = Utility.sum(stmt2.executeBatch());
slowLog(s, sqls);
return c;
} catch (SQLException se) {
throw se;
} finally {
conn.offerUpdateStatement(stmt2);
}
@@ -2199,7 +2197,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
conn.setAutoCommit(true);
prestmt = conn.prepareQueryStatement(sql);
final ResultSet set = prestmt.executeQuery();
boolean rs = set.next() ? (set.getInt(1) > 0) : false;
boolean rs = set.next() && (set.getInt(1) > 0);
set.close();
conn.offerQueryStatement(prestmt);
if (info.isLoggable(logger, Level.FINEST, sql)) {

View File

@@ -5118,29 +5118,27 @@ public final class Utility {
// return socket;
// }
//
public static String postHttpContent(String url) throws IOException {
public static String postHttpContent(String url) {
return remoteHttpContent("POST", url, 0, null, null).toString(StandardCharsets.UTF_8);
}
public static String postHttpContent(String url, int timeoutMs) throws IOException {
public static String postHttpContent(String url, int timeoutMs) {
return remoteHttpContent("POST", url, timeoutMs, null, null).toString(StandardCharsets.UTF_8);
}
public static String postHttpContent(String url, String body) throws IOException {
public static String postHttpContent(String url, String body) {
return remoteHttpContent("POST", url, 0, null, body).toString(StandardCharsets.UTF_8);
}
public static String postHttpContent(String url, int timeoutMs, String body) throws IOException {
public static String postHttpContent(String url, int timeoutMs, String body) {
return remoteHttpContent("POST", url, timeoutMs, null, body).toString(StandardCharsets.UTF_8);
}
public static String postHttpContent(String url, Map<String, Serializable> headers, String body)
throws IOException {
public static String postHttpContent(String url, Map<String, Serializable> headers, String body) {
return remoteHttpContent("POST", url, 0, headers, body).toString(StandardCharsets.UTF_8);
}
public static String postHttpContent(String url, int timeoutMs, Map<String, Serializable> headers, String body)
throws IOException {
public static String postHttpContent(String url, int timeoutMs, Map<String, Serializable> headers, String body) {
return remoteHttpContent("POST", url, timeoutMs, headers, body).toString(StandardCharsets.UTF_8);
}
@@ -5171,38 +5169,36 @@ public final class Utility {
return remoteHttpContent("POST", url, timeoutMs, headers, body).toString(charset.name());
}
public static byte[] postHttpBytesContent(String url) throws IOException {
public static byte[] postHttpBytesContent(String url) {
return remoteHttpContent("POST", url, 0, null, null).toByteArray();
}
public static byte[] postHttpBytesContent(String url, int timeoutMs) throws IOException {
public static byte[] postHttpBytesContent(String url, int timeoutMs) {
return remoteHttpContent("POST", url, timeoutMs, null, null).toByteArray();
}
public static byte[] postHttpBytesContent(String url, Map<String, Serializable> headers, String body)
throws IOException {
public static byte[] postHttpBytesContent(String url, Map<String, Serializable> headers, String body) {
return remoteHttpContent("POST", url, 0, headers, body).toByteArray();
}
public static byte[] postHttpBytesContent(String url, int timeoutMs, Map<String, Serializable> headers, String body)
throws IOException {
public static byte[] postHttpBytesContent(
String url, int timeoutMs, Map<String, Serializable> headers, String body) {
return remoteHttpContent("POST", url, timeoutMs, headers, body).toByteArray();
}
public static String getHttpContent(String url) throws IOException {
public static String getHttpContent(String url) {
return remoteHttpContent("GET", url, 0, null, null).toString(StandardCharsets.UTF_8);
}
public static String getHttpContent(String url, int timeoutMs) throws IOException {
public static String getHttpContent(String url, int timeoutMs) {
return remoteHttpContent("GET", url, timeoutMs, null, null).toString(StandardCharsets.UTF_8);
}
public static String getHttpContent(String url, Map<String, Serializable> headers, String body) throws IOException {
public static String getHttpContent(String url, Map<String, Serializable> headers, String body) {
return remoteHttpContent("GET", url, 0, headers, body).toString(StandardCharsets.UTF_8);
}
public static String getHttpContent(String url, int timeoutMs, Map<String, Serializable> headers, String body)
throws IOException {
public static String getHttpContent(String url, int timeoutMs, Map<String, Serializable> headers, String body) {
return remoteHttpContent("GET", url, timeoutMs, headers, body).toString(StandardCharsets.UTF_8);
}
@@ -5225,41 +5221,38 @@ public final class Utility {
return remoteHttpContent("GET", url, timeoutMs, headers, body).toString(charset.name());
}
public static byte[] getHttpBytesContent(String url) throws IOException {
public static byte[] getHttpBytesContent(String url) {
return remoteHttpContent("GET", url, 0, null, null).toByteArray();
}
public static byte[] getHttpBytesContent(String url, int timeoutMs) throws IOException {
public static byte[] getHttpBytesContent(String url, int timeoutMs) {
return remoteHttpContent("GET", url, timeoutMs, null, null).toByteArray();
}
public static byte[] getHttpBytesContent(String url, Map<String, Serializable> headers, String body)
throws IOException {
public static byte[] getHttpBytesContent(String url, Map<String, Serializable> headers, String body) {
return remoteHttpContent("GET", url, 0, headers, body).toByteArray();
}
public static byte[] getHttpBytesContent(String url, int timeoutMs, Map<String, Serializable> headers, String body)
throws IOException {
public static byte[] getHttpBytesContent(
String url, int timeoutMs, Map<String, Serializable> headers, String body) {
return remoteHttpContent("GET", url, timeoutMs, headers, body).toByteArray();
}
public static String remoteHttpContent(HttpClient client, String method, String url, Charset charset)
throws IOException {
public static String remoteHttpContent(HttpClient client, String method, String url, Charset charset) {
return remoteHttpContentAsync(client, method, url, 0, null, null)
.thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset))
.join();
}
public static String remoteHttpContent(HttpClient client, String method, String url, int timeoutMs, Charset charset)
throws IOException {
public static String remoteHttpContent(
HttpClient client, String method, String url, int timeoutMs, Charset charset) {
return remoteHttpContentAsync(client, method, url, timeoutMs, null, null)
.thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset))
.join();
}
public static String remoteHttpContent(
HttpClient client, String method, String url, Charset charset, Map<String, Serializable> headers)
throws IOException {
HttpClient client, String method, String url, Charset charset, Map<String, Serializable> headers) {
return remoteHttpContentAsync(client, method, url, 0, headers, null)
.thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset))
.join();
@@ -5271,8 +5264,7 @@ public final class Utility {
String url,
Charset charset,
Map<String, Serializable> headers,
String body)
throws IOException {
String body) {
return remoteHttpContentAsync(client, method, url, 0, headers, body)
.thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset))
.join();
@@ -5284,8 +5276,7 @@ public final class Utility {
String url,
int timeoutMs,
Charset charset,
Map<String, Serializable> headers)
throws IOException {
Map<String, Serializable> headers) {
return remoteHttpContentAsync(client, method, url, timeoutMs, headers, null)
.thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset))
.join();
@@ -5298,8 +5289,7 @@ public final class Utility {
int timeoutMs,
Charset charset,
Map<String, Serializable> headers,
String body)
throws IOException {
String body) {
return remoteHttpContentAsync(client, method, url, timeoutMs, headers, body)
.thenApply(out -> out.toString(charset == null ? StandardCharsets.UTF_8 : charset))
.join();
@@ -5311,10 +5301,9 @@ public final class Utility {
String url,
Charset charset,
Map<String, Serializable> headers,
String body)
throws IOException {
String body) {
return remoteHttpContentAsync(client, method, url, 0, headers, body)
.thenApply(out -> out.toByteArray())
.thenApply(ByteArrayOutputStream::toByteArray)
.join();
}
@@ -5324,10 +5313,9 @@ public final class Utility {
String url,
int timeoutMs,
Charset charset,
Map<String, Serializable> headers)
throws IOException {
Map<String, Serializable> headers) {
return remoteHttpContentAsync(client, method, url, timeoutMs, headers, null)
.thenApply(out -> out.toByteArray())
.thenApply(ByteArrayOutputStream::toByteArray)
.join();
}
@@ -5338,27 +5326,29 @@ public final class Utility {
int timeoutMs,
Charset charset,
Map<String, Serializable> headers,
String body)
throws IOException {
String body) {
return remoteHttpContentAsync(client, method, url, timeoutMs, headers, body)
.thenApply(out -> out.toByteArray())
.thenApply(ByteArrayOutputStream::toByteArray)
.join();
}
public static ByteArrayOutputStream remoteHttpContent(
String method, String url, Map<String, Serializable> headers, String body) throws IOException {
String method, String url, Map<String, Serializable> headers, String body) {
return remoteHttpContent(method, url, 0, headers, body);
}
public static ByteArrayOutputStream remoteHttpContent(
String method, String url, int timeoutMs, Map<String, Serializable> headers, String body)
throws IOException {
String method, String url, int timeoutMs, Map<String, Serializable> headers, String body) {
return remoteHttpContentAsync(method, url, timeoutMs, headers, body).join();
}
public static ByteArrayOutputStream remoteHttpContent(
HttpClient client, String method, String url, int timeoutMs, Map<String, Serializable> headers, String body)
throws IOException {
HttpClient client,
String method,
String url,
int timeoutMs,
Map<String, Serializable> headers,
String body) {
return remoteHttpContentAsync(client, method, url, timeoutMs, headers, body)
.join();
}
@@ -5548,38 +5538,40 @@ public final class Utility {
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(String url) {
return remoteHttpContentAsync("POST", url, 0, null, null).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("POST", url, 0, null, null).thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(
String url, Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("POST", url, 0, null, null, respHeaders).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("POST", url, 0, null, null, respHeaders)
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(String url, int timeoutMs) {
return remoteHttpContentAsync("POST", url, timeoutMs, null, null).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("POST", url, timeoutMs, null, null).thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(
String url, int timeoutMs, Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("POST", url, timeoutMs, null, null, respHeaders)
.thenApply(out -> out.toByteArray());
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(
String url, Map<String, Serializable> headers, String body) {
return remoteHttpContentAsync("POST", url, 0, headers, body).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("POST", url, 0, headers, body).thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(
String url, Map<String, Serializable> headers, String body, Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("POST", url, 0, headers, body, respHeaders)
.thenApply(out -> out.toByteArray());
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(
String url, int timeoutMs, Map<String, Serializable> headers, String body) {
return remoteHttpContentAsync("POST", url, timeoutMs, headers, body).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("POST", url, timeoutMs, headers, body)
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> postHttpBytesContentAsync(
@@ -5589,7 +5581,7 @@ public final class Utility {
String body,
Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("POST", url, timeoutMs, headers, body, respHeaders)
.thenApply(out -> out.toByteArray());
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<String> getHttpContentAsync(String url) {
@@ -5718,37 +5710,40 @@ public final class Utility {
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(String url) {
return remoteHttpContentAsync("GET", url, 0, null, null).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("GET", url, 0, null, null).thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(
String url, Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("GET", url, 0, null, null, respHeaders).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("GET", url, 0, null, null, respHeaders)
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(String url, int timeoutMs) {
return remoteHttpContentAsync("GET", url, timeoutMs, null, null).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("GET", url, timeoutMs, null, null).thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(
String url, int timeoutMs, Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("GET", url, timeoutMs, null, null, respHeaders)
.thenApply(out -> out.toByteArray());
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(
String url, Map<String, Serializable> headers, String body) {
return remoteHttpContentAsync("GET", url, 0, headers, body).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("GET", url, 0, headers, body).thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(
String url, Map<String, Serializable> headers, String body, Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("GET", url, 0, headers, body, respHeaders).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("GET", url, 0, headers, body, respHeaders)
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(
String url, int timeoutMs, Map<String, Serializable> headers, String body) {
return remoteHttpContentAsync("GET", url, timeoutMs, headers, body).thenApply(out -> out.toByteArray());
return remoteHttpContentAsync("GET", url, timeoutMs, headers, body)
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(
@@ -5758,7 +5753,7 @@ public final class Utility {
String body,
Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync("GET", url, timeoutMs, headers, body, respHeaders)
.thenApply(out -> out.toByteArray());
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<byte[]> getHttpBytesContentAsync(
@@ -5769,7 +5764,7 @@ public final class Utility {
String body,
Map<String, Serializable> respHeaders) {
return remoteHttpContentAsync(client, "GET", url, timeoutMs, headers, body, respHeaders)
.thenApply(out -> out.toByteArray());
.thenApply(ByteArrayOutputStream::toByteArray);
}
public static CompletableFuture<ByteArrayOutputStream> remoteHttpContentAsync(