Merge "Fix junit dependencies in poms. Reuse existing from parent, add missing ones."
[bgpcep.git] / concepts / src / main / java / org / opendaylight / protocol / concepts / HandlerRegistry.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. 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 package org.opendaylight.protocol.concepts;
9
10 import javax.annotation.concurrent.ThreadSafe;
11
12 @ThreadSafe
13 public class HandlerRegistry<CLASS, PARSER, SERIALIZER> {
14         private final MultiRegistry<Class<? extends CLASS>, SERIALIZER> serializers = new MultiRegistry<>();
15         private final MultiRegistry<Integer, PARSER> parsers = new MultiRegistry<>();
16
17         public AbstractRegistration registerParser(final int type, final PARSER parser) {
18                 return parsers.register(type, parser);
19         }
20
21         public PARSER getParser(final int type) {
22                 return parsers.get(type);
23         }
24
25         public AbstractRegistration registerSerializer(final Class<? extends CLASS> clazz, final SERIALIZER serializer) {
26                 return serializers.register(clazz, serializer);
27         }
28
29         public SERIALIZER getSerializer(final Class<? extends CLASS> clazz) {
30                 return serializers.get(clazz);
31         }
32 }