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
9 package org.opendaylight.mdsal.common.api;
11 import com.google.common.base.Supplier;
13 import org.opendaylight.yangtools.yang.common.RpcError;
14 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
15 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
21 * A type of TransactionCommitFailedException that indicates a situation that would result in a
22 * threading deadlock. This can occur if a caller that submits a write transaction tries to perform
23 * a blocking call via one of the <code>get</code> methods on the returned ListenableFuture. Callers
24 * should process the commit result asynchronously (via Futures#addCallback) to ensure deadlock
27 * @author Thomas Pantelis
29 public class TransactionCommitDeadlockException extends TransactionCommitFailedException {
30 private static final long serialVersionUID = 1L;
31 private static final String DEADLOCK_MESSAGE =
32 "An attempt to block on a ListenableFuture via a get method from a write "
34 "transaction submit was detected that would result in deadlock. The commit "
36 "result must be obtained asynchronously, e.g. via Futures#addCallback, to avoid deadlock.";
37 private static final RpcError DEADLOCK_RPCERROR =
38 RpcResultBuilder.newError(ErrorType.APPLICATION, "lock-denied", DEADLOCK_MESSAGE);
40 public static final Supplier<Exception> DEADLOCK_EXCEPTION_SUPPLIER = new Supplier<Exception>() {
42 public Exception get() {
43 return new TransactionCommitDeadlockException(DEADLOCK_MESSAGE, DEADLOCK_RPCERROR);
47 public TransactionCommitDeadlockException(final String message, final RpcError... errors) {
48 super(message, errors);