Refactor AbstractClientHandle a bit
[controller.git] / opendaylight / md-sal / sal-distributed-eos / src / main / java / org / opendaylight / controller / cluster / entityownership / DistributedEntityOwnershipListenerRegistration.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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.controller.cluster.entityownership;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
14 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListenerRegistration;
15 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
16
17 /**
18  * Implementation of EntityOwnershipListenerRegistration.
19  *
20  * @author Thomas Pantelis
21  */
22 class DistributedEntityOwnershipListenerRegistration extends AbstractObjectRegistration<DOMEntityOwnershipListener>
23         implements DOMEntityOwnershipListenerRegistration {
24     private final DistributedEntityOwnershipService service;
25     private final String entityType;
26
27     DistributedEntityOwnershipListenerRegistration(final DOMEntityOwnershipListener listener, final String entityType,
28             final DistributedEntityOwnershipService service) {
29         super(listener);
30         this.entityType = requireNonNull(entityType, "entityType cannot be null");
31         this.service = requireNonNull(service, "DOMEntityOwnershipListener cannot be null");
32     }
33
34     @Override
35     protected void removeRegistration() {
36         service.unregisterListener(getEntityType(), getInstance());
37     }
38
39     @Override
40     public String getEntityType() {
41         return entityType;
42     }
43
44     @Override
45     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
46         return toStringHelper.add("entityType", entityType);
47     }
48 }