Switch to using ListenerRegistration from yangtools 71/5471/2
authorRobert Varga <rovarga@cisco.com>
Wed, 26 Feb 2014 12:20:22 +0000 (13:20 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 26 Feb 2014 12:24:24 +0000 (13:24 +0100)
Yangtools concepts have been updated to mmatch our ListenerRegistration
semantics, so there's no reason to keep it around. Migrate our code and
remove it from our concepts.

Also remove Immutable interface. It has been deprecated and unused --
again, yangtools concepts carry the equivalent interface.

Change-Id: I28e5b4e06df0e0b39f808768763c341ad166e352
Signed-off-by: Robert Varga <rovarga@cisco.com>
bgp/rib-impl-config/src/main/java/org/opendaylight/controller/config/yang/bgp/rib/impl/RIBImplModule.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGP.java
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPImpl.java
bgp/rib-impl/src/test/java/org/opendaylight/protocol/bgp/rib/impl/BGPImplTest.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/BGPMock.java
bgp/rib-mock/src/main/java/org/opendaylight/protocol/bgp/rib/mock/EventBusRegistration.java
concepts/src/main/java/org/opendaylight/protocol/concepts/Immutable.java [deleted file]
concepts/src/main/java/org/opendaylight/protocol/concepts/ListenerRegistration.java [deleted file]
concepts/src/test/java/org/opendaylight/protocol/concepts/MultiRegistryTest.java
concepts/src/test/java/org/opendaylight/protocol/concepts/SimpleListenerRegistration.java [deleted file]

index b0d653dde2aa68daf5380382f133544877fef79a..2c2e70759bb1dfb1a538906b09498a57a6d2a43b 100644 (file)
@@ -27,11 +27,11 @@ import org.opendaylight.protocol.bgp.rib.impl.BGP;
 import org.opendaylight.protocol.bgp.rib.impl.BGPPeer;
 import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
 import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
-import org.opendaylight.protocol.concepts.ListenerRegistration;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.RibId;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 import com.google.common.base.Preconditions;
 
index 65fe5eabbfe5a4add0725eb7d7cedad53b744060..90433c885990084faa2e909c20ee01ce0a31fffe 100644 (file)
@@ -8,9 +8,9 @@
 package org.opendaylight.protocol.bgp.rib.impl;
 
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
-import org.opendaylight.protocol.concepts.ListenerRegistration;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 /**
  * BGP interface. At this time it only supports listening to changes seen by the backing device, typically a network
index 23db57cfe66c1bbe6565459399877021255b6780..e976596c453e88fde07baa42900d77f0bb601591 100644 (file)
@@ -15,9 +15,10 @@ import java.net.InetSocketAddress;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
-import org.opendaylight.protocol.concepts.ListenerRegistration;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 import com.google.common.base.Preconditions;
 
@@ -40,7 +41,7 @@ public class BGPImpl implements BGP, Closeable {
        @Override
        public ListenerRegistration<BGPSessionListener> registerUpdateListener(final BGPSessionListener listener, final ReconnectStrategyFactory tcpStrategyFactory, final ReconnectStrategy sessionStrategy) {
                final Future<Void> s = this.dispatcher.createReconnectingClient(address, this.proposal.getProposal(), listener, tcpStrategyFactory, sessionStrategy);
-               return new ListenerRegistration<BGPSessionListener>(listener) {
+               return new AbstractListenerRegistration<BGPSessionListener>(listener) {
                        @Override
                        protected void removeRegistration() {
                                s.cancel(true);
index 47b90b7e2fcf58d83022d4de085530bbf6aee9b4..5d4ffebb757919050ddcf52be76d47df12e2ec0d 100644 (file)
@@ -26,12 +26,12 @@ import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionProposal;
-import org.opendaylight.protocol.concepts.ListenerRegistration;
 import org.opendaylight.protocol.framework.NeverReconnectStrategy;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.AsNumber;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 public class BGPImplTest {
 
@@ -63,7 +63,7 @@ public class BGPImplTest {
                                return new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000);
                        }
                }, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000));
-               assertEquals(SimpleSessionListener.class, reg.getListener().getClass());
+               assertEquals(SimpleSessionListener.class, reg.getInstance().getClass());
        }
 
        @After
index d07f5fdf994e8a32e643ae07f0f944722d02da5d..e5c69d2a2509d7d1b2b056a6e2e78b9fc56b2e90 100644 (file)
@@ -21,11 +21,11 @@ import org.opendaylight.protocol.bgp.parser.BGPParsingException;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.BGP;
-import org.opendaylight.protocol.concepts.ListenerRegistration;
 import org.opendaylight.protocol.framework.ReconnectStrategy;
 import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
 import org.opendaylight.protocol.util.ByteArray;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.NotifyBuilder;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 9a516576a2b3dc2d08456989c748288cdb4d30ff..8401b7b723ffdc98bf400cd43c5eeb4ecce6712a 100644 (file)
@@ -13,12 +13,12 @@ import java.util.Set;
 import org.opendaylight.protocol.bgp.parser.BGPSession;
 import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
-import org.opendaylight.protocol.concepts.ListenerRegistration;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Keepalive;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.Open;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.open.bgp.parameters.c.parameters.MultiprotocolCase;
+import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,7 +31,7 @@ import com.google.common.eventbus.Subscribe;
  * This class has @Subscribe annotated methods which receive events from {@link EventBus} . Events are produced by
  * {@link BGPMock}, and each instance notifies exactly one {@link BGPSessionListener}.
  */
-final class EventBusRegistration extends ListenerRegistration<BGPSessionListener> {
+final class EventBusRegistration extends AbstractListenerRegistration<BGPSessionListener> {
 
        private static final Logger LOG = LoggerFactory.getLogger(EventBusRegistration.class);
 
@@ -54,7 +54,7 @@ final class EventBusRegistration extends ListenerRegistration<BGPSessionListener
 
        @Subscribe
        public void onMessage(final Notification message) {
-               sendMessage(this.getListener(), message);
+               sendMessage(this.getInstance(), message);
        }
 
        @Override
diff --git a/concepts/src/main/java/org/opendaylight/protocol/concepts/Immutable.java b/concepts/src/main/java/org/opendaylight/protocol/concepts/Immutable.java
deleted file mode 100644 (file)
index ac9b45f..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.concepts;
-
-/**
- * Marker interface for objects which are immutable. This interface should be used directly on objects, preferably
- * final, which are eligible for the JSR-305 @Immutable annotation and objects implementing this interface are required
- * to abide to interface contract specified by @Immutable. The reason for the existence of this interface is twofold:
- * unlike @Immutable, it is visible at runtime and objects can be quickly checked for compliance using a quick
- * 'instanceof' check. This is useful for code which needs to capture a point-in-time snapshot of otherwise unknown
- * objects -- a typical example being logging/tracing systems. Such systems would normally have to rely on serializing
- * the object to get a stable checkpoint. Objects marked with this interface are guaranteed to remain stable, thus
- * already being a checkpoint for all intents and purposes, so aside from retaining a reference no further action on
- * them is necessary.
- * 
- * @deprecated Use {@link org.opendaylight.yangtools.concepts.Immutable} instead
- */
-@Deprecated
-public interface Immutable {
-
-}
diff --git a/concepts/src/main/java/org/opendaylight/protocol/concepts/ListenerRegistration.java b/concepts/src/main/java/org/opendaylight/protocol/concepts/ListenerRegistration.java
deleted file mode 100644 (file)
index d1694a4..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.concepts;
-
-import java.util.EventListener;
-
-import javax.annotation.concurrent.ThreadSafe;
-
-import com.google.common.base.Preconditions;
-
-/**
- * An interface representing a listener registration. Objects offering the ability to register listener should return an
- * implementation of this interface upon successful registration. The users are required to call #close() before losing
- * the reference to that object.
- * 
- * @param <T> template reference to associated EventListener implementation
- */
-@ThreadSafe
-public abstract class ListenerRegistration<T extends EventListener> extends AbstractRegistration {
-
-       private final T listener;
-
-       protected ListenerRegistration(final T listener) {
-               this.listener = Preconditions.checkNotNull(listener);
-       }
-
-       /**
-        * Access the listener object associated with this registration.
-        * 
-        * @return Associated listener.
-        */
-       public final T getListener() {
-               return this.listener;
-       }
-}
index 75c05a433f2ec3e40f319f9a16f76fbd9d9efb99..f6c87a10f2fc416dc245e141ec1c6606f032d9fa 100644 (file)
@@ -8,9 +8,6 @@
 package org.opendaylight.protocol.concepts;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.EventListener;
 
 import org.junit.Test;
 
@@ -40,18 +37,4 @@ public class MultiRegistryTest {
                assertEquals(Integer.valueOf(5), registry.get('c'));
        }
 
-       @Test
-       public void testRegistration() {
-               EventListener list1 = new EventListener() {
-               };
-               SimpleListenerRegistration<EventListener> holder = new SimpleListenerRegistration<EventListener>(list1);
-
-               assertEquals(list1, holder.getListener());
-               assertEquals(1, holder.listeners.size());
-
-               holder.removeRegistration();
-
-               assertEquals(0, holder.listeners.size());
-               assertNotNull(holder.getListener());
-       }
 }
diff --git a/concepts/src/test/java/org/opendaylight/protocol/concepts/SimpleListenerRegistration.java b/concepts/src/test/java/org/opendaylight/protocol/concepts/SimpleListenerRegistration.java
deleted file mode 100644 (file)
index 114b4ee..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.concepts;
-
-import java.util.ArrayList;
-import java.util.EventListener;
-import java.util.List;
-
-public class SimpleListenerRegistration<K extends EventListener> extends ListenerRegistration<K> {
-
-       public List<K> listeners = new ArrayList<>();
-
-       protected SimpleListenerRegistration(K listener) {
-               super(listener);
-               this.listeners.add(listener);
-       }
-
-       @Override
-       protected void removeRegistration() {
-               this.listeners.clear();
-       }
-}