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
8 package org.opendaylight.controller.md.sal.binding.impl;
10 import com.google.common.base.Optional;
11 import com.google.common.cache.CacheBuilder;
12 import com.google.common.cache.LoadingCache;
13 import org.gaul.modernizer_maven_annotations.SuppressModernizer;
14 import org.opendaylight.controller.md.sal.binding.api.BindingService;
15 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
16 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
17 import org.opendaylight.controller.md.sal.dom.api.DOMService;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 public class BindingMountPointAdapter implements MountPoint {
23 private final InstanceIdentifier<?> identifier;
24 private LoadingCache<Class<? extends BindingService>, Optional<BindingService>> services;
26 public BindingMountPointAdapter(final BindingToNormalizedNodeCodec codec, final DOMMountPoint domMountPoint) {
27 identifier = codec.getCodecRegistry().fromYangInstanceIdentifier(domMountPoint.getIdentifier());
28 services = CacheBuilder.newBuilder().build(new BindingDOMAdapterLoader(codec) {
31 protected DOMService getDelegate(final Class<? extends DOMService> reqDeleg) {
32 return domMountPoint.getService(reqDeleg).orNull();
38 public InstanceIdentifier<?> getIdentifier() {
44 public <T extends BindingService> Optional<T> getService(final Class<T> service) {
45 Optional<BindingService> potential = services.getUnchecked(service);
46 if (potential.isPresent()) {
47 return Optional.of(service.cast(potential.get()));
49 return Optional.absent();