-/*\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 java.net.InetSocketAddress;\r
-import java.util.HashMap;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.connection.MessageConsumer;\r
-\r
-/**\r
- * As UDP communication is handled only by one channel, it is needed\r
- * to store MessageConsumers, so that we know which consumer handles which channel\r
-\r
- * @author michal.polkorab\r
- */\r
-public class UdpConnectionMap {\r
-\r
- private static HashMap<InetSocketAddress, MessageConsumer> connectionMap = new HashMap<>();\r
-\r
- /**\r
- * @param address sender's address\r
- * @return corresponding MessageConsumer\r
- */\r
- public static MessageConsumer getMessageConsumer(InetSocketAddress address) {\r
- return connectionMap.get(address);\r
- }\r
-\r
- /**\r
- * @param address sender's address\r
- * @param consumer MessageConsumer to be added / paired with specified address\r
- */\r
- public static void addConnection(InetSocketAddress address, MessageConsumer consumer) {\r
- connectionMap.put(address, consumer);\r
- }\r
-\r
- /**\r
- * @param address sender's address\r
- */\r
- public static void removeConnection(InetSocketAddress address) {\r
- connectionMap.remove(address);\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 java.net.InetSocketAddress;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
+
+/**
+ * As UDP communication is handled only by one channel, it is needed
+ * to store MessageConsumers, so that we know which consumer handles which channel
+
+ * @author michal.polkorab
+ */
+public final class UdpConnectionMap {
+
+ private static Map<InetSocketAddress, MessageConsumer> connectionMap = new ConcurrentHashMap<>();
+
+ private UdpConnectionMap() {
+ throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
+ }
+
+ /**
+ * @param address sender's address
+ * @return corresponding MessageConsumer
+ */
+ public static MessageConsumer getMessageConsumer(InetSocketAddress address) {
+ if(address == null){
+ throw new IllegalArgumentException("Address can not be null");
+ }
+ return connectionMap.get(address);
+ }
+
+ /**
+ * @param address sender's address
+ * @param consumer MessageConsumer to be added / paired with specified address
+ */
+ public static void addConnection(InetSocketAddress address, MessageConsumer consumer) {
+ if(address == null){
+ throw new IllegalArgumentException("Address can not be null");
+ }
+ connectionMap.put(address, consumer);
+ }
+
+ /**
+ * @param address sender's address
+ */
+ public static void removeConnection(InetSocketAddress address) {
+ if(address == null){
+ throw new IllegalArgumentException("Address can not be null");
+ }
+ connectionMap.remove(address);
+ }
}
\ No newline at end of file