1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.tradefed.retry;
17 
18 /**
19  * A Class to describe the decisions about whether or not to retry preparation and to fail the
20  * module run. Overall, there would be 3 situations:
21  *   - NO_NEED_RETRY: No need to retry preparation but need to stop the module run.
22  *   - RETRIED_SUCCESS: No need to retry preparation and no need to stop the module run.
23  *   - RETRIED_FAILED: Need to retry preparation but no need to stop the module run.
24  */
25 public class RetryPreparationDecision {
26 
27     /** Decide whether or not to retry module preparation. */
28     private final boolean mShouldRetry;
29 
30     /** Decide whether or not to stop the module run. */
31     private final boolean mShouldFailRun;
32 
33     /** Store the previous exception after retrying. */
34     private Throwable mPreviousException;
35 
RetryPreparationDecision(boolean shouldRetry, boolean shouldFailRun)36     public RetryPreparationDecision(boolean shouldRetry, boolean shouldFailRun) {
37         mShouldRetry = shouldRetry;
38         mShouldFailRun = shouldFailRun;
39     }
40 
41     /** Returns whether or not to retry module preparation. */
shouldRetry()42     public boolean shouldRetry() {
43       return mShouldRetry;
44     }
45 
46     /** Returns whether or not to stop the module run. */
shouldFailRun()47     public boolean shouldFailRun() {
48         return mShouldFailRun;
49     }
50 
51     /** Returns the previous exception after retrying. */
getPreviousException()52     public Throwable getPreviousException() {
53         return mPreviousException;
54     }
55 
56     /** Set the previous exception after retrying. */
setPreviousException(Throwable exception)57     public void setPreviousException(Throwable exception) {
58         mPreviousException = exception;
59     }
60 }
61