2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.core;
11 import java.net.InetSocketAddress;
13 import java.util.concurrent.ConcurrentHashMap;
15 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
18 * As UDP communication is handled only by one channel, it is needed
19 * to store MessageConsumers, so that we know which consumer handles which channel
21 * @author michal.polkorab
23 public final class UdpConnectionMap {
25 private static Map<InetSocketAddress, MessageConsumer> connectionMap = new ConcurrentHashMap<>();
27 private UdpConnectionMap() {
28 throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
32 * @param address sender's address
33 * @return corresponding MessageConsumer
35 public static MessageConsumer getMessageConsumer(InetSocketAddress address) {
37 throw new IllegalArgumentException("Address can not be null");
39 return connectionMap.get(address);
43 * @param address sender's address
44 * @param consumer MessageConsumer to be added / paired with specified address
46 public static void addConnection(InetSocketAddress address, MessageConsumer consumer) {
48 throw new IllegalArgumentException("Address can not be null");
50 connectionMap.put(address, consumer);
54 * @param address sender's address
56 public static void removeConnection(InetSocketAddress address) {
58 throw new IllegalArgumentException("Address can not be null");
60 connectionMap.remove(address);