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.ActorRef;
11 import akka.dispatch.OnComplete;
12 import akka.util.Timeout;
13 import java.util.concurrent.TimeUnit;
14 import org.opendaylight.controller.cluster.datastore.DistributedDataStore;
15 import org.opendaylight.controller.cluster.datastore.messages.CreateShard;
16 import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException;
17 import org.opendaylight.controller.md.sal.common.api.clustering.Entity;
18 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidate;
19 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration;
20 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListener;
21 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipListenerRegistration;
22 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import scala.concurrent.Future;
28 * The distributed implementation of the EntityOwnershipService.
30 * @author Thomas Pantelis
32 public class DistributedEntityOwnershipService implements EntityOwnershipService, AutoCloseable {
33 private static final Logger LOG = LoggerFactory.getLogger(DistributedEntityOwnershipService.class);
34 static final String ENTITY_OWNERSHIP_SHARD_NAME = "entity-ownership";
35 private static final Timeout MESSAGE_TIMEOUT = new Timeout(1, TimeUnit.MINUTES);
37 private final DistributedDataStore datastore;
39 public DistributedEntityOwnershipService(DistributedDataStore datastore) {
40 this.datastore = datastore;
44 ActorRef shardManagerActor = datastore.getActorContext().getShardManager();
46 CreateShard createShard = new CreateShard(ENTITY_OWNERSHIP_SHARD_NAME,
47 datastore.getActorContext().getConfiguration().getUniqueMemberNamesForAllShards(),
48 new EntityOwnershipShardPropsCreator(), null);
50 Future<Object> createFuture = datastore.getActorContext().executeOperationAsync(shardManagerActor,
51 createShard, MESSAGE_TIMEOUT);
53 createFuture.onComplete(new OnComplete<Object>() {
55 public void onComplete(Throwable failure, Object response) {
57 LOG.error("Failed to create {} shard", ENTITY_OWNERSHIP_SHARD_NAME);
59 LOG.info("Successfully created {} shard", ENTITY_OWNERSHIP_SHARD_NAME);
62 }, datastore.getActorContext().getClientDispatcher());
66 public EntityOwnershipCandidateRegistration registerCandidate(Entity entity, EntityOwnershipCandidate candidate)
67 throws CandidateAlreadyRegisteredException {
68 // TODO Auto-generated method stub
73 public EntityOwnershipListenerRegistration registerListener(Entity entity, EntityOwnershipListener listener) {
74 // TODO Auto-generated method stub