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
8 package org.opendaylight.controller.cluster.sharding;
10 import static akka.actor.ActorRef.noSender;
12 import akka.actor.ActorRef;
13 import akka.actor.Status;
14 import javax.annotation.concurrent.NotThreadSafe;
15 import org.eclipse.jdt.annotation.Nullable;
18 * Base class for lookup tasks. Lookup tasks are supposed to run repeatedly
19 * until successful lookup or maximum retries are hit.
22 abstract class LookupTask implements Runnable {
23 private final int maxRetries;
24 private final ActorRef replyTo;
25 private int retried = 0;
27 LookupTask(final ActorRef replyTo, final int maxRetries) {
28 this.replyTo = replyTo;
29 this.maxRetries = maxRetries;
32 abstract void reschedule(int retries);
34 void tryReschedule(final @Nullable Throwable throwable) {
35 if (retried <= maxRetries) {
43 void fail(final @Nullable Throwable throwable) {
44 if (throwable == null) {
45 replyTo.tell(new Status.Failure(
46 new DOMDataTreeShardCreationFailedException("Unable to find the backend shard."
47 + "Failing..")), noSender());
49 replyTo.tell(new Status.Failure(
50 new DOMDataTreeShardCreationFailedException("Unable to find the backend shard."
51 + "Failing..", throwable)), noSender());