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