2.3retriable Interface

Source: Internet
Author: User
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:

 
 
  1. Public void setConf (Configuration conf ){
  2. // Obtain the configuration item with the key "sequencefile. filter. regex" (FILTER_REGEX) in the conf file.
  3. String regex = conf. get (FILTER_REGEX );
  4. If (regex = null)
  5. Throw new RuntimeException (FILTER_REGEX + "not set ");
  6. This. p = Pattern. compile (regex );
  7. This. conf = conf;
  8. }

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:

 
 
  1. 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:

 
 
  1. Public static void setConf (Object theObject, Configuration conf ){
  2. If (conf! = Null ){
  3. // The passed object implements the retriable interface.
  4. If (theObject instanceof retriable ){
  5. // Call the setConf method of the object and pass in the Configuration object
  6. (Retriable) theObject). setConf (conf );
  7. }
  8. SetJobConf (theObject, conf );
  9. }
  10. }

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.