Fixed Checkstyle violation errors in mdsal-common-api
[mdsal.git] / common / mdsal-common-api / src / main / java / org / opendaylight / mdsal / common / api / TransactionCommitDeadlockException.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.mdsal.common.api;
10
11 import com.google.common.base.Supplier;
12
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;
16
17
18
19
20 /**
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
25  * won't occur.
26  *
27  * @author Thomas Pantelis
28  */
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 "
33                     +
34                     "transaction submit was detected that would result in deadlock. The commit "
35                     +
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);
39
40     public static final Supplier<Exception> DEADLOCK_EXCEPTION_SUPPLIER = new Supplier<Exception>() {
41         @Override
42         public Exception get() {
43             return new TransactionCommitDeadlockException(DEADLOCK_MESSAGE, DEADLOCK_RPCERROR);
44         }
45     };
46
47     public TransactionCommitDeadlockException(final String message, final RpcError... errors) {
48         super(message, errors);
49     }
50 }