f802cd2d1d7437f948a80040bfce24b347db34e4
[bgpcep.git] / bgp / rib-api / src / main / java / org / opendaylight / protocol / bgp / rib / AbstractRIBChangeListener.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.bgp.rib;
9
10 import javax.annotation.concurrent.ThreadSafe;
11
12 import org.opendaylight.protocol.concepts.InitialListenerEvents;
13 import org.opendaylight.protocol.concepts.ListenerRegistration;
14
15 @ThreadSafe
16 public abstract class AbstractRIBChangeListener implements RIBEventListener {
17         @Override
18         synchronized public final void onRIBEvent(final RIBEvent event) {
19                 onRIBEventImpl(event);
20         }
21
22         abstract protected void onRIBEventImpl(final RIBEvent event);
23
24         synchronized public final ListenerRegistration<RIBEventListener> register(final RIB rib) {
25                 InitialListenerEvents<RIBEventListener, RIBEvent> ile = rib.registerListener(this);
26                 for (RIBEvent e : ile.getEvents())
27                         onRIBEvent(e);
28
29                 return ile.getRegistration();
30         }
31 }