Skip to content

Commit

Permalink
🐳 #375 Support for lightweight or embedded Linux distributions;支持轻量级或…
Browse files Browse the repository at this point in the history
…嵌入式 Linux 发行版
  • Loading branch information
iohao committed Sep 28, 2024
1 parent b5b182c commit 7b970dc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.iohao.game.bolt.broker.core.aware.BrokerClientAware;
import com.iohao.game.bolt.broker.core.client.BrokerClient;
import com.iohao.game.common.kit.attr.AttrOptions;
import com.iohao.game.common.kit.system.OsInfo;
import com.iohao.game.external.core.ExternalCoreSetting;
import com.iohao.game.bolt.broker.core.aware.CmdRegionsAware;
import com.iohao.game.external.core.aware.ExternalCoreSettingAware;
Expand All @@ -32,7 +33,12 @@
import com.iohao.game.external.core.hook.internal.IdleProcessSetting;
import com.iohao.game.external.core.micro.MicroBootstrap;
import com.iohao.game.external.core.micro.MicroBootstrapFlow;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOption;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOptionForLinux;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOptionForMac;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOptionForOther;
import com.iohao.game.external.core.session.UserSessions;
import io.netty.channel.epoll.Epoll;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -75,6 +81,9 @@ public final class DefaultExternalCoreSetting implements ExternalCoreSetting {
/** 与 Broker(游戏网关)通信的 client */
@Setter
BrokerClient brokerClient;
/** external netty GroupChannelOption */
@Setter
GroupChannelOption groupChannelOption;

public void inject() {
this.injectObject.forEach(this::aware);
Expand Down Expand Up @@ -133,4 +142,26 @@ public void setUserHook(UserHook userHook) {
this.userHook = userHook;
this.injectObject.add(this.userHook);
}

public GroupChannelOption getGroupChannelOption() {
if (Objects.isNull(this.groupChannelOption)) {
this.groupChannelOption = createGroupChannelOption();
}

return this.groupChannelOption;
}

private GroupChannelOption createGroupChannelOption() {
if (OsInfo.isMac()) {
return new GroupChannelOptionForMac();
}

// #375,Lightweight or embedded Linux distributions may not have fulled I/O multiplexing support
if (OsInfo.isLinux() && Epoll.isAvailable()) {
return new GroupChannelOptionForLinux();
}

// other system nio
return new GroupChannelOptionForOther();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@

import com.iohao.game.action.skeleton.toy.IoGameBanner;
import com.iohao.game.common.consts.IoGameLogName;
import com.iohao.game.common.kit.system.OsInfo;
import com.iohao.game.external.core.micro.MicroBootstrapFlow;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOption;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOptionForLinux;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOptionForMac;
import com.iohao.game.external.core.netty.micro.auto.GroupChannelOptionForOther;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
Expand All @@ -48,7 +44,7 @@ public final class SocketMicroBootstrap extends AbstractMicroBootstrap {
@Override
public void startup() {
// 线程组相关
GroupChannelOption groupChannelOption = createGroupChannelOption();
GroupChannelOption groupChannelOption = this.setting.getGroupChannelOption();
EventLoopGroup bossGroup = groupChannelOption.bossGroup();
EventLoopGroup workerGroup = groupChannelOption.workerGroup();
Class<? extends ServerChannel> channelClass = groupChannelOption.channelClass();
Expand Down Expand Up @@ -76,23 +72,4 @@ public void startup() {
workerGroup.shutdownGracefully();
}
}

private GroupChannelOption createGroupChannelOption() {
// 根据环境自动选择,开发者也可以重写此方法,做些自定义
GroupChannelOption groupChannelOption;

// 根据系统内核来优化
if (OsInfo.isLinux()) {
// linux
groupChannelOption = new GroupChannelOptionForLinux();
} else if (OsInfo.isMac()) {
// mac
groupChannelOption = new GroupChannelOptionForMac();
} else {
// other system
groupChannelOption = new GroupChannelOptionForOther();
}

return groupChannelOption;
}
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@
<disruptor.version>3.4.4</disruptor.version>

<!-- JSR-380 bean 验证框架 https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<hibernate-validator.version>7.0.4.Final</hibernate-validator.version>
<hibernate-validator.version>8.0.1.Final</hibernate-validator.version>
<!-- JSR-380 https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api -->
<jakarta.validation-api.version>3.0.2</jakarta.validation-api.version>
<jakarta.validation-api.version>3.1.0</jakarta.validation-api.version>
<!-- JSR-380 https://mvnrepository.com/artifact/org.glassfish/jakarta.el -->
<jakarta.el.version>4.0.2</jakarta.el.version>

<!-- temp spring boot https://mvnrepository.com/artifact/org.springframework/spring-core -->
<spring.version>6.1.12</spring.version>

<!-- slf4j https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<slf4j-api.version>2.0.11</slf4j-api.version>
<slf4j-api.version>2.0.16</slf4j-api.version>
<!-- slf4j https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<logback.version>1.4.14</logback.version>
<!-- lombok 消除冗长的 Java 代码 https://mvnrepository.com/artifact/org.projectlombok/lombok -->
Expand Down

0 comments on commit 7b970dc

Please sign in to comment.