yang文件中的notification和实现

在告警开发中很常用到notification机制,notification机制就是我们设计者模式中的观察者模式。
yang文件中的notification的实现

module test-notificat
{
    ///其它实现
    notification test-notifi
    {
        leaf test-leaff
            {
                  type String;
            }
    }
}

编译yang文件会自动生成Listenser接口 TestNotificatListener其继承于NotificationListener

public interface TestNotificatListener implements NotificationListener
{
   void onTestNotificat(); 
}

消息发送方须获取NotificationPublicService服务的实现,通过putNotification( TestNotifi testNotifi)将消息注入NotificationPublicService中实现发布。
消息接受方须获取NotificationService服务的实现,并在bundle启动activator类中,将消息接收类注册到NotificationService中
TestNotificatListener实现类TestNotificatListenerImpl

public class TestNotificatListenerImpl implements TestNotificatListener
{
  @overide
  public void onTestNotificat()
  {
    ///消息接受方业务逻辑
  }
}
public class testActivitor
{
  public static void init(ProviderContext session)
  {
    NotificationService notifiService
                      = session.getService(NotificationService.class);
    notifiService.registerListenerService
            (TestNotificatListener,new TestNotificatListenerImpl());
  }
}

你可能感兴趣的:(yang文件中的notification和实现)