com.iohao.game.bolt.broker.client.BrokerClientStartup Maven / Gradle / Ivy
/*
* ioGame
* Copyright (C) 2021 - present 渔民小镇 ([email protected]、[email protected]) . 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 .
*/
package com.iohao.game.bolt.broker.client;
import com.iohao.game.action.skeleton.core.BarSkeleton;
import com.iohao.game.bolt.broker.core.client.*;
import com.iohao.game.bolt.broker.core.common.IoGameGlobalConfig;
import com.iohao.game.common.kit.NetworkKit;
/**
* BoltBrokerClient 的配置
*
* @author 渔民小镇
* @date 2022-04-29
*/
public sealed interface BrokerClientStartup permits AbstractBrokerClientStartup {
/**
* 初始化 业务框架
*
* 如果不需要业务框架的逻辑服,使用下面的示例代码
* {@code return BarSkeleton.newBuilder().build();}
*
*
* @return 业务框架
*/
BarSkeleton createBarSkeleton();
/**
* BoltBrokerClient 构建器
*
*
* see {@link BrokerClient#newBuilder()}
*
* see {@link AbstractBrokerClientStartup#setBrokerClientBuilder(BrokerClientBuilder)}
*
*
* @return 构建器
*/
BrokerClientBuilder createBrokerClientBuilder();
/**
* 初始化 远程连接地址 (连接到游戏网关的地址)
*
* 地址格式: ip:port
* 如: 127.0.0.1:10200
*
* 默认方法中提供了本地连接 broker(游戏网关) 的地址
* 如果不能满足业务的,可以重写此方法
*
*
* @return 远程连接地址
*/
default BrokerAddress createBrokerAddress() {
// 类似 127.0.0.1 ,但这里是本机的 ip
String localIp = NetworkKit.LOCAL_IP;
// broker (游戏网关)默认端口
int brokerPort = IoGameGlobalConfig.brokerPort;
return new BrokerAddress(localIp, brokerPort);
}
/**
* 添加连接处理器
*
* see:
* {@link com.alipay.remoting.ConnectionEventType#CLOSE}
* {@link com.alipay.remoting.ConnectionEventType#CONNECT}
*
* 默认方法中提供了一些比较通用的连接处理器,如果不能满足业务的,可以重写此方法
*
*
* @param brokerClientBuilder boltBrokerClientBuilder
*/
void connectionEventProcessor(BrokerClientBuilder brokerClientBuilder);
/**
* 注册用户处理器
*
* 默认方法中提供了一些比较通用的用户处理器,如果不能满足业务的,可以重写此方法
*
*
* @param brokerClientBuilder boltBrokerClientBuilder
*/
void registerUserProcessor(BrokerClientBuilder brokerClientBuilder);
/**
* BrokerClient 启动后的钩子方法
*
* 如果有需要,可以在这里 保存一下 BrokerClient 的引用
*
* 框架会在逻辑服启动时,在 {@link BrokerClientHelper} 中保存了一份 BrokerClient 的引用
*
*
* @param brokerClient BrokerClient
*/
default void startupSuccess(BrokerClient brokerClient) {
// 对于 brokerClient 的引用使用,建议用 BrokerClientHolder
String id = brokerClient.getId();
BrokerClients.put(id, brokerClient);
}
}