X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fcore%2FUdpConnectionMap.java;h=d23d5ada1c63d46ec99ba47dd64d54d6a4579de1;hb=519a86d1ddcfb8f0fe264174e62e5424e1efba1f;hp=ce6d17f034179cf6480612b743c3cf620364c8e6;hpb=fbfd230558d9c43581f8b5d08eb51d0bbde02a4f;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/UdpConnectionMap.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/UdpConnectionMap.java index ce6d17f0..d23d5ada 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/UdpConnectionMap.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/UdpConnectionMap.java @@ -1,48 +1,62 @@ -/* - * 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.HashMap; - -import org.opendaylight.openflowjava.protocol.impl.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 class UdpConnectionMap { - - private static HashMap connectionMap = new HashMap<>(); - - /** - * @param address sender's address - * @return corresponding MessageConsumer - */ - public static MessageConsumer getMessageConsumer(InetSocketAddress address) { - 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) { - connectionMap.put(address, consumer); - } - - /** - * @param address sender's address - */ - public static void removeConnection(InetSocketAddress address) { - connectionMap.remove(address); - } +/* + * 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 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