Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Driver Lifecycle Annotations

Patrick Jaromin edited this page Apr 13, 2015 · 2 revisions

Lifecycle Annotations: @Validate, @DriverInit, @JobInit, and @DriverCleanup

@Driver is used to mark up your driver class and optionally provide a friendly name or id for the container, a description, and a version. Special lifecycle annotations may then be applied to methods in the driver class to be called by the container at the appropriate time.

annotation target Comments
@Driver CLASS Identifies a driver for a mapreduce job
@Validate METHOD Called following context creation and immediately before Job creation and initialization. The distinction between @Validate and @DriverInit is purely semantic.
@DriverInit METHOD Called just after @Validate method(s)
@JobInit METHOD Called immediately after job initialization
@DriverCleanup METHOD Called after the job is complete before the driver exits.

Example

@Driver(listener=WordCountListener.class)
public class AnnotatedWordCountWithListener {
   
   @JobInfo // config annotations omitted...
   private Job job;

   @DriverInit
   public void initializeDriver() {
     // ...something useful
   }

   @DriverInit
   public void anotherInit() { 
     // ... can have multiple if desired
   }

   @JobInit
   public void jobStuff() {
     // ...job has been created, can access here
   }

   @DriverCleanup
   public void cleanUp() {
     // ...something useful
   }
}