/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.protocol.pcep.spi.pojo; import org.opendaylight.protocol.concepts.HandlerRegistry; import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry; import org.opendaylight.protocol.pcep.spi.MessageParser; import org.opendaylight.protocol.pcep.spi.MessageSerializer; import org.opendaylight.protocol.util.Values; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; import org.opendaylight.yangtools.yang.binding.DataContainer; import com.google.common.base.Preconditions; public final class SimpleMessageHandlerRegistry implements MessageHandlerRegistry { private final HandlerRegistry handlers = new HandlerRegistry<>(); public AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) { Preconditions.checkArgument(messageType >= 0 && messageType <= Values.UNSIGNED_BYTE_MAX_VALUE); return this.handlers.registerParser(messageType, parser); } public AutoCloseable registerMessageSerializer(final Class msgClass, final MessageSerializer serializer) { return this.handlers.registerSerializer(msgClass, serializer); } @Override public MessageParser getMessageParser(final int messageType) { Preconditions.checkArgument(messageType >= 0 && messageType <= Values.UNSIGNED_BYTE_MAX_VALUE); return this.handlers.getParser(messageType); } @Override public MessageSerializer getMessageSerializer(final Message message) { return this.handlers.getSerializer(message.getImplementedInterface()); } }