Magnesium platform upgrade
[lispflowmapping.git] / mappingservice / southbound / src / main / java / org / opendaylight / lispflowmapping / southbound / LispSouthboundPlugin.java
index 6977e60773ff2afe3dc9ebb2fef1b74bef852e7e..6bc70e716799155b0cab62e0cdde2e3880974fc7 100644 (file)
@@ -18,8 +18,6 @@ import io.netty.buffer.ByteBuf;
 import io.netty.buffer.ByteBufUtil;
 import io.netty.buffer.PooledByteBufAllocator;
 import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.ChannelOption;
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.epoll.Epoll;
@@ -36,8 +34,6 @@ import java.net.UnknownHostException;
 import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.concurrent.ThreadFactory;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
 import org.opendaylight.lispflowmapping.dsbackend.DataStoreBackEnd;
 import org.opendaylight.lispflowmapping.inmemorydb.HashMapDb;
 import org.opendaylight.lispflowmapping.lisp.type.LispMessage;
@@ -48,6 +44,8 @@ import org.opendaylight.lispflowmapping.southbound.lisp.LispSouthboundHandler;
 import org.opendaylight.lispflowmapping.southbound.lisp.LispXtrSouthboundHandler;
 import org.opendaylight.lispflowmapping.southbound.lisp.cache.MapRegisterCache;
 import org.opendaylight.lispflowmapping.type.sbplugin.IConfigLispSouthboundPlugin;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
@@ -70,7 +68,7 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
     private volatile boolean isMaster = false;
     private volatile String bindingAddress;
     private AuthKeyDb akdb;
-    private MapRegisterCache mapRegisterCache = new MapRegisterCache();
+    private final MapRegisterCache mapRegisterCache = new MapRegisterCache();
     private boolean mapRegisterCacheEnabled;
     private long mapRegisterCacheTimeout;
 
@@ -78,19 +76,19 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
     private final ClusterSingletonServiceProvider clusterSingletonService;
     private LispSouthboundHandler lispSouthboundHandler;
     private LispXtrSouthboundHandler lispXtrSouthboundHandler;
-    private NotificationPublishService notificationPublishService;
+    private final NotificationPublishService notificationPublishService;
     private int numChannels = 1;
-    private Channel[] channel;
+    private final Channel[] channel;
     private Channel xtrChannel;
     private Class channelType;
     private volatile int xtrPort = LispMessage.XTR_PORT_NUM;
     private volatile boolean listenOnXtrPort = false;
-    private ConcurrentLispSouthboundStats statistics = new ConcurrentLispSouthboundStats();
-    private Bootstrap bootstrap = new Bootstrap();
-    private Bootstrap xtrBootstrap = new Bootstrap();
-    private ThreadFactory threadFactory = new DefaultThreadFactory("lisp-sb");
+    private final ConcurrentLispSouthboundStats statistics = new ConcurrentLispSouthboundStats();
+    private final Bootstrap bootstrap = new Bootstrap();
+    private final Bootstrap xtrBootstrap = new Bootstrap();
+    private final ThreadFactory threadFactory = new DefaultThreadFactory("lisp-sb");
     private EventLoopGroup eventLoopGroup;
-    private DataBroker dataBroker;
+    private final DataBroker dataBroker;
     private AuthenticationKeyDataListener authenticationKeyDataListener;
     private DataStoreBackEnd dsbe;
 
@@ -117,11 +115,11 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
             this.dsbe = new DataStoreBackEnd(dataBroker);
             restoreDaoFromDatastore();
 
-            LispSouthboundHandler lispSouthboundHandler = new LispSouthboundHandler(this);
-            this.lispSouthboundHandler = lispSouthboundHandler;
+            LispSouthboundHandler lsbh = new LispSouthboundHandler(this);
+            this.lispSouthboundHandler = lsbh;
 
-            LispXtrSouthboundHandler lispXtrSouthboundHandler = new LispXtrSouthboundHandler(this);
-            this.lispXtrSouthboundHandler = lispXtrSouthboundHandler;
+            LispXtrSouthboundHandler lxsbh = new LispXtrSouthboundHandler(this);
+            this.lispXtrSouthboundHandler = lxsbh;
 
             if (Epoll.isAvailable()) {
                 eventLoopGroup = new EpollEventLoopGroup(numChannels, threadFactory);
@@ -137,11 +135,11 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
 
             bootstrap.group(eventLoopGroup);
             bootstrap.channel(channelType);
-            bootstrap.handler(lispSouthboundHandler);
+            bootstrap.handler(lsbh);
 
             xtrBootstrap.group(eventLoopGroup);
             xtrBootstrap.channel(channelType);
-            xtrBootstrap.handler(lispXtrSouthboundHandler);
+            xtrBootstrap.handler(lxsbh);
 
             start();
             startXtr();
@@ -241,7 +239,7 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
     public void handleSerializedLispBuffer(TransportAddress address, ByteBuffer outBuffer,
                                            final MessageType packetType) {
         InetAddress ip = getInetAddress(address);
-        handleSerializedLispBuffer(ip, outBuffer, packetType, address.getPort().getValue(), null);
+        handleSerializedLispBuffer(ip, outBuffer, packetType, address.getPort().getValue().toJava(), null);
     }
 
     public void handleSerializedLispBuffer(InetAddress address, ByteBuffer outBuffer,
@@ -257,16 +255,13 @@ public class LispSouthboundPlugin implements IConfigLispSouthboundPlugin, AutoCl
         if (LOG.isTraceEnabled()) {
             LOG.trace("Buffer:\n{}", ByteBufUtil.prettyHexDump(data));
         }
-        senderChannel.write(packet).addListener(new ChannelFutureListener() {
-            @Override
-            public void operationComplete(ChannelFuture future) {
-                if (future.isSuccess()) {
-                    LOG.trace("Success");
-                    statistics.incrementTx(packetType.getIntValue());
-                } else {
-                    LOG.warn("Failed to send packet");
-                    statistics.incrementTxErrors();
-                }
+        senderChannel.write(packet).addListener(future -> {
+            if (future.isSuccess()) {
+                LOG.trace("Success");
+                statistics.incrementTx(packetType.getIntValue());
+            } else {
+                LOG.warn("Failed to send packet");
+                statistics.incrementTxErrors();
             }
         });
         senderChannel.flush();