sncp
This commit is contained in:
@@ -32,6 +32,7 @@ import org.redkale.cluster.spi.HttpClusterRpcClient;
|
|||||||
import org.redkale.cluster.spi.HttpLocalRpcClient;
|
import org.redkale.cluster.spi.HttpLocalRpcClient;
|
||||||
import org.redkale.convert.Convert;
|
import org.redkale.convert.Convert;
|
||||||
import org.redkale.convert.json.*;
|
import org.redkale.convert.json.*;
|
||||||
|
import org.redkale.convert.pb.ProtobufConvert;
|
||||||
import org.redkale.convert.pb.ProtobufFactory;
|
import org.redkale.convert.pb.ProtobufFactory;
|
||||||
import org.redkale.inject.ResourceAnnotationLoader;
|
import org.redkale.inject.ResourceAnnotationLoader;
|
||||||
import org.redkale.inject.ResourceEvent;
|
import org.redkale.inject.ResourceEvent;
|
||||||
@@ -305,12 +306,14 @@ public final class Application {
|
|||||||
this.resourceFactory.register(Environment.class, environment);
|
this.resourceFactory.register(Environment.class, environment);
|
||||||
this.resourceFactory.register(JsonFactory.root());
|
this.resourceFactory.register(JsonFactory.root());
|
||||||
this.resourceFactory.register(ProtobufFactory.root());
|
this.resourceFactory.register(ProtobufFactory.root());
|
||||||
this.resourceFactory.register(JsonFactory.root().getConvert());
|
JsonConvert jsonConvert = JsonFactory.root().getConvert();
|
||||||
this.resourceFactory.register(ProtobufFactory.root().getConvert());
|
jsonConvert.offerWriter(jsonConvert.pollWriter());
|
||||||
this.resourceFactory.register(
|
this.resourceFactory.register(jsonConvert);
|
||||||
"jsonconvert", Convert.class, JsonFactory.root().getConvert());
|
ProtobufConvert protobufConvert = ProtobufFactory.root().getConvert();
|
||||||
this.resourceFactory.register(
|
protobufConvert.offerWriter(protobufConvert.pollWriter());
|
||||||
"protobufconvert", Convert.class, ProtobufFactory.root().getConvert());
|
this.resourceFactory.register(protobufConvert);
|
||||||
|
this.resourceFactory.register("jsonconvert", Convert.class, jsonConvert);
|
||||||
|
this.resourceFactory.register("protobufconvert", Convert.class, protobufConvert);
|
||||||
JsonFactory.root().registerFieldFuncConsumer(resourceFactory::inject);
|
JsonFactory.root().registerFieldFuncConsumer(resourceFactory::inject);
|
||||||
ProtobufFactory.root().registerFieldFuncConsumer(resourceFactory::inject);
|
ProtobufFactory.root().registerFieldFuncConsumer(resourceFactory::inject);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import java.nio.channels.CompletionHandler;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
import org.redkale.annotation.ClassDepends;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.convert.pb.ProtobufConvert;
|
import org.redkale.convert.pb.ProtobufConvert;
|
||||||
import org.redkale.convert.pb.ProtobufWriter;
|
import org.redkale.convert.pb.ProtobufWriter;
|
||||||
@@ -107,6 +108,7 @@ public class SncpRemoteInfo<S extends Service> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 由远程模式的DyncRemoveService调用
|
// 由远程模式的DyncRemoveService调用
|
||||||
|
@ClassDepends
|
||||||
public <T> T remote(final String actionid, final Object... params) {
|
public <T> T remote(final String actionid, final Object... params) {
|
||||||
final SncpRemoteAction action = this.actions.get(actionid);
|
final SncpRemoteAction action = this.actions.get(actionid);
|
||||||
CompletionHandler callbackHandler = null;
|
CompletionHandler callbackHandler = null;
|
||||||
|
|||||||
@@ -1,124 +1,124 @@
|
|||||||
///*
|
/*
|
||||||
// * Copyright (c) 2016-2116 Redkale
|
* Copyright (c) 2016-2116 Redkale
|
||||||
// * All rights reserved.
|
* All rights reserved.
|
||||||
// */
|
*/
|
||||||
//package org.redkale.util;
|
package org.redkale.util;
|
||||||
//
|
|
||||||
//import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
//import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
//import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
//import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
//import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
//import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// *
|
*
|
||||||
// * @author zhangjx
|
* @author zhangjx
|
||||||
// */
|
*/
|
||||||
//class Jdk21Inners {
|
class Jdk21Inners {
|
||||||
//
|
|
||||||
// static {
|
static {
|
||||||
// // 加载时进行可用性判断
|
// 加载时进行可用性判断
|
||||||
// Thread.currentThread().isVirtual();
|
Thread.currentThread().isVirtual();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// private Jdk21Inners() {
|
private Jdk21Inners() {
|
||||||
// // do nothing
|
// do nothing
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static Executor createExecutor() {
|
public static Executor createExecutor() {
|
||||||
// return new VirtualExecutor();
|
return new VirtualExecutor();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static Function<String, ExecutorService> createPoolFunction() {
|
public static Function<String, ExecutorService> createPoolFunction() {
|
||||||
// return new VirtualPoolFunction();
|
return new VirtualPoolFunction();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static Function<Supplier, ThreadLocal> createThreadLocalFunction() {
|
public static Function<Supplier, ThreadLocal> createThreadLocalFunction() {
|
||||||
// return new VirtualThreadLocal(() -> null);
|
return new VirtualThreadLocal(() -> null);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public static Function<String, ThreadFactory> createThreadFactoryFunction() {
|
public static Function<String, ThreadFactory> createThreadFactoryFunction() {
|
||||||
// return new VirtualThreadFactory("");
|
return new VirtualThreadFactory("");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// static class VirtualExecutor implements Executor {
|
static class VirtualExecutor implements Executor {
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void execute(Runnable t) {
|
public void execute(Runnable t) {
|
||||||
// Thread.ofVirtual().name("Redkale-VirtualThread").start(t);
|
Thread.ofVirtual().name("Redkale-VirtualThread").start(t);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// static class VirtualPoolFunction implements Function<String, ExecutorService> {
|
static class VirtualPoolFunction implements Function<String, ExecutorService> {
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public ExecutorService apply(String threadNameFormat) {
|
public ExecutorService apply(String threadNameFormat) {
|
||||||
// final ThreadFactory factory = Thread.ofVirtual().factory();
|
final ThreadFactory factory = Thread.ofVirtual().factory();
|
||||||
// final String threadName = String.format(threadNameFormat, "Virtual");
|
final String threadName = String.format(threadNameFormat, "Virtual");
|
||||||
// return Executors.newThreadPerTaskExecutor(r -> {
|
return Executors.newThreadPerTaskExecutor(r -> {
|
||||||
// Thread t = factory.newThread(r);
|
Thread t = factory.newThread(r);
|
||||||
// t.setName(threadName);
|
t.setName(threadName);
|
||||||
// return t;
|
return t;
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// static class VirtualThreadLocal<T> extends ThreadLocal<T> implements Function<Supplier<T>, ThreadLocal<T>> {
|
static class VirtualThreadLocal<T> extends ThreadLocal<T> implements Function<Supplier<T>, ThreadLocal<T>> {
|
||||||
//
|
|
||||||
// private final Supplier<T> supplier;
|
private final Supplier<T> supplier;
|
||||||
//
|
|
||||||
// public VirtualThreadLocal(Supplier<T> supplier) {
|
public VirtualThreadLocal(Supplier<T> supplier) {
|
||||||
// this.supplier = supplier;
|
this.supplier = supplier;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public ThreadLocal<T> apply(Supplier<T> supplier) {
|
public ThreadLocal<T> apply(Supplier<T> supplier) {
|
||||||
// return new VirtualThreadLocal<>(supplier);
|
return new VirtualThreadLocal<>(supplier);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// protected T initialValue() {
|
protected T initialValue() {
|
||||||
// return supplier.get();
|
return supplier.get();
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void set(T value) {
|
public void set(T value) {
|
||||||
// Thread t = Thread.currentThread();
|
Thread t = Thread.currentThread();
|
||||||
// if (!t.isVirtual()) {
|
if (!t.isVirtual()) {
|
||||||
// super.set(value);
|
super.set(value);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public T get() {
|
public T get() {
|
||||||
// Thread t = Thread.currentThread();
|
Thread t = Thread.currentThread();
|
||||||
// return t.isVirtual() ? initialValue() : super.get();
|
return t.isVirtual() ? initialValue() : super.get();
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// static class VirtualThreadFactory implements ThreadFactory, Function<String, ThreadFactory> {
|
static class VirtualThreadFactory implements ThreadFactory, Function<String, ThreadFactory> {
|
||||||
//
|
|
||||||
// private final ThreadFactory factory = Thread.ofVirtual().factory();
|
private final ThreadFactory factory = Thread.ofVirtual().factory();
|
||||||
//
|
|
||||||
// private final String name;
|
private final String name;
|
||||||
//
|
|
||||||
// public VirtualThreadFactory(String name) {
|
public VirtualThreadFactory(String name) {
|
||||||
// this.name = name;
|
this.name = name;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public ThreadFactory apply(String name) {
|
public ThreadFactory apply(String name) {
|
||||||
// return new VirtualThreadFactory(name);
|
return new VirtualThreadFactory(name);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public Thread newThread(Runnable r) {
|
public Thread newThread(Runnable r) {
|
||||||
// Thread t = factory.newThread(r);
|
Thread t = factory.newThread(r);
|
||||||
// if (name != null) {
|
if (name != null) {
|
||||||
// t.setName(name);
|
t.setName(name);
|
||||||
// }
|
}
|
||||||
// return t;
|
return t;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,6 @@ public class SncpSleepTest {
|
|||||||
System.out.println("耗时: " + e + " ms");
|
System.out.println("耗时: " + e + " ms");
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
workExecutor.shutdown();
|
workExecutor.shutdown();
|
||||||
Assertions.assertTrue(e < 660);
|
Assertions.assertTrue(e < 600);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user