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.opendaylight.controller.md.sal.binding.api.BindingService;
14 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
15 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
16 import org.opendaylight.controller.md.sal.dom.api.DOMService;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 public class BindingMountPointAdapter implements MountPoint {
21 private final InstanceIdentifier<?> identifier;
22 private LoadingCache<Class<? extends BindingService>, Optional<BindingService>> services;
24 public BindingMountPointAdapter(final BindingToNormalizedNodeCodec codec, final DOMMountPoint domMountPoint) {
25 identifier = codec.getCodecRegistry().fromYangInstanceIdentifier(domMountPoint.getIdentifier());
26 services = CacheBuilder.newBuilder().build(new BindingDOMAdapterLoader(codec) {
29 protected DOMService getDelegate(Class<? extends DOMService> reqDeleg) {
30 return domMountPoint.getService(reqDeleg).orNull();
36 public InstanceIdentifier<?> getIdentifier() {
41 public <T extends BindingService> Optional<T> getService(Class<T> service) {
42 Optional<BindingService> potential = services.getUnchecked(service);
43 if(potential.isPresent()) {
44 return Optional.of(service.cast(potential.get()));
46 return Optional.absent();