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;
12 import java.util.concurrent.Executors;
14 import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
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.util.ListenerRegistry;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import com.google.common.util.concurrent.ListeningExecutorService;
24 import com.google.common.util.concurrent.MoreExecutors;
26 public class MountPointManagerImpl implements MountProviderService {
28 public final Logger LOG = LoggerFactory.getLogger(MountPointManagerImpl.class);
30 private final ConcurrentMap<InstanceIdentifier<?>, BindingMountPointImpl> mountPoints;
31 private final ListenerRegistry<MountProvisionListener> listeners = ListenerRegistry.create();
33 private ListeningExecutorService notificationExecutor;
34 private ListeningExecutorService dataCommitExecutor;
36 public MountPointManagerImpl() {
37 mountPoints = new ConcurrentHashMap<>();
40 public ListeningExecutorService getNotificationExecutor() {
41 return notificationExecutor;
44 public void setNotificationExecutor(final ListeningExecutorService notificationExecutor) {
45 this.notificationExecutor = notificationExecutor;
48 public ListeningExecutorService getDataCommitExecutor() {
49 return dataCommitExecutor;
52 public void setDataCommitExecutor(final ListeningExecutorService dataCommitExecutor) {
53 this.dataCommitExecutor = dataCommitExecutor;
57 public synchronized BindingMountPointImpl createMountPoint(final InstanceIdentifier<?> path) {
58 BindingMountPointImpl potential = mountPoints.get(path);
59 if (potential != null) {
60 throw new IllegalStateException("Mount point already exists.");
62 return createOrGetMountPointImpl(path);
66 public BindingMountPointImpl createOrGetMountPoint(final InstanceIdentifier<?> path) {
67 BindingMountPointImpl potential = getMountPoint(path);
68 if (potential != null) {
71 return createOrGetMountPointImpl(path);
75 public BindingMountPointImpl getMountPoint(final InstanceIdentifier<?> path) {
76 return mountPoints.get(path);
79 private synchronized BindingMountPointImpl createOrGetMountPointImpl(final InstanceIdentifier<?> path) {
80 BindingMountPointImpl potential = getMountPoint(path);
81 if (potential != null) {
84 RpcProviderRegistryImpl rpcRegistry = new RpcProviderRegistryImpl("mount");
85 NotificationBrokerImpl notificationBroker = new NotificationBrokerImpl(getNotificationExecutor());
86 DataBrokerImpl dataBroker = new DataBrokerImpl();
87 dataBroker.setExecutor(MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()));
88 BindingMountPointImpl mountInstance = new BindingMountPointImpl(path, rpcRegistry, notificationBroker,
90 mountPoints.putIfAbsent(path, mountInstance);
91 notifyMountPointCreated(path);
95 private void notifyMountPointCreated(final InstanceIdentifier<?> path) {
96 for (ListenerRegistration<MountProvisionListener> listener : listeners) {
98 listener.getInstance().onMountPointCreated(path);
99 } catch (Exception e) {
100 LOG.error("Unhandled exception during invoking listener.", e);
106 public ListenerRegistration<MountProvisionListener> registerProvisionListener(final MountProvisionListener listener) {
107 return listeners.register(listener);
110 public class BindingMountPointImpl extends
111 AbstractBindingSalProviderInstance<DataBrokerImpl, NotificationBrokerImpl, RpcProviderRegistryImpl>
112 implements MountProviderInstance {
114 private final InstanceIdentifier<?> identifier;
116 public BindingMountPointImpl(final org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> identifier,
117 final RpcProviderRegistryImpl rpcRegistry, final NotificationBrokerImpl notificationBroker,
118 final DataBrokerImpl dataBroker) {
119 super(rpcRegistry, notificationBroker, dataBroker);
120 this.identifier = identifier;
123 // Needed only for BI Connector
124 public DataBrokerImpl getDataBrokerImpl() {
125 return getDataBroker();
129 public InstanceIdentifier<?> getIdentifier() {
130 return this.identifier;