Bug#1854 - Exit command in console causing OOM.
[controller.git] / opendaylight / md-sal / sal-common-api / src / main / java / org / opendaylight / controller / md / sal / common / api / data / 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.controller.md.sal.common.api.data;
10
11 import org.opendaylight.yangtools.yang.common.RpcError;
12 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
13 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
14
15 import com.google.common.base.Function;
16
17 /**
18  * A type of TransactionCommitFailedException that indicates a situation that would result in a
19  * threading deadlock. This can occur if a caller that submits a write transaction tries to perform
20  * a blocking call via one of the <code>get</code> methods on the returned ListenableFuture. Callers
21  * should process the commit result asynchronously (via Futures#addCallback) to ensure deadlock
22  * won't occur.
23  *
24  * @author Thomas Pantelis
25  */
26 public class TransactionCommitDeadlockException extends TransactionCommitFailedException {
27
28     private static final long serialVersionUID = 1L;
29
30     private static final String DEADLOCK_MESSAGE =
31             "An attempt to block on a ListenableFuture via a get method from a write " +
32             "transaction submit was detected that would result in deadlock. The commit " +
33             "result must be obtained asynchronously, e.g. via Futures#addCallback, to avoid deadlock.";
34
35     public static Function<Void, Exception> DEADLOCK_EXECUTOR_FUNCTION = new Function<Void, Exception>() {
36         @Override
37         public Exception apply(Void notUsed) {
38             return new TransactionCommitDeadlockException( DEADLOCK_MESSAGE,
39                     RpcResultBuilder.newError(ErrorType.APPLICATION, "lock-denied", DEADLOCK_MESSAGE));
40         }
41     };
42
43     public TransactionCommitDeadlockException(String message, final RpcError... errors) {
44         super(message, errors);
45     }
46 }