BUG 2245 - Fixed Loose coupling
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / UdpConnectionMap.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\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
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.impl.core;\r
10 \r
11 import java.net.InetSocketAddress;\r
12 import java.util.HashMap;\r
13 import java.util.Map;\r
14 \r
15 import org.opendaylight.openflowjava.protocol.impl.connection.MessageConsumer;\r
16 \r
17 /**\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
20 \r
21  * @author michal.polkorab\r
22  */\r
23 public class UdpConnectionMap {\r
24 \r
25     private static Map<InetSocketAddress, MessageConsumer> connectionMap = new HashMap<>();\r
26 \r
27     /**\r
28      * @param address sender's address\r
29      * @return corresponding MessageConsumer\r
30      */\r
31     public static MessageConsumer getMessageConsumer(InetSocketAddress address) {\r
32         return connectionMap.get(address);\r
33     }\r
34 \r
35     /**\r
36      * @param address sender's address\r
37      * @param consumer MessageConsumer to be added / paired with specified address\r
38      */\r
39     public static void addConnection(InetSocketAddress address, MessageConsumer consumer) {\r
40         connectionMap.put(address, consumer);\r
41     }\r
42 \r
43     /**\r
44      * @param address sender's address\r
45      */\r
46     public static void removeConnection(InetSocketAddress address) {\r
47         connectionMap.remove(address);\r
48     }\r
49 }