1 package org.opendaylight.controller.sal.binding.impl;
3 import java.util.concurrent.ConcurrentHashMap;
4 import java.util.concurrent.ConcurrentMap;
6 import org.opendaylight.controller.md.sal.binding.util.AbstractBindingSalProviderInstance;
7 import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
8 import org.opendaylight.controller.sal.binding.api.mount.MountProviderInstance;
9 import org.opendaylight.controller.sal.binding.api.mount.MountProviderService;
10 import org.opendaylight.yangtools.concepts.ListenerRegistration;
11 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 import com.google.common.util.concurrent.ListeningExecutorService;
17 public class MountPointManagerImpl implements MountProviderService {
19 public final Logger LOG = LoggerFactory.getLogger(MountPointManagerImpl.class);
21 private final ConcurrentMap<InstanceIdentifier<?>, BindingMountPointImpl> mountPoints;
22 private final ListenerRegistry<MountProvisionListener> listeners = ListenerRegistry.create();
24 private ListeningExecutorService notificationExecutor;
25 private ListeningExecutorService dataCommitExecutor;
27 public MountPointManagerImpl() {
28 mountPoints = new ConcurrentHashMap<>();
31 public ListeningExecutorService getNotificationExecutor() {
32 return notificationExecutor;
35 public void setNotificationExecutor(ListeningExecutorService notificationExecutor) {
36 this.notificationExecutor = notificationExecutor;
39 public ListeningExecutorService getDataCommitExecutor() {
40 return dataCommitExecutor;
43 public void setDataCommitExecutor(ListeningExecutorService dataCommitExecutor) {
44 this.dataCommitExecutor = dataCommitExecutor;
48 public synchronized BindingMountPointImpl createMountPoint(InstanceIdentifier<?> path) {
49 BindingMountPointImpl potential = mountPoints.get(path);
50 if (potential != null) {
51 throw new IllegalStateException("Mount point already exists.");
53 return createOrGetMountPointImpl(path);
57 public BindingMountPointImpl createOrGetMountPoint(InstanceIdentifier<?> path) {
58 BindingMountPointImpl potential = getMountPoint(path);
59 if (potential != null) {
62 return createOrGetMountPointImpl(path);
66 public BindingMountPointImpl getMountPoint(InstanceIdentifier<?> path) {
67 return mountPoints.get(path);
70 private synchronized BindingMountPointImpl createOrGetMountPointImpl(InstanceIdentifier<?> path) {
71 BindingMountPointImpl potential = getMountPoint(path);
72 if (potential != null) {
75 RpcProviderRegistryImpl rpcRegistry = new RpcProviderRegistryImpl("mount");
76 NotificationBrokerImpl notificationBroker = new NotificationBrokerImpl();
77 notificationBroker.setExecutor(getNotificationExecutor());
78 DataBrokerImpl dataBroker = new DataBrokerImpl();
79 dataBroker.setExecutor(getDataCommitExecutor());
80 BindingMountPointImpl mountInstance = new BindingMountPointImpl(path, rpcRegistry, notificationBroker,
82 mountPoints.putIfAbsent(path, mountInstance);
83 notifyMountPointCreated(path);
87 private void notifyMountPointCreated(InstanceIdentifier<?> path) {
88 for (ListenerRegistration<MountProvisionListener> listener : listeners) {
90 listener.getInstance().onMountPointCreated(path);
91 } catch (Exception e) {
92 LOG.error("Unhandled exception during invoking listener.", e);
98 public ListenerRegistration<MountProvisionListener> registerProvisionListener(MountProvisionListener listener) {
99 return listeners.register(listener);
102 public class BindingMountPointImpl extends
103 AbstractBindingSalProviderInstance<DataBrokerImpl, NotificationBrokerImpl, RpcProviderRegistryImpl>
104 implements MountProviderInstance {
106 private InstanceIdentifier<?> identifier;
108 public BindingMountPointImpl(org.opendaylight.yangtools.yang.binding.InstanceIdentifier<?> identifier,
109 RpcProviderRegistryImpl rpcRegistry, NotificationBrokerImpl notificationBroker,
110 DataBrokerImpl dataBroker) {
111 super(rpcRegistry, notificationBroker, dataBroker);
112 this.identifier = identifier;
116 public InstanceIdentifier<?> getIdentifier() {
117 return this.identifier;