2 * Copyright (c) 2014 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.mdsal.common.api;
10 import java.util.function.Supplier;
11 import org.opendaylight.yangtools.yang.common.ErrorTag;
12 import org.opendaylight.yangtools.yang.common.ErrorType;
13 import org.opendaylight.yangtools.yang.common.RpcError;
14 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
17 * A type of TransactionCommitFailedException that indicates a situation that would result in a
18 * threading deadlock. This can occur if a caller that submits a write transaction tries to perform
19 * a blocking call via one of the <code>get</code> methods on the returned ListenableFuture. Callers
20 * should process the commit result asynchronously (via Futures#addCallback) to ensure deadlock
23 * @author Thomas Pantelis
25 public class TransactionCommitDeadlockException extends TransactionCommitFailedException {
26 private static final long serialVersionUID = 1L;
27 private static final String DEADLOCK_MESSAGE = "An attempt to block on a ListenableFuture via a get method from a "
28 + "write transaction submit was detected that would result in deadlock. The commit result must be obtained "
29 + "asynchronously, e.g. via Futures#addCallback, to avoid deadlock.";
30 private static final RpcError DEADLOCK_RPCERROR =
31 RpcResultBuilder.newError(ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, DEADLOCK_MESSAGE);
33 public static final Supplier<Exception> DEADLOCK_EXCEPTION_SUPPLIER =
34 () -> new TransactionCommitDeadlockException(DEADLOCK_MESSAGE, DEADLOCK_RPCERROR);
36 public TransactionCommitDeadlockException(final String message, final RpcError... errors) {
37 super(message, errors);