apache Ignite 节点生命周期事件例子
2023-04-18 14:50:17 时间
例子代码位置
https://github.com/lilihongjava/ignite_examples/tree/main/ignite-02
节点生命周期事件介绍
生命周期事件可以在节点生命周期的不同阶段执行自定义代码。
共有4个生命周期事件:
- BEFORE_NODE_START:Ignite节点的启动程序初始化之前调用;
- AFTER_NODE_START:Ignite节点启动之后调用;
- BEFORE_NODE_STOP:Ignite节点的停止程序初始化之前调用;
- AFTER_NODE_STOP:Ignite节点停止之后调用。
以下为添加一个自定义生命周期事件监听器的步骤
配置文件
IgniteConfiguration下添加自定义的类MyLifecycleBean
<bean abstract="true" id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<!-- Set to true to enable distributed class loading for examples, default is false. -->
<property name="peerClassLoadingEnabled" value="true"/>
<!-- 节点生命周期 -->
<property name="lifecycleBeans">
<list>
<bean class="org.lovelife110.example.MyLifecycleBean"/>
</list>
</property>
</bean>
MyLifecycleBean自定义类
实现LifecycleBean 接口,通过LifecycleEventType 拿到4个生命周期事件
public class MyLifecycleBean implements LifecycleBean {
@IgniteInstanceResource
public Ignite ignite;
@Override
public void onLifecycleEvent(LifecycleEventType evt) {
if (evt == LifecycleEventType.BEFORE_NODE_START) {
System.out.format("Ignite节点的启动程序初始化之前调用;
");
} else if (evt == LifecycleEventType.AFTER_NODE_START) {
System.out.format("Ignite节点启动之后调用。
");
System.out.format("Ignite节点(consistentId = %s) 启动之后调用;
", ignite.cluster().node().consistentId());
} else if (evt == LifecycleEventType.BEFORE_NODE_STOP) {
System.out.format("Ignite节点的停止程序初始化之前调用。
");
} else if (evt == LifecycleEventType.AFTER_NODE_STOP) {
System.out.format("Ignite节点停止之后调用。
");
}
}
}
启动测试
public static void main(String[] args) throws IgniteException {
Ignite ignite = Ignition.start("example-ignite.xml");
ignite.close();
}
结果日志如下:
Ignite节点的启动程序初始化之前调用;
[17:00:28] Configured plugins:
[17:00:28] ^-- None
[17:00:28]
[17:00:28] Configured failure handler: [hnd=StopNodeOrHaltFailureHandler [tryStop=false, timeout=0, super=AbstractFailureHandler [ignoredFailureTypes=UnmodifiableSet [SYSTEM_WORKER_BLOCKED, SYSTEM_CRITICAL_OPERATION_TIMEOUT]]]]
[17:00:28] Message queue limit is set to 0 which may lead to potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes due to message queues growth on sender and receiver sides.
[17:00:47] Security status [authentication=off, sandbox=off, tls/ssl=off]
[17:01:16] Data Regions Started: 4
[17:01:16] ^-- sysMemPlc region [type=internal, persistence=false, lazyAlloc=false,
[17:01:16] ... initCfg=40MB, maxCfg=100MB, usedRam=0MB, freeRam=100%, allocRam=40MB]
[17:01:16] ^-- default region [type=default, persistence=false, lazyAlloc=true,
[17:01:16] ... initCfg=256MB, maxCfg=3247MB, usedRam=0MB, freeRam=100%, allocRam=0MB]
[17:01:16] ^-- TxLog region [type=internal, persistence=false, lazyAlloc=false,
[17:01:16] ... initCfg=40MB, maxCfg=100MB, usedRam=0MB, freeRam=100%, allocRam=40MB]
[17:01:16] ^-- volatileDsMemPlc region [type=user, persistence=false, lazyAlloc=true,
[17:01:16] ... initCfg=40MB, maxCfg=100MB, usedRam=0MB, freeRam=100%, allocRam=0MB]
Ignite节点启动之后调用。
Ignite节点(consistentId = 0:0:0:0:0:0:0:1,10.1.3.201,127.0.0.1,192.168.137.1,192.168.139.1:47500) 启动之后调用;
[17:01:17] Performance suggestions for grid (fix if possible)
[17:01:17] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[17:01:17] ^-- Enable G1 Garbage Collector (add '-XX:+UseG1GC' to JVM options)
[17:01:17] ^-- Specify JVM heap max size (add '-Xmx<size>[g|G|m|M|k|K]' to JVM options)
[17:01:17] ^-- Set max direct memory size if getting 'OOME: Direct buffer memory' (add '-XX:MaxDirectMemorySize=<size>[g|G|m|M|k|K]' to JVM options)
[17:01:17] Refer to this page for more performance suggestions: https://apacheignite.readme.io/docs/jvm-and-system-tuning
[17:01:17]
[17:01:17] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[17:01:17]
[17:01:17] Ignite node started OK (id=f3e79055)
[17:01:17] Topology snapshot [ver=1, locNode=f3e79055, servers=1, clients=0, state=ACTIVE, CPUs=8, offheap=3.2GB, heap=3.5GB]
[17:01:17] ^-- Baseline [id=0, size=1, online=1, offline=0]
Ignite节点的停止程序初始化之前调用。
Ignite节点停止之后调用。
[17:01:17] Ignite node stopped OK [uptime=00:00:00.032]
相关文章
- 谷歌要用SoC代替主板了吗?
- 弹窗广告究竟是从哪里来的?来源就在软件,果断更换后电脑清净了
- 谷歌联手马斯克,低延迟星链云计算下半年可用
- 连肌肉颤动都清晰可见!3D人体模型自动生成算法,一作北大图灵班
- 又一家IT巨头倒下了,不敢相信...
- LibreOffice 已出现 GTK4 工具包支持代码
- 教AI开发软件:IBM开源数据集Project CodeNet,含有1400万个代码示例
- 完善算法技术 规范算法应用(数字时代的文化生活)
- 超胆侠来了!「蝙蝠感知」AI让智能手机听声生成3D图像
- Google网页版黑暗模式已经全面上线 如何开启请看这里
- 当你发现你同事是培训出来的,你会怎么做
- IT程序员的坏习惯有哪些?你中了吗?
- 认识人和鱼的AI,能识别美人鱼吗?阿里CVPR论文因果推理方法解答
- 前馈网络+线性交互层=残差MLP,Facebook纯MLP图像分类架构入场
- 科学家开发新的神经电子系统 可以读取和“操纵”大脑信号
- 美国宣布进入紧急状态!网络攻击,别只看这冰山一角
- AI识图驴唇不对马嘴?Google AI:用交错训练集提升图像描述准确性
- 华人小哥的“黑话”数据集,AI:你连dbq都不懂
- MIT开发能“感知”隐藏物体的机器人:“我们正试图赋予机器人超人的感知力”
- Google十年,我被彻底颠覆了!