2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.rsvp.parser.spi.pojo;
11 import com.google.common.cache.Cache;
12 import com.google.common.cache.CacheBuilder;
13 import java.util.concurrent.atomic.AtomicReference;
14 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectParser;
15 import org.opendaylight.protocol.rsvp.parser.spi.EROSubobjectSerializer;
16 import org.opendaylight.protocol.rsvp.parser.spi.LabelParser;
17 import org.opendaylight.protocol.rsvp.parser.spi.LabelSerializer;
18 import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectParser;
19 import org.opendaylight.protocol.rsvp.parser.spi.RROSubobjectSerializer;
20 import org.opendaylight.protocol.rsvp.parser.spi.RSVPExtensionProviderContext;
21 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectParser;
22 import org.opendaylight.protocol.rsvp.parser.spi.RSVPTeObjectSerializer;
23 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectParser;
24 import org.opendaylight.protocol.rsvp.parser.spi.XROSubobjectSerializer;
25 import org.opendaylight.protocol.util.ReferenceCache;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.RsvpTeObject;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
30 public class SimpleRSVPExtensionProviderContext extends SimpleRSVPExtensionConsumerContext implements RSVPExtensionProviderContext {
32 public static final int DEFAULT_MAXIMUM_CACHED_OBJECTS = 100000;
34 private final AtomicReference<Cache<Object, Object>> cacheRef;
35 private final ReferenceCache referenceCache = new ReferenceCache() {
37 public <T> T getSharedReference(final T object) {
38 final Cache<Object, Object> cache = SimpleRSVPExtensionProviderContext.this.cacheRef.get();
40 @SuppressWarnings("unchecked")
41 final T ret = (T) cache.getIfPresent(object);
43 cache.put(object, object);
50 private final int maximumCachedObjects;
52 public SimpleRSVPExtensionProviderContext() {
53 this(DEFAULT_MAXIMUM_CACHED_OBJECTS);
56 public SimpleRSVPExtensionProviderContext(final int maximumCachedObjects) {
57 this.maximumCachedObjects = maximumCachedObjects;
59 final Cache<Object, Object> cache = CacheBuilder.newBuilder().maximumSize(maximumCachedObjects).build();
60 this.cacheRef = new AtomicReference<Cache<Object,Object>>(cache);
64 public ReferenceCache getReferenceCache() {
65 return this.referenceCache;
70 public void registerRsvpObjectParser(final int classNum, final int cType, final RSVPTeObjectParser parser) {
71 this.getRsvpRegistry().registerRsvpObjectParser(classNum, cType, parser);
75 public void registerRsvpObjectSerializer(final Class<? extends RsvpTeObject> objectClass, final RSVPTeObjectSerializer serializer) {
76 this.getRsvpRegistry().registerRsvpObjectSerializer(objectClass, serializer);
80 public AutoCloseable registerXROSubobjectSerializer(final Class<? extends SubobjectType> subobjectClass, final XROSubobjectSerializer serializer) {
81 return this.getXROSubobjectHandlerRegistry().registerSubobjectSerializer(subobjectClass, serializer);
85 public AutoCloseable registerXROSubobjectParser(final int subobjectType, final XROSubobjectParser parser) {
86 return this.getXROSubobjectHandlerRegistry().registerSubobjectParser(subobjectType, parser);
90 public AutoCloseable registerRROSubobjectSerializer(final Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.record.route.subobjects.SubobjectType> subobjectClass, final RROSubobjectSerializer serializer) {
91 return this.getRROSubobjectHandlerRegistry().registerSubobjectSerializer(subobjectClass, serializer);
95 public AutoCloseable registerRROSubobjectParser(final int subobjectType, final RROSubobjectParser parser) {
96 return this.getRROSubobjectHandlerRegistry().registerSubobjectParser(subobjectType, parser);
100 public AutoCloseable registerEROSubobjectSerializer(final Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.SubobjectType> subobjectClass, final EROSubobjectSerializer serializer) {
101 return this.getEROSubobjectHandlerRegistry().registerSubobjectSerializer(subobjectClass, serializer);
105 public AutoCloseable registerEROSubobjectParser(final int subobjectType, final EROSubobjectParser parser) {
106 return this.getEROSubobjectHandlerRegistry().registerSubobjectParser(subobjectType, parser);
110 public AutoCloseable registerLabelSerializer(final Class<? extends LabelType> labelClass, final LabelSerializer serializer) {
111 return this.getLabelHandlerRegistry().registerLabelSerializer(labelClass, serializer);
115 public AutoCloseable registerLabelParser(final int cType, final LabelParser parser) {
116 return this.getLabelHandlerRegistry().registerLabelParser(cType, parser);