增加APP_GLOBAL_IOGROUP功能
This commit is contained in:
@@ -96,11 +96,27 @@ public final class Application {
|
|||||||
*/
|
*/
|
||||||
public static final String RESNAME_APP_EXECUTOR = "APP_EXECUTOR";
|
public static final String RESNAME_APP_EXECUTOR = "APP_EXECUTOR";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前进程的客共享AsyncGroup, 有且只有一个server节点NodeServer此字段值才有效
|
||||||
|
*
|
||||||
|
* @since 2.8.0
|
||||||
|
*/
|
||||||
|
public static final String RESNAME_APP_GLOBAL_IOGROUP = "APP_GLOBAL_IOGROUP";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前进程的客户端组, 类型:AsyncGroup
|
* 当前进程的客户端组, 类型:AsyncGroup
|
||||||
*
|
*
|
||||||
* @since 2.3.0
|
* @since 2.8.0
|
||||||
*/
|
*/
|
||||||
|
public static final String RESNAME_APP_CLIENT_IOGROUP = "APP_CLIENT_IOGROUP";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用RESNAME_APP_CLIENT_IOGROUP代替
|
||||||
|
*
|
||||||
|
* @since 2.3.0
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Deprecated(since = "2.8.0")
|
||||||
public static final String RESNAME_APP_CLIENT_ASYNCGROUP = "APP_CLIENT_ASYNCGROUP";
|
public static final String RESNAME_APP_CLIENT_ASYNCGROUP = "APP_CLIENT_ASYNCGROUP";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,6 +178,9 @@ public final class Application {
|
|||||||
//配置项里的group信息, 注意: 只给SNCP使用
|
//配置项里的group信息, 注意: 只给SNCP使用
|
||||||
private final SncpRpcGroups sncpRpcGroups = new SncpRpcGroups();
|
private final SncpRpcGroups sncpRpcGroups = new SncpRpcGroups();
|
||||||
|
|
||||||
|
//
|
||||||
|
private final AsyncIOGroup globalAsyncGroup;
|
||||||
|
|
||||||
//给客户端使用,包含SNCP客户端、自定义数据库客户端连接池
|
//给客户端使用,包含SNCP客户端、自定义数据库客户端连接池
|
||||||
private final AsyncIOGroup clientAsyncGroup;
|
private final AsyncIOGroup clientAsyncGroup;
|
||||||
|
|
||||||
@@ -578,7 +597,17 @@ public final class Application {
|
|||||||
this.resourceFactory.register(RESNAME_APP_EXECUTOR, Executor.class, this.workExecutor);
|
this.resourceFactory.register(RESNAME_APP_EXECUTOR, Executor.class, this.workExecutor);
|
||||||
this.resourceFactory.register(RESNAME_APP_EXECUTOR, ExecutorService.class, this.workExecutor);
|
this.resourceFactory.register(RESNAME_APP_EXECUTOR, ExecutorService.class, this.workExecutor);
|
||||||
|
|
||||||
this.clientAsyncGroup = new AsyncIOGroup("Redkale-DefaultClient-IOThread-%s", clientExecutor, bufferCapacity, bufferPoolSize).skipClose(true);
|
if (config.getAnyValues("server").length < 2) { //只存在一个server节点
|
||||||
|
this.globalAsyncGroup = new AsyncIOGroup("Redkale-Global-IOThread-%s", workExecutor, bufferCapacity, bufferPoolSize).skipClose(true);
|
||||||
|
this.resourceFactory.register(RESNAME_APP_GLOBAL_IOGROUP, AsyncGroup.class, this.globalAsyncGroup);
|
||||||
|
this.resourceFactory.register(RESNAME_APP_GLOBAL_IOGROUP, AsyncIOGroup.class, this.globalAsyncGroup);
|
||||||
|
this.clientAsyncGroup = this.globalAsyncGroup;
|
||||||
|
} else {
|
||||||
|
this.globalAsyncGroup = null;
|
||||||
|
this.clientAsyncGroup = new AsyncIOGroup("Redkale-DefaultClient-IOThread-%s", clientExecutor, bufferCapacity, bufferPoolSize).skipClose(true);
|
||||||
|
}
|
||||||
|
this.resourceFactory.register(RESNAME_APP_CLIENT_IOGROUP, AsyncGroup.class, this.clientAsyncGroup);
|
||||||
|
this.resourceFactory.register(RESNAME_APP_CLIENT_IOGROUP, AsyncIOGroup.class, this.clientAsyncGroup);
|
||||||
this.resourceFactory.register(RESNAME_APP_CLIENT_ASYNCGROUP, AsyncGroup.class, this.clientAsyncGroup);
|
this.resourceFactory.register(RESNAME_APP_CLIENT_ASYNCGROUP, AsyncGroup.class, this.clientAsyncGroup);
|
||||||
|
|
||||||
this.excludelibs = excludelib0;
|
this.excludelibs = excludelib0;
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.atomic.LongAdder;
|
import java.util.concurrent.atomic.LongAdder;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import org.redkale.annotation.Resource;
|
||||||
import org.redkale.boot.Application;
|
import org.redkale.boot.Application;
|
||||||
|
import static org.redkale.boot.Application.RESNAME_APP_GLOBAL_IOGROUP;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +32,7 @@ class AsyncNioTcpProtocolServer extends ProtocolServer {
|
|||||||
|
|
||||||
private Selector selector;
|
private Selector selector;
|
||||||
|
|
||||||
|
@Resource(name = RESNAME_APP_GLOBAL_IOGROUP, required = false)
|
||||||
private AsyncIOGroup ioGroup;
|
private AsyncIOGroup ioGroup;
|
||||||
|
|
||||||
private Thread acceptThread;
|
private Thread acceptThread;
|
||||||
@@ -118,8 +121,10 @@ class AsyncNioTcpProtocolServer extends ProtocolServer {
|
|||||||
(pool == null ? safeResponsePool : pool).accept(v);
|
(pool == null ? safeResponsePool : pool).accept(v);
|
||||||
};
|
};
|
||||||
final String threadNameFormat = server.name == null || server.name.isEmpty() ? "Redkale-IOServletThread-%s" : ("Redkale-" + server.name.replace("Server-", "") + "-IOServletThread-%s");
|
final String threadNameFormat = server.name == null || server.name.isEmpty() ? "Redkale-IOServletThread-%s" : ("Redkale-" + server.name.replace("Server-", "") + "-IOServletThread-%s");
|
||||||
this.ioGroup = new AsyncIOGroup(threadNameFormat, null, safeBufferPool);
|
if (this.ioGroup == null) {
|
||||||
this.ioGroup.start();
|
this.ioGroup = new AsyncIOGroup(threadNameFormat, null, safeBufferPool);
|
||||||
|
this.ioGroup.start();
|
||||||
|
}
|
||||||
|
|
||||||
this.acceptThread = new Thread() {
|
this.acceptThread = new Thread() {
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import java.util.concurrent.atomic.LongAdder;
|
|||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.function.*;
|
import java.util.function.*;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import org.redkale.annotation.Resource;
|
||||||
import org.redkale.boot.Application;
|
import org.redkale.boot.Application;
|
||||||
|
import static org.redkale.boot.Application.RESNAME_APP_GLOBAL_IOGROUP;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,6 +34,7 @@ class AsyncNioUdpProtocolServer extends ProtocolServer {
|
|||||||
|
|
||||||
private Selector selector;
|
private Selector selector;
|
||||||
|
|
||||||
|
@Resource(name = RESNAME_APP_GLOBAL_IOGROUP, required = false)
|
||||||
private AsyncIOGroup ioGroup;
|
private AsyncIOGroup ioGroup;
|
||||||
|
|
||||||
private Thread acceptThread;
|
private Thread acceptThread;
|
||||||
@@ -111,8 +114,10 @@ class AsyncNioUdpProtocolServer extends ProtocolServer {
|
|||||||
(pool == null ? safeResponsePool : pool).accept(v);
|
(pool == null ? safeResponsePool : pool).accept(v);
|
||||||
};
|
};
|
||||||
final String threadNameFormat = server.name == null || server.name.isEmpty() ? "Redkale-IOServletThread-%s" : ("Redkale-" + server.name.replace("Server-", "") + "-IOServletThread-%s");
|
final String threadNameFormat = server.name == null || server.name.isEmpty() ? "Redkale-IOServletThread-%s" : ("Redkale-" + server.name.replace("Server-", "") + "-IOServletThread-%s");
|
||||||
this.ioGroup = new AsyncIOGroup(threadNameFormat, null, safeBufferPool);
|
if (this.ioGroup == null) {
|
||||||
this.ioGroup.start();
|
this.ioGroup = new AsyncIOGroup(threadNameFormat, null, safeBufferPool);
|
||||||
|
this.ioGroup.start();
|
||||||
|
}
|
||||||
udpServerChannel.serverChannel.register(this.selector, SelectionKey.OP_READ);
|
udpServerChannel.serverChannel.register(this.selector, SelectionKey.OP_READ);
|
||||||
this.acceptThread = new Thread() {
|
this.acceptThread = new Thread() {
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
|
|||||||
|
|
||||||
protected Properties writeConfProps;
|
protected Properties writeConfProps;
|
||||||
|
|
||||||
@Resource(name = RESNAME_APP_CLIENT_ASYNCGROUP, required = false)
|
@Resource(name = RESNAME_APP_CLIENT_IOGROUP, required = false)
|
||||||
protected AsyncGroup clientAsyncGroup;
|
protected AsyncGroup clientAsyncGroup;
|
||||||
|
|
||||||
//配置<executor threads="0"> APP_EXECUTOR资源为null
|
//配置<executor threads="0"> APP_EXECUTOR资源为null
|
||||||
|
|||||||
Reference in New Issue
Block a user