2 * Copyright (c) 2017 Inocybe Technologies 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.utils;
10 import akka.dispatch.OnComplete;
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
17 * An OnComplete implementation that aggrgates other OnComplete tasks.
19 * @author Thomas Pantelis
21 * @param <T> the result type
23 public abstract class CompositeOnComplete<T> extends OnComplete<T> {
24 private static final Logger LOG = LoggerFactory.getLogger(CompositeOnComplete.class);
26 private final List<OnComplete<T>> onCompleteTasks = new ArrayList<>();
28 public void addOnComplete(OnComplete<T> task) {
29 onCompleteTasks.add(task);
32 @SuppressWarnings({ "checkstyle:IllegalCatch", "squid:S1181" /* Throwable and Error should not be caught */ })
33 protected void notifyOnCompleteTasks(Throwable failure, T result) {
34 for (OnComplete<T> task: onCompleteTasks) {
36 task.onComplete(failure, result);
37 } catch (Throwable e) {
38 LOG.error("Caught unexpected exception", e);
42 onCompleteTasks.clear();