Migrate Props.create() call sites
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / entityownership / EntityOwnershipListenerActor.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.datastore.entityownership;
9
10 import static java.util.Objects.requireNonNull;
11
12 import akka.actor.Props;
13 import akka.japi.Creator;
14 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
15 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
16 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipChange;
17 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
18
19 /**
20  * An actor which is responsible for notifying an EntityOwnershipListener of changes.
21  *
22  * @author Thomas Pantelis
23  */
24 final class EntityOwnershipListenerActor extends AbstractUntypedActor {
25     private final DOMEntityOwnershipListener listener;
26
27     private EntityOwnershipListenerActor(final DOMEntityOwnershipListener listener) {
28         this.listener = listener;
29     }
30
31     @Override
32     protected void handleReceive(final Object message) {
33         if (message instanceof DOMEntityOwnershipChange) {
34             onEntityOwnershipChanged((DOMEntityOwnershipChange)message);
35         } else {
36             unknownMessage(message);
37         }
38     }
39
40     @SuppressWarnings("checkstyle:IllegalCatch")
41     private void onEntityOwnershipChanged(final DOMEntityOwnershipChange change) {
42         LOG.debug("Notifying EntityOwnershipListener {}: {}", listener, change);
43
44         try {
45             listener.ownershipChanged(change);
46         } catch (Exception e) {
47             LOG.error("Error notifying listener {}", listener, e);
48         }
49     }
50
51     static Props props(final DOMEntityOwnershipListener listener) {
52         return Props.create(EntityOwnershipListenerActor.class, new EntityOwnershipListenerCreator(listener));
53     }
54
55     private static final class EntityOwnershipListenerCreator implements Creator<EntityOwnershipListenerActor> {
56         private static final long serialVersionUID = 1L;
57
58         @SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "This field is not Serializable but we don't "
59                 + "create remote instances of this actor and thus don't need it to be Serializable.")
60         private final DOMEntityOwnershipListener listener;
61
62         EntityOwnershipListenerCreator(final DOMEntityOwnershipListener listener) {
63             this.listener = requireNonNull(listener);
64         }
65
66         @Override
67         public EntityOwnershipListenerActor create() {
68             return new EntityOwnershipListenerActor(listener);
69         }
70     }
71 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.