Skip to content

Commit

Permalink
🐳 #359 [逻辑服-监听] 增加打印其他进程逻辑服的上线与下线信息
Browse files Browse the repository at this point in the history
  • Loading branch information
iohao committed Aug 19, 2024
1 parent fe4c5b3 commit e6188c4
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ private void settingDefaultValue() {
// 处理分布式事件总线的 listener
this.addListener(new EventBusBrokerClientListener());

if (IoGameGlobalConfig.brokerClientListenerPrintLog) {
this.addListener(PrintBrokerClientListener.me());
}

for (Class<?> removeClass : this.removeProcessorList) {
Iterator<Supplier<UserProcessor<?>>> iterator = this.processorList.iterator();
while (iterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* ioGame
* Copyright (C) 2021 - present 渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
* # iohao.com . 渔民小镇
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.iohao.game.bolt.broker.core.client;

import com.iohao.game.bolt.broker.core.common.processor.listener.BrokerClientListener;
import com.iohao.game.bolt.broker.core.message.BrokerClientModuleMessage;
import lombok.extern.slf4j.Slf4j;

/**
* 打印其他进程的逻辑服信息
*
* @author 渔民小镇
* @date 2024-08-19
* @since 21.15
*/
@Slf4j
final class PrintBrokerClientListener implements BrokerClientListener {
@Override
public void onlineExternal(BrokerClientModuleMessage otherModuleMessage, BrokerClient client) {
if (client.getWithNo() == otherModuleMessage.getWithNo()) {
return;
}

// 其他游戏对外服上线监听。已经在线上的,或者有新上线的游戏对外服都会触发此方法。
log.info("【上线监听】其他进程的游戏对外服信息 {}", otherModuleMessage);
}

@Override
public void offlineExternal(BrokerClientModuleMessage otherModuleMessage, BrokerClient client) {
if (client.getWithNo() == otherModuleMessage.getWithNo()) {
return;
}

// 其他游戏对外服下线监听
log.info("【下线监听】其他进程的游戏对外服信息 {}", otherModuleMessage);
}

@Override
public void onlineLogic(BrokerClientModuleMessage otherModuleMessage, BrokerClient client) {
if (client.getWithNo() == otherModuleMessage.getWithNo()) {
return;
}

// 其他游戏逻辑服在线监听。已经在线上的,或者有新上线的游戏逻辑服都会触发此方法
log.info("【上线监听】其他进程的游戏逻辑服信息 {}", otherModuleMessage);
}

@Override
public void offlineLogic(BrokerClientModuleMessage otherModuleMessage, BrokerClient client) {
if (client.getWithNo() == otherModuleMessage.getWithNo()) {
return;
}

// 其他游戏逻辑服下线监听
log.info("【下线监听】其他进程的游戏逻辑服信息 {}", otherModuleMessage);
}

private PrintBrokerClientListener() {
}

public static PrintBrokerClientListener me() {
return Holder.ME;
}

/** 通过 JVM 的类加载机制, 保证只加载一次 (singleton) */
private static class Holder {
static final PrintBrokerClientListener ME = new PrintBrokerClientListener();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class IoGameGlobalConfig {
public boolean brokerClusterFixedRateLog;
/** true 表示开启 traceId 特性 */
public boolean openTraceId;
/** ture 开启逻辑服上线、下线监听日志。 */
public boolean brokerClientListenerPrintLog = true;

@Getter
boolean eventBusLog;
Expand Down

0 comments on commit e6188c4

Please sign in to comment.