/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public override void Run(Mapper.Context context) { Setup(context); int numMappers = chain.GetAllMappers().Count; if (numMappers == 0) { return; } Chain.ChainBlockingQueue <Chain.KeyValuePair <object, object> > inputqueue; Chain.ChainBlockingQueue <Chain.KeyValuePair <object, object> > outputqueue; if (numMappers == 1) { chain.RunMapper(context, 0); } else { // add all the mappers with proper context // add first mapper outputqueue = chain.CreateBlockingQueue(); chain.AddMapper(context, outputqueue, 0); // add other mappers for (int i = 1; i < numMappers - 1; i++) { inputqueue = outputqueue; outputqueue = chain.CreateBlockingQueue(); chain.AddMapper(inputqueue, outputqueue, context, i); } // add last mapper chain.AddMapper(outputqueue, context, numMappers - 1); } // start all threads chain.StartAllThreads(); // wait for all threads chain.JoinAllThreads(); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public override void Run(Reducer.Context context) { Setup(context); // if no reducer is set, just do nothing if (chain.GetReducer() == null) { return; } int numMappers = chain.GetAllMappers().Count; // if there are no mappers in chain, run the reducer if (numMappers == 0) { chain.RunReducer(context); return; } // add reducer and all mappers with proper context Chain.ChainBlockingQueue <Chain.KeyValuePair <object, object> > inputqueue; Chain.ChainBlockingQueue <Chain.KeyValuePair <object, object> > outputqueue; // add reducer outputqueue = chain.CreateBlockingQueue(); chain.AddReducer(context, outputqueue); // add all mappers except last one for (int i = 0; i < numMappers - 1; i++) { inputqueue = outputqueue; outputqueue = chain.CreateBlockingQueue(); chain.AddMapper(inputqueue, outputqueue, context, i); } // add last mapper chain.AddMapper(outputqueue, context, numMappers - 1); // start all threads chain.StartAllThreads(); // wait for all threads chain.JoinAllThreads(); }