d0b6c061b7363497e95e0de191ccf2e12cb31bcc
[mdsal.git] / singleton-service / mdsal-singleton-dom-impl / src / main / java / org / opendaylight / mdsal / singleton / dom / impl / DOMClusterSingletonServiceProviderImpl.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.singleton.dom.impl;
9
10 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipService;
11 import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
12 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange;
13 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
14 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration;
15 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
18
19 /**
20  * Binding version of {@link AbstractClusterSingletonServiceProviderImpl}.
21  */
22 public final class DOMClusterSingletonServiceProviderImpl extends
23         AbstractClusterSingletonServiceProviderImpl<YangInstanceIdentifier, DOMEntity,
24                                                     DOMEntityOwnershipChange,
25                                                     DOMEntityOwnershipListener,
26                                                     DOMEntityOwnershipService,
27                                                     DOMEntityOwnershipListenerRegistration>
28         implements DOMEntityOwnershipListener {
29
30     /**
31      * Initialization all needed class internal property for {@link DOMClusterSingletonServiceProviderImpl}.
32      *
33      * @param entityOwnershipService - we need only {@link GenericEntityOwnershipService}
34      */
35     public DOMClusterSingletonServiceProviderImpl(final DOMEntityOwnershipService entityOwnershipService) {
36         super(entityOwnershipService);
37     }
38
39     @Override
40     protected DOMEntity createEntity(final String type, final String ident) {
41         return new DOMEntity(type, ident);
42     }
43
44     @Override
45     protected DOMEntityOwnershipListenerRegistration registerListener(final String type,
46             final DOMEntityOwnershipService eos) {
47         return eos.registerListener(type, this);
48     }
49
50     @Override
51     protected String getServiceIdentifierFromEntity(final DOMEntity entity) {
52         final YangInstanceIdentifier yii = entity.getIdentifier();
53         final NodeIdentifierWithPredicates niiwp = (NodeIdentifierWithPredicates) yii.getLastPathArgument();
54         return niiwp.values().iterator().next().toString();
55     }
56 }