Mass replace CRLF->LF
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / UdpConnectionMap.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.core;
10
11 import java.net.InetSocketAddress;
12 import java.util.Map;
13 import java.util.concurrent.ConcurrentHashMap;
14
15 import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageConsumer;
16
17 /**
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
20
21  * @author michal.polkorab
22  */
23 public final class UdpConnectionMap {
24
25     private static Map<InetSocketAddress, MessageConsumer> connectionMap = new ConcurrentHashMap<>();
26
27     private UdpConnectionMap() {
28         throw new UnsupportedOperationException("Utility class shouldn't be instantiated");
29     }
30
31     /**
32      * @param address sender's address
33      * @return corresponding MessageConsumer
34      */
35     public static MessageConsumer getMessageConsumer(InetSocketAddress address) {
36         if(address == null){
37             throw new IllegalArgumentException("Address can not be null");
38         }
39         return connectionMap.get(address);
40     }
41
42     /**
43      * @param address sender's address
44      * @param consumer MessageConsumer to be added / paired with specified address
45      */
46     public static void addConnection(InetSocketAddress address, MessageConsumer consumer) {
47         if(address == null){
48             throw new IllegalArgumentException("Address can not be null");
49         }
50         connectionMap.put(address, consumer);
51     }
52
53     /**
54      * @param address sender's address
55      */
56     public static void removeConnection(InetSocketAddress address) {
57         if(address == null){
58             throw new IllegalArgumentException("Address can not be null");
59         }
60         connectionMap.remove(address);
61     }
62 }