2 * Copyright (c) 2015 Brocade Communications 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.cluster.datastore.entityownership;
10 import akka.actor.Props;
11 import akka.japi.Creator;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.common.actor.AbstractUntypedActor;
14 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipChange;
15 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
20 * An actor which is responsible for notifying an EntityOwnershipListener of changes.
22 * @author Thomas Pantelis
24 class EntityOwnershipListenerActor extends AbstractUntypedActor {
25 private static final Logger LOG = LoggerFactory.getLogger(EntityOwnershipListenerActor.class);
27 private final EntityOwnershipListener listener;
29 private EntityOwnershipListenerActor(EntityOwnershipListener listener) {
30 this.listener = listener;
34 protected void handleReceive(Object message) {
35 if (message instanceof EntityOwnershipChange) {
36 onEntityOwnershipChanged((EntityOwnershipChange)message);
38 unknownMessage(message);
42 private void onEntityOwnershipChanged(EntityOwnershipChange change) {
43 LOG.debug("Notifying EntityOwnershipListener {}: {}", listener, change);
46 listener.ownershipChanged(change);
47 } catch (Exception e) {
48 LOG.error("Error notifying listener {}", listener, e);
52 static Props props(EntityOwnershipListener listener) {
53 return Props.create(new EntityOwnershipListenerCreator(listener));
56 private static final class EntityOwnershipListenerCreator implements Creator<EntityOwnershipListenerActor> {
57 private static final long serialVersionUID = 1L;
59 private final EntityOwnershipListener listener;
61 EntityOwnershipListenerCreator(EntityOwnershipListener listener) {
62 this.listener = Preconditions.checkNotNull(listener);
66 public EntityOwnershipListenerActor create() {
67 return new EntityOwnershipListenerActor(listener);