zoukankan      html  css  js  c++  java
  • Spring DM所提供的Bundle监听接口OsgiBundleApplicationContextListener

    通过使用Spring DM提供的监听接口,我们可以更好的对服务进行管控,其实该接口也非常简单就能使用上,只要自定义一个类实现OsgiBundleApplicationContextListener接口,实现onOsgiApplicationEvent方法,并将自定义类注册成OSGI服务,通过判断event的事件类型来执行相应逻辑处理,同时也可以获取到当前监听的Bundle,从而达到更深层次的监控,

    public class ListenerDemo implements OsgiBundleApplicationContextListener{
    
        @Override
        public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {
            
            String bundleName = event.getBundle().getSymbolicName();
            
            if (event instanceof OsgiBundleContextRefreshedEvent) {//Spring上下文创建成功事件
                System.out.println("服务启动");
            }else if (event instanceof OsgiBundleContextClosedEvent) {//Spring上下文销毁事件
                System.out.println("服务关闭");
                
            }
        }
    }
    <bean id="ListenerDemo" class="com.sample.service.listener.ListenerDemo"></bean>
        
        <osgi:service ref="ListenerDemo" interface="org.springframework.osgi.context.event.OsgiBundleApplicationContextListener"/>
  • 相关阅读:
    Python中matplotlib模块的简单使用
    Python中numpy模块的简单使用
    TensorFlow入门(矩阵基础)
    TensorFlow入门(常量变量及其基本运算)
    计算机视觉入门
    菜得一P!
    Hdu2097 Sky数
    Hdu2099 整除的尾数
    Hdu2098 分拆素数和
    Linux下用Bash语言实现简单排序的功能
  • 原文地址:https://www.cnblogs.com/xufan/p/6407492.html
Copyright © 2011-2022 走看看