2 * Copyright (c) 2017 Cisco 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
9 package org.opendaylight.controller.cluster.sharding;
11 import static akka.actor.ActorRef.noSender;
13 import akka.actor.ActorRef;
14 import akka.actor.Status;
15 import javax.annotation.Nullable;
16 import javax.annotation.concurrent.NotThreadSafe;
19 * Base class for lookup tasks. Lookup tasks are supposed to run repeatedly
20 * until successful lookup or maximum retries are hit.
23 abstract class LookupTask implements Runnable {
24 private final int maxRetries;
25 private final ActorRef replyTo;
26 private int retries = 0;
28 LookupTask(final ActorRef replyTo, final int maxRetries) {
29 this.replyTo = replyTo;
30 this.maxRetries = maxRetries;
33 abstract void reschedule(int retries);
35 void tryReschedule(@Nullable final Throwable throwable) {
36 if (retries <= maxRetries) {
44 void fail(@Nullable final Throwable throwable) {
45 if (throwable == null) {
46 replyTo.tell(new Status.Failure(
47 new DOMDataTreeShardCreationFailedException("Unable to find the backend shard."
48 + "Failing..")), noSender());
50 replyTo.tell(new Status.Failure(
51 new DOMDataTreeShardCreationFailedException("Unable to find the backend shard."
52 + "Failing..", throwable)), noSender());