View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.client;
19  
20  import org.apache.commons.lang.mutable.MutableBoolean;
21  import org.apache.hadoop.hbase.ServerName;
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  
24  @InterfaceAudience.Private
25  class FastFailInterceptorContext extends
26      RetryingCallerInterceptorContext {
27  
28    // The variable that indicates whether we were able to connect with the server
29    // in the last run
30    private MutableBoolean couldNotCommunicateWithServer = new MutableBoolean(
31        false);
32  
33    // The variable which indicates whether this was a retry or the first time
34    private boolean didTry = false;
35  
36    // The failure info that is associated with the machine which we are trying to
37    // contact as part of this attempt.
38    private FailureInfo fInfo = null;
39  
40    // Variable indicating that the thread that is currently executing the
41    // operation is in a mode where it would retry instead of failing fast, so
42    // that we can figure out whether making contact with the server is
43    // possible or not.
44    private boolean retryDespiteFastFailMode = false;
45  
46    // The server that would be contacted to successfully complete this operation.
47    private ServerName server;
48  
49    // The number of the retry we are currenty doing.
50    private int tries;
51  
52    public MutableBoolean getCouldNotCommunicateWithServer() {
53      return couldNotCommunicateWithServer;
54    }
55  
56    public FailureInfo getFailureInfo() {
57      return fInfo;
58    }
59  
60    public ServerName getServer() {
61      return server;
62    }
63  
64    public int getTries() {
65      return tries;
66    }
67  
68    public boolean didTry() {
69      return didTry;
70    }
71  
72    public boolean isRetryDespiteFastFailMode() {
73      return retryDespiteFastFailMode;
74    }
75  
76    public void setCouldNotCommunicateWithServer(
77        MutableBoolean couldNotCommunicateWithServer) {
78      this.couldNotCommunicateWithServer = couldNotCommunicateWithServer;
79    }
80  
81    public void setDidTry(boolean didTry) {
82      this.didTry = didTry;
83    }
84  
85    public void setFailureInfo(FailureInfo fInfo) {
86      this.fInfo = fInfo;
87    }
88  
89    public void setRetryDespiteFastFailMode(boolean retryDespiteFastFailMode) {
90      this.retryDespiteFastFailMode = retryDespiteFastFailMode;
91    }
92  
93    public void setServer(ServerName server) {
94      this.server = server;
95    }
96  
97    public void setTries(int tries) {
98      this.tries = tries;
99    }
100 
101   public void clear() {
102     server = null;
103     fInfo = null;
104     didTry = false;
105     couldNotCommunicateWithServer.setValue(false);
106     retryDespiteFastFailMode = false;
107     tries = 0;
108   }
109 
110   public FastFailInterceptorContext prepare(RetryingCallable<?> callable) {
111     return prepare(callable, 0);
112   }
113 
114   public FastFailInterceptorContext prepare(RetryingCallable<?> callable,
115       int tries) {
116     if (callable instanceof RegionServerCallable) {
117       RegionServerCallable<?> retryingCallable = (RegionServerCallable<?>) callable;
118       server = retryingCallable.getLocation().getServerName();
119     }
120     this.tries = tries;
121     return this;
122   }
123 }