Пример #1
0
 public void run() {
   // TODO Auto-generated method stub
   run = true;
   System.out.println("Running a map");
   while (run) {
     // Figure out how to read input file
     // Evaluate it
     Map<String, List<String>> input = reader.getKeyValuePairs();
     if (input == null) {
       map.setStatus(-1);
       Message msg = new Message();
       msg.setTask(map);
       msg.setType('f');
       coord.conn.sendMessage(msg);
       return;
     }
     OutputCollector<String, String> collect = new OutputCollector<String, String>();
     Set<String> keySet = input.keySet();
     for (String key : keySet) {
       List<String> values = input.get(key);
       for (String value : values) {
         map.getJob().map(key, value, collect);
       }
     }
     List<Pair> results = collect.getResults();
     int length = results.size();
     FileOutputStream out;
     try {
       System.out.println("Trying to Write to File");
       out = new FileOutputStream(new File(map.getOutput().get(0)));
       BufferedWriter dw = new BufferedWriter(new OutputStreamWriter(out));
       for (Pair p : results) {
         dw.append(p.toString());
         dw.newLine();
       }
       dw.newLine();
       dw.flush();
       dw.close();
       out.close();
       coord.dataNode.addFileToDFS(map.getOutput().get(0), coord.conn.port, false);
     } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
       map.setStatus(-1);
       Message msg = new Message();
       msg.setTask(map);
       msg.setType('f');
       coord.conn.sendMessage(msg);
       return;
     }
     map.setStatus(1);
     Message msg = new Message();
     msg.setTask(map);
     msg.setType('f');
     coord.conn.sendMessage(msg);
     break;
   }
 }
Пример #2
0
 public RunMap(MapTask m, SlaveCoordinator coordinator) {
   map = m;
   coord = coordinator;
   RandomAccessFile read;
   try {
     read = new RandomAccessFile((m.getInput()).get(0), "r");
     List<RandomAccessFile> readers = new LinkedList<RandomAccessFile>();
     readers.add(read);
     reader = new RecordReader(readers, m.recordlength, true);
   } catch (FileNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }