use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.
the class DispatchersTest method testGetDispatcher.
@Test
public void testGetDispatcher() {
akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
MessageDispatcher mockDispatcher = mock(MessageDispatcher.class);
doReturn(true).when(mockDispatchers).hasDispatcher(anyString());
doReturn(mockDispatcher).when(mockDispatchers).lookup(anyString());
Dispatchers dispatchers = new Dispatchers(mockDispatchers);
assertEquals(Dispatchers.CLIENT_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Client));
assertEquals(Dispatchers.TXN_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Transaction));
assertEquals(Dispatchers.SHARD_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Shard));
assertEquals(Dispatchers.NOTIFICATION_DISPATCHER_PATH, dispatchers.getDispatcherPath(Dispatchers.DispatcherType.Notification));
}
use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.
the class DispatchersTest method testGetDefaultDispatcher.
@Test
public void testGetDefaultDispatcher() {
akka.dispatch.Dispatchers mockDispatchers = mock(akka.dispatch.Dispatchers.class);
MessageDispatcher mockGlobalDispatcher = mock(MessageDispatcher.class);
doReturn(false).when(mockDispatchers).hasDispatcher(anyString());
doReturn(mockGlobalDispatcher).when(mockDispatchers).defaultGlobalDispatcher();
Dispatchers dispatchers = new Dispatchers(mockDispatchers);
for (Dispatchers.DispatcherType type : Dispatchers.DispatcherType.values()) {
assertEquals(mockGlobalDispatcher, dispatchers.getDispatcher(type));
}
}
use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.
the class ShardManager method onShutDown.
private void onShutDown() {
List<Future<Boolean>> stopFutures = new ArrayList<>(localShards.size());
for (ShardInformation info : localShards.values()) {
if (info.getActor() != null) {
LOG.debug("{}: Issuing gracefulStop to shard {}", persistenceId(), info.getShardId());
FiniteDuration duration = info.getDatastoreContext().getShardRaftConfig().getElectionTimeOutInterval().$times(2);
stopFutures.add(Patterns.gracefulStop(info.getActor(), duration, Shutdown.INSTANCE));
}
}
LOG.info("Shutting down ShardManager {} - waiting on {} shards", persistenceId(), stopFutures.size());
ExecutionContext dispatcher = new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client);
Future<Iterable<Boolean>> combinedFutures = Futures.sequence(stopFutures, dispatcher);
combinedFutures.onComplete(new OnComplete<Iterable<Boolean>>() {
@Override
public void onComplete(final Throwable failure, final Iterable<Boolean> results) {
LOG.debug("{}: All shards shutdown - sending PoisonPill to self", persistenceId());
self().tell(PoisonPill.getInstance(), self());
if (failure != null) {
LOG.warn("{}: An error occurred attempting to shut down the shards", persistenceId(), failure);
} else {
int nfailed = 0;
for (Boolean result : results) {
if (!result) {
nfailed++;
}
}
if (nfailed > 0) {
LOG.warn("{}: {} shards did not shut down gracefully", persistenceId(), nfailed);
}
}
}
}, dispatcher);
}
use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.
the class ShardManager method removeShard.
@SuppressWarnings("checkstyle:IllegalCatch")
private void removeShard(final ShardIdentifier shardId) {
final String shardName = shardId.getShardName();
final ShardInformation shardInformation = localShards.remove(shardName);
if (shardInformation == null) {
LOG.debug("{} : Shard replica {} is not present in list", persistenceId(), shardId.toString());
return;
}
final ActorRef shardActor = shardInformation.getActor();
if (shardActor != null) {
long timeoutInMS = Math.max(shardInformation.getDatastoreContext().getShardRaftConfig().getElectionTimeOutInterval().$times(3).toMillis(), 10000);
LOG.debug("{} : Sending Shutdown to Shard actor {} with {} ms timeout", persistenceId(), shardActor, timeoutInMS);
final Future<Boolean> stopFuture = Patterns.gracefulStop(shardActor, FiniteDuration.apply(timeoutInMS, TimeUnit.MILLISECONDS), Shutdown.INSTANCE);
final CompositeOnComplete<Boolean> onComplete = new CompositeOnComplete<Boolean>() {
@Override
public void onComplete(final Throwable failure, final Boolean result) {
if (failure == null) {
LOG.debug("{} : Successfully shut down Shard actor {}", persistenceId(), shardActor);
} else {
LOG.warn("{}: Failed to shut down Shard actor {}", persistenceId(), shardActor, failure);
}
self().tell((RunnableMessage) () -> {
// At any rate, invalidate primaryShardInfo cache
primaryShardInfoCache.remove(shardName);
shardActorsStopping.remove(shardName);
notifyOnCompleteTasks(failure, result);
}, ActorRef.noSender());
}
};
shardActorsStopping.put(shardName, onComplete);
stopFuture.onComplete(onComplete, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
LOG.debug("{} : Local Shard replica for shard {} has been removed", persistenceId(), shardName);
persistShardList();
}
use of org.opendaylight.controller.cluster.common.actor.Dispatchers in project controller by opendaylight.
the class ShardManager method findPrimary.
private void findPrimary(final String shardName, final FindPrimaryResponseHandler handler) {
Timeout findPrimaryTimeout = new Timeout(datastoreContextFactory.getBaseDatastoreContext().getShardInitializationTimeout().duration().$times(2));
Future<Object> futureObj = ask(getSelf(), new FindPrimary(shardName, true), findPrimaryTimeout);
futureObj.onComplete(new OnComplete<Object>() {
@Override
public void onComplete(final Throwable failure, final Object response) {
if (failure != null) {
handler.onFailure(failure);
} else {
if (response instanceof RemotePrimaryShardFound) {
handler.onRemotePrimaryShardFound((RemotePrimaryShardFound) response);
} else if (response instanceof LocalPrimaryShardFound) {
handler.onLocalPrimaryFound((LocalPrimaryShardFound) response);
} else {
handler.onUnknownResponse(response);
}
}
}
}, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
}
Aggregations