Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / UdpHandler.java
index c0f958d2acb0ccd0fa0062e7a2fc8ce0a1e1bd69..0d7bb4e5b13783625d9dc138184e762f2c3e9143 100644 (file)
-/*\r
- * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.openflowjava.protocol.impl.core;\r
-\r
-import io.netty.bootstrap.Bootstrap;\r
-import io.netty.channel.ChannelFuture;\r
-import io.netty.channel.ChannelOption;\r
-import io.netty.channel.EventLoopGroup;\r
-import io.netty.channel.nio.NioEventLoopGroup;\r
-import io.netty.channel.socket.nio.NioDatagramChannel;\r
-import io.netty.util.concurrent.GenericFutureListener;\r
-\r
-import java.net.InetAddress;\r
-import java.net.InetSocketAddress;\r
-\r
-import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;\r
-import org.opendaylight.openflowjava.protocol.impl.connection.ServerFacade;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import com.google.common.util.concurrent.ListenableFuture;\r
-import com.google.common.util.concurrent.SettableFuture;\r
-\r
-/**\r
- * Class implementing server over UDP for handling incoming connections.\r
- * \r
- * @author michal.polkorab\r
- */\r
-public final class UdpHandler implements ServerFacade {\r
-\r
-    private static final Logger LOGGER = LoggerFactory\r
-            .getLogger(UdpHandler.class);\r
-    private int port;\r
-    private String address;\r
-    private EventLoopGroup group;\r
-    private final InetAddress startupAddress;\r
-    private final SettableFuture<Boolean> isOnlineFuture;\r
-    private UdpChannelInitializer channelInitializer;\r
-    private ThreadConfiguration threadConfig;\r
-\r
-    /**\r
-     * Constructor of UdpHandler that listens on selected port.\r
-     *\r
-     * @param port listening port of UdpHandler server\r
-     */\r
-    public UdpHandler(final int port) {\r
-        this(null, port);\r
-    }\r
-\r
-    /**\r
-     * Constructor of UdpHandler that listens on selected address and port.\r
-     * @param address listening address of UdpHandler server\r
-     * @param port listening port of UdpHandler server\r
-     */\r
-    public UdpHandler(final InetAddress address, final int port) {\r
-        this.port = port;\r
-        this.startupAddress = address;\r
-        isOnlineFuture = SettableFuture.create();\r
-    }\r
-\r
-    @Override\r
-    public void run() {\r
-        if (threadConfig != null) {\r
-            group = new NioEventLoopGroup(threadConfig.getWorkerThreadCount());\r
-        } else {\r
-            group = new NioEventLoopGroup();\r
-        }\r
-        final ChannelFuture f;\r
-        try {\r
-            Bootstrap b = new Bootstrap();\r
-            b.group(group)\r
-             .channel(NioDatagramChannel.class)\r
-             .option(ChannelOption.SO_BROADCAST, false)\r
-             .handler(channelInitializer);\r
-\r
-            if (startupAddress != null) {\r
-                f = b.bind(startupAddress.getHostAddress(), port).sync();\r
-            } else {\r
-                f = b.bind(port).sync();\r
-            }\r
-        } catch (InterruptedException e) {\r
-            LOGGER.error("Interrupted while binding port {}", port, e);\r
-            return;\r
-        }\r
-\r
-        try {\r
-            InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress();\r
-            this.address = isa.getHostString();\r
-\r
-            // Update port, as it may have been specified as 0\r
-            this.port = isa.getPort();\r
-\r
-            LOGGER.debug("Address from udpHandler: {}", address);\r
-            isOnlineFuture.set(true);\r
-            LOGGER.info("Switch listener started and ready to accept incoming udp connections on port: {}", port);\r
-            f.channel().closeFuture().sync();\r
-        } catch (InterruptedException e) {\r
-            LOGGER.error("Interrupted while waiting for port {} shutdown", port, e);\r
-        } finally {\r
-            shutdown();\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public ListenableFuture<Boolean> shutdown() {\r
-        final SettableFuture<Boolean> result = SettableFuture.create();\r
-        group.shutdownGracefully().addListener(new GenericFutureListener<io.netty.util.concurrent.Future<Object>>() {\r
-\r
-            @Override\r
-            public void operationComplete(\r
-                    final io.netty.util.concurrent.Future<Object> downResult) throws Exception {\r
-                result.set(downResult.isSuccess());\r
-                if (downResult.cause() != null) {\r
-                    result.setException(downResult.cause());\r
-                }\r
-            }\r
-\r
-        });\r
-        return result;\r
-    }\r
-\r
-    @Override\r
-    public ListenableFuture<Boolean> getIsOnlineFuture() {\r
-        return isOnlineFuture;\r
-    }\r
-\r
-    /**\r
-     * @return the port\r
-     */\r
-    public int getPort() {\r
-        return port;\r
-    }\r
-\r
-    /**\r
-     * @param channelInitializer\r
-     */\r
-    public void setChannelInitializer(UdpChannelInitializer channelInitializer) {\r
-        this.channelInitializer = channelInitializer;\r
-    }\r
-\r
-    @Override\r
-    public void setThreadConfig(ThreadConfiguration threadConfig) {\r
-        this.threadConfig = threadConfig;\r
-    }\r
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.core;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.nio.NioDatagramChannel;
+import io.netty.util.concurrent.GenericFutureListener;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+
+import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+
+/**
+ * Class implementing server over UDP for handling incoming connections.
+ * 
+ * @author michal.polkorab
+ */
+public final class UdpHandler implements ServerFacade {
+
+    private static final Logger LOGGER = LoggerFactory
+            .getLogger(UdpHandler.class);
+    private int port;
+    private EventLoopGroup group;
+    private final InetAddress startupAddress;
+    private final SettableFuture<Boolean> isOnlineFuture;
+    private UdpChannelInitializer channelInitializer;
+    private ThreadConfiguration threadConfig;
+
+    /**
+     * Constructor of UdpHandler that listens on selected port.
+     *
+     * @param port listening port of UdpHandler server
+     */
+    public UdpHandler(final int port) {
+        this(null, port);
+    }
+
+    /**
+     * Constructor of UdpHandler that listens on selected address and port.
+     * @param address listening address of UdpHandler server
+     * @param port listening port of UdpHandler server
+     */
+    public UdpHandler(final InetAddress address, final int port) {
+        this.port = port;
+        this.startupAddress = address;
+        isOnlineFuture = SettableFuture.create();
+    }
+
+    @Override
+    public void run() {
+        if (threadConfig != null) {
+            group = new NioEventLoopGroup(threadConfig.getWorkerThreadCount());
+        } else {
+            group = new NioEventLoopGroup();
+        }
+        final ChannelFuture f;
+        try {
+            Bootstrap b = new Bootstrap();
+            b.group(group)
+             .channel(NioDatagramChannel.class)
+             .option(ChannelOption.SO_BROADCAST, false)
+             .handler(channelInitializer);
+
+            if (startupAddress != null) {
+                f = b.bind(startupAddress.getHostAddress(), port).sync();
+            } else {
+                f = b.bind(port).sync();
+            }
+        } catch (InterruptedException e) {
+            LOGGER.error("Interrupted while binding port {}", port, e);
+            return;
+        }
+
+        try {
+            InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress();
+            String address = isa.getHostString();
+
+            // Update port, as it may have been specified as 0
+            this.port = isa.getPort();
+
+            LOGGER.debug("Address from udpHandler: {}", address);
+            isOnlineFuture.set(true);
+            LOGGER.info("Switch listener started and ready to accept incoming udp connections on port: {}", port);
+            f.channel().closeFuture().sync();
+        } catch (InterruptedException e) {
+            LOGGER.error("Interrupted while waiting for port {} shutdown", port, e);
+        } finally {
+            shutdown();
+        }
+    }
+
+    @Override
+    public ListenableFuture<Boolean> shutdown() {
+        final SettableFuture<Boolean> result = SettableFuture.create();
+        group.shutdownGracefully().addListener(new GenericFutureListener<io.netty.util.concurrent.Future<Object>>() {
+
+            @Override
+            public void operationComplete(
+                    final io.netty.util.concurrent.Future<Object> downResult) throws Exception {
+                result.set(downResult.isSuccess());
+                if (downResult.cause() != null) {
+                    result.setException(downResult.cause());
+                }
+            }
+
+        });
+        return result;
+    }
+
+    @Override
+    public ListenableFuture<Boolean> getIsOnlineFuture() {
+        return isOnlineFuture;
+    }
+
+    /**
+     * @return the port
+     */
+    public int getPort() {
+        return port;
+    }
+
+    /**
+     * @param channelInitializer
+     */
+    public void setChannelInitializer(UdpChannelInitializer channelInitializer) {
+        this.channelInitializer = channelInitializer;
+    }
+
+    @Override
+    public void setThreadConfig(ThreadConfiguration threadConfig) {
+        this.threadConfig = threadConfig;
+    }
 }
\ No newline at end of file