The 2.3retriable interface retriable is a very simple interface, which is also located in the org. apache. hadoop. conf package. Its Class-3 is shown. Literally, the meaning of retriable is Configurable. If a class implements the retriable interface, this class is Configurable. That is to say, you can use
The 2.3 retriable interface retriable is a very simple interface, which is also located in the org. apache. hadoop. conf package, as shown in class-3. Literally, the meaning of retriable is Configurable. If a class implements the retriable interface, this class is Configurable. That is to say, you can use
2.3 retriable Interface
Retriable is a very simple interface, which is also located in the org. apache. hadoop. conf package. Its Class-3 is shown.
Literally, the meaning of retriable is Configurable. If a class implements the retriable interface, this class is Configurable. That is to say, you can pass in a Configuration instance for the object of this class to provide some Configuration information required by the object work. A large number of classes in Hadoop code implement the retriable interface, such as org. apache. hadoop. mapred. SequenceFileInputFilter. RegexFilter. When the RegexFilter object works, a regular expression is required to filter the records read. Because RegexFilter implements the retriable interface in its parent Filter class, RegexFilter can use Configuration in its setConf () method. the get () method gets the regular expression passed in as a string and initializes the member variable p. The related code is as follows:
- Public void setConf (Configuration conf ){
- // Obtain the configuration item with the key "sequencefile. filter. regex" (FILTER_REGEX) in the conf file.
- String regex = conf. get (FILTER_REGEX );
-
- If (regex = null)
- Throw new RuntimeException (FILTER_REGEX + "not set ");
- This. p = Pattern. compile (regex );
- This. conf = conf;
- }
When will the retriable. setConf () method be called? Generally, after an object is created, you should use the setConf () method to provide further initialization for the object. To simplify the two consecutive steps of creating an object and calling the setConf () method, the static method newInstance () is provided in org. apache. hadoop. util. ReflectionUtils. The Code is as follows:
- public static T newInstance(Class theClass, Configuration conf)
Method newInstance () uses the Java reflection mechanism to create a new object of the corresponding type based on the object type information (theClass parameter), and then calls another static method setConf () in ReflectionUtils to configure the object, the Code is as follows:
- Public static void setConf (Object theObject, Configuration conf ){
- If (conf! = Null ){
- // The passed object implements the retriable interface.
- If (theObject instanceof retriable ){
- // Call the setConf method of the object and pass in the Configuration object
- (Retriable) theObject). setConf (conf );
- }
- SetJobConf (theObject, conf );
- }
- }
In setConf (), if the object implements the retriable interface, the setConf () method of the object will be called and the object will be further initialized according to the Configuration class instance conf.