2 * Copyright (c) 2014 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.sal.binding.impl;
10 import java.util.concurrent.ConcurrentHashMap;
11 import java.util.concurrent.ConcurrentMap;
13 import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
14 import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
15 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
16 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import com.google.common.util.concurrent.ListeningExecutorService;
24 public class MountPointManagerImpl implements MountProviderService {
26 public final Logger LOG = LoggerFactory.getLogger(MountPointManagerImpl.class);
28 private final ConcurrentMap<InstanceIdentifier<?>, BindingMountPointImpl> mountPoints;
29 private final ListenerRegistry<MountProvisionListener> listeners = ListenerRegistry.create();
31 private ListeningExecutorService notificationExecutor;
32 private ListeningExecutorService dataCommitExecutor;
34 public MountPointManagerImpl() {
35 mountPoints = new ConcurrentHashMap<>();
38 public ListeningExecutorService getNotificationExecutor() {
39 return notificationExecutor;
42 public void setNotificationExecutor(ListeningExecutorService notificationExecutor) {
43 this.notificationExecutor = notificationExecutor;
46 public ListeningExecutorService getDataCommitExecutor() {
47 return dataCommitExecutor;
50 public void setDataCommitExecutor(ListeningExecutorService dataCommitExecutor) {
51 this.dataCommitExecutor = dataCommitExecutor;
55 public synchronized BindingMountPointImpl createMountPoint(InstanceIdentifier<?> path) {
56 BindingMountPointImpl potential = mountPoints.get(path);
57 if (potential != null) {
58 throw new IllegalStateException("Mount point already exists.");
60 return createOrGetMountPointImpl(path);
64 public BindingMountPointImpl createOrGetMountPoint(InstanceIdentifier<?> path) {
65 BindingMountPointImpl potential = getMountPoint(path);
66 if (potential != null) {
69 return createOrGetMountPointImpl(path);
73 public BindingMountPointImpl getMountPoint(InstanceIdentifier<?> path) {
74 return mountPoints.get(path);
77 private synchronized BindingMountPointImpl createOrGetMountPointImpl(InstanceIdentifier<?> path) {
78 BindingMountPointImpl potential = getMountPoint(path);
79 if (potential != null) {
82 RpcProviderRegistryImpl rpcRegistry = new RpcProviderRegistryImpl("mount");
83 NotificationBrokerImpl notificationBroker = new NotificationBrokerImpl();
84 notificationBroker.setExecutor(getNotificationExecutor());
85 DataBrokerImpl dataBroker = new DataBrokerImpl();
86 dataBroker.setExecutor(getDataCommitExecutor());
87 BindingMountPointImpl mountInstance = new BindingMountPointImpl(path, rpcRegistry, notificationBroker,
89 mountPoints.putIfAbsent(path, mountInstance);
90 notifyMountPointCreated(path);
94 private void notifyMountPointCreated(InstanceIdentifier<?> path) {
95 for (ListenerRegistration<MountProvisionListener> listener : listeners) {
97 listener.getInstance().onMountPointCreated(path);
98 } catch (Exception e) {
99 LOG.error("Unhandled exception during invoking listener.", e);
105 public ListenerRegistration<MountProvisionListener> registerProvisionListener(MountProvisionListener listener) {
106 return listeners.register(listener);
109 public class BindingMountPointImpl extends
110 AbstractBindingSalProviderInstance<DataBrokerImpl, NotificationBrokerImpl, RpcProviderRegistryImpl>
111 implements MountProviderInstance {
113 private InstanceIdentifier<?> identifier;
115 public BindingMountPointImpl(org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> identifier,
116 RpcProviderRegistryImpl rpcRegistry, NotificationBrokerImpl notificationBroker,
117 DataBrokerImpl dataBroker) {
118 super(rpcRegistry, notificationBroker, dataBroker);
119 this.identifier = identifier;
122 // Needed only for BI Connector
123 public DataBrokerImpl getDataBrokerImpl() {
124 return (DataBrokerImpl) getDataBroker();
128 public InstanceIdentifier<?> getIdentifier() {
129 return this.identifier;