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 com.google.common.util.concurrent.ListeningExecutorService;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14 import java.util.concurrent.Executors;
15 import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
16 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
17 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.util.ListenerRegistry;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
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(final ListeningExecutorService notificationExecutor) {
43 this.notificationExecutor = notificationExecutor;
46 public ListeningExecutorService getDataCommitExecutor() {
47 return dataCommitExecutor;
50 public void setDataCommitExecutor(final ListeningExecutorService dataCommitExecutor) {
51 this.dataCommitExecutor = dataCommitExecutor;
55 public synchronized BindingMountPointImpl createMountPoint(final 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(final InstanceIdentifier<?> path) {
65 BindingMountPointImpl potential = getMountPoint(path);
66 if (potential != null) {
69 return createOrGetMountPointImpl(path);
73 public BindingMountPointImpl getMountPoint(final InstanceIdentifier<?> path) {
74 return mountPoints.get(path);
77 private synchronized BindingMountPointImpl createOrGetMountPointImpl(final InstanceIdentifier<?> path) {
78 BindingMountPointImpl potential = getMountPoint(path);
79 if (potential != null) {
82 RpcProviderRegistryImpl rpcRegistry = new RpcProviderRegistryImpl("mount");
83 NotificationBrokerImpl notificationBroker = new NotificationBrokerImpl(getNotificationExecutor());
84 DataBrokerImpl dataBroker = new DataBrokerImpl();
85 dataBroker.setExecutor(MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()));
86 BindingMountPointImpl mountInstance = new BindingMountPointImpl(path, rpcRegistry, notificationBroker,
88 mountPoints.putIfAbsent(path, mountInstance);
89 notifyMountPointCreated(path);
93 private void notifyMountPointCreated(final InstanceIdentifier<?> path) {
94 for (ListenerRegistration<MountProvisionListener> listener : listeners) {
96 listener.getInstance().onMountPointCreated(path);
97 } catch (Exception e) {
98 LOG.error("Unhandled exception during invoking listener.", e);
104 public ListenerRegistration<MountProvisionListener> registerProvisionListener(final MountProvisionListener listener) {
105 return listeners.register(listener);
108 public class BindingMountPointImpl extends
109 AbstractBindingSalProviderInstance<DataBrokerImpl, NotificationBrokerImpl, RpcProviderRegistryImpl>
110 implements MountProviderInstance {
112 private final InstanceIdentifier<?> identifier;
114 public BindingMountPointImpl(final InstanceIdentifier<?> identifier,
115 final RpcProviderRegistryImpl rpcRegistry, final NotificationBrokerImpl notificationBroker,
116 final DataBrokerImpl dataBroker) {
117 super(rpcRegistry, notificationBroker, dataBroker);
118 this.identifier = identifier;
121 // Needed only for BI Connector
122 public DataBrokerImpl getDataBrokerImpl() {
123 return getDataBroker();
127 public InstanceIdentifier<?> getIdentifier() {
128 return this.identifier;