Merge changes Ic12888cc,I669cc282,Iad2d6119
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / SimpleMessageHandlerRegistry.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.pcep.spi.pojo;
9
10 import org.opendaylight.protocol.concepts.HandlerRegistry;
11 import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
12 import org.opendaylight.protocol.pcep.spi.MessageParser;
13 import org.opendaylight.protocol.pcep.spi.MessageSerializer;
14 import org.opendaylight.protocol.util.Values;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
16 import org.opendaylight.yangtools.yang.binding.DataContainer;
17
18 import com.google.common.base.Preconditions;
19
20 public final class SimpleMessageHandlerRegistry implements MessageHandlerRegistry {
21
22         private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
23
24         public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
25                 Preconditions.checkArgument(messageType >= 0 && messageType <= Values.UNSIGNED_BYTE_MAX_VALUE);
26                 return this.handlers.registerParser(messageType, parser);
27         }
28
29         public AutoCloseable registerMessageSerializer(final Class<? extends Message> msgClass, final MessageSerializer serializer) {
30                 return this.handlers.registerSerializer(msgClass, serializer);
31         }
32
33         @Override
34         public MessageParser getMessageParser(final int messageType) {
35                 Preconditions.checkArgument(messageType >= 0 && messageType <= Values.UNSIGNED_BYTE_MAX_VALUE);
36                 return this.handlers.getParser(messageType);
37         }
38
39         @Override
40         public MessageSerializer getMessageSerializer(final Message message) {
41                 return this.handlers.getSerializer(message.getImplementedInterface());
42         }
43 }