Ask is moving to Stack Overflow and! Please use the "opendaylight" tag on either of these sites. This site is now in Read-Only mode


How to register for event notifications?

asked 2016-11-15 11:45:50 -0700

ahuja gravatar image

My Provider class look like:

public class PahujaProvider implements BindingAwareProvider, AutoCloseable, PacketProcessingListener {

    private static final Logger LOG = LoggerFactory.getLogger(PahujaProvider.class);
    private ListenerRegistration<NotificationListener> listener;
    private List<Registration> registrations;
    private DataBroker dataBroker;
    private PacketProcessingService packetProcessingService;

   public PahujaProvider(DataBroker dataBroker, NotificationProviderService notificaitonService, RpcProviderRegistry rpcProviderRegistry) {
    // TODO Auto-generated constructor stub

    // Store DataBroker for reading/ writing from inventory store
    this.dataBroker = dataBroker;

    // Get access to the packet processing service for making RPC calls
    this.packetProcessingService = rpcProviderRegistry.getRpcService(PacketProcessingService.class);

    //List of registrations to track notifications for both data changed and yand defined registrations
    this.registrations = Lists.newArrayList();

    // Register to recieve notificaitons in case of events
    // first event - packet in

    public void onSessionInitiated(ProviderContext session) {"PahujaProvider Session Initiated");
//      DataBroker db = session.getSALService(DataBroker.class);


    public void close() throws Exception {"PahujaProvider Closed");

    public  void onPacketReceived(PacketReceived packet) {
    LOG.debug("reveived the packet :" + packet.toString());
        System.out.println("packet received");


What should I include in my PahujaModule code to create instance?

public class PahujaModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pahuja.impl.rev141210.AbstractPahujaModule {
    private static final Logger LOG = LoggerFactory.getLogger(PahujaModule.class);

   public PahujaModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
        super(identifier, dependencyResolver);

    public PahujaModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pahuja.impl.rev141210.PahujaModule oldModule, java.lang.AutoCloseable oldInstance) {
        super(identifier, dependencyResolver, oldModule, oldInstance);

    public void customValidation() {
        // add custom validation form module attributes here.

    public java.lang.AutoCloseable createInstance() {


        DataBroker dataBroker = (DataBroker) getDataBrokerDependency();
        RpcProviderRegistry rpcRegistry = getRpcRegistryDependency();
        NotificationProviderService notificationService = getNotificationServiceDependency();

        PahujaProvider provider = new PahujaProvider(getBroker(), getNotificationServiceDependency(), rpcProviderRegistry)
        return provider;



My Code:


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-11-22 06:37:53 -0700

updated 2016-11-22 07:28:56 -0700

Hello @ahuja,

What ODL version do you want to use? If using Boron or master, I strongly recommend not using the config system to inject dependencies, as you're doing in the code shown. Instead you should use blueprint, which is way easier.

Beryllium and previous:

  1. You need to add the NotificationService in the default-config.xml file to inject its instance in the *Module#createInstance() See this example - pretty much the same as your, but using the new interface, not the deprecated one.
  2. In the *Module#createInstance() get the NotificationService dependency See this example - You've done the same thing already
  3. In the provider, use the #registerNotificationListener() from the NotificationService.
  4. Hold the Registration element to close it in the #close() funtion

Boron and after:

To register a notification listener using blueprint, see this wiki

Here is a concrete example with blueprint: 1. Create the bean (that will instantiate your class implementing the *Listener interface) 2. Register the listener using odl:notification-listener

If you really need to be tied to Beryllium or previous version, I'll edit that response with appropriate information.

Hope this helps. Alexis

edit flag offensive delete publish link more


Hi Alexis, I appreciate your help. As of now, I have to stick to the Beryllium version only.

ahuja ( 2016-11-22 07:11:03 -0700 )edit

@ahuja, The issue you're facing has nothing to do with the notification registration itself; you haven't registered the provider within the config system registry. You're missing `getBrokerDependency().registerProvider(provider);` in your *Module#createInstance() before the return statement.

adetalhouet ( 2016-11-22 07:30:58 -0700 )edit

Forget that last comment, I've spoken too fast. You got that right l47 (I was tricked by the indentation)

adetalhouet ( 2016-11-22 07:32:27 -0700 )edit

Based on all this, I'm not actually sure to see what you're missing, can you elaborate on that?

adetalhouet ( 2016-11-22 07:33:17 -0700 )edit

There are errors in the method createInstance(). I am not able to register events. If you clone my github project, and open in some ide like eclipse, you can come to know that there are some fundamental things i am missing. However, if this helps, here are the errors in my next comment:

ahuja ( 2016-11-22 08:13:04 -0700 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-11-15 11:45:50 -0700

Seen: 966 times

Last updated: Nov 22 '16