p.magalhaes
p.magalhaes

Reputation: 8374

Dependency Injection on Mapper and Reduce

I would like to inject a class in my mapper and reduce function. Is there any method that I can use to pass an instance of an object and inside mapper/reduce I can get the same instance?

Probably using the configuration...

Upvotes: 0

Views: 127

Answers (1)

Chris Hinshaw
Chris Hinshaw

Reputation: 7285

If your using guice it is easy. Otherwise I think you may be out of luck since hadoop uses reflection to construct your mapper and reducer.

The Mapper and Reducer classes have an empty method for setup(); This is where I inject my dependencies.

/**
 * Called once at the beginning of the task.
 */
protected void setup(Context context) throws IOException, InterruptedException {
    IOCJobInjector.getInjector().injectMembers(this);
}

Upvotes: 2

Related Questions