Ejemplo n.º 1
0
  /**
   * Combine the actual line data. The data is read line for line and then appended one after the
   * other and then written to the file.
   *
   * <p>The order of the files is maintained so that the data is not corrupted once the writing out
   * to the final result file is performed.
   *
   * @param writer destination of the final output.
   * @param partials list of partial results.
   */
  private void combineData(final BufferedWriter writer, final List<File> partials) {
    List<BufferedReader> readers = Lists.newArrayListWithCapacity(partials.size());
    for (File f : partials) {
      try {
        InputStreamReader is =
            new InputStreamReader(new FileInputStream(f), Charset.forName("UTF-8"));
        readers.add(new BufferedReader(is));
      } catch (FileNotFoundException ex) {
        throw new RuntimeException(ex);
      }
    }

    try {
      BufferedReader checkReader = readers.get(0); // There will always be at least 1
      String checkLine = checkReader.readLine();
      String[] parts = checkLine.split(" ");
      Entry entry = new Entry(parts[0], parts.length - 1);
      for (int i = 1; i < parts.length; i++) {
        entry.add(i - 1, parts[i]);
      }

      List<BufferedReader> loopingList = readers.subList(1, readers.size());
      while (checkLine != null) {
        for (BufferedReader reader : loopingList) {
          String string = reader.readLine();
          String[] localParts = string.split(" ");
          for (int i = 1; i < localParts.length; i++) {
            entry.add(i - 1, localParts[i]);
          }
        }

        writer.write(entry.toString());
        writer.newLine();
        checkLine = checkReader.readLine();

        if (checkLine != null) {
          parts = checkLine.split(" ");
          entry = new Entry(parts[0], parts.length - 1);
          for (int i = 1; i < parts.length; i++) {
            entry.add(i - 1, parts[i]);
          }
        }
      }

      for (BufferedReader reader : readers) {
        reader.close();
      }

      for (File f : partials) {
        f.delete();
      }
    } catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }
 public void add(
     final String field, final ExternalIdBundle idBundle, final HistoricalTimeSeries timeSeries) {
   ArgumentChecker.notNull(field, "field");
   ArgumentChecker.notNull(idBundle, "idBundle");
   ArgumentChecker.notNull(timeSeries, "timeSeries");
   Entry e = _data.get(field);
   if (e == null) {
     e = new Entry();
     _data.put(field, e);
   }
   e.add(idBundle, timeSeries);
 }
 public static Entry fromFudgeMsg(final FudgeDeserializer context, final FudgeMsg msg) {
   final Entry e = new Entry();
   final Iterator<FudgeField> keys = msg.getAllByOrdinal(1).iterator();
   final Iterator<FudgeField> values = msg.getAllByOrdinal(2).iterator();
   while (keys.hasNext() && values.hasNext()) {
     final FudgeField key = keys.next();
     final FudgeField value = values.next();
     e.add(
         context.fieldValueToObject(ExternalIdBundle.class, key),
         context.fieldValueToObject(HistoricalTimeSeries.class, value));
   }
   return e;
 }
Ejemplo n.º 4
0
  public Future<?> schedule(Runnable work, long delay, TimeUnit unit) {
    if (work == null) return null;

    Future<?> retval = null;

    long key =
        System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(delay, unit); // execution time
    Entry task = new Entry(work);
    while (!isShutdown()) {
      Entry existing = tasks.putIfAbsent(key, task);
      if (existing == null) {
        retval = task.getFuture();
        break; // break out of the while loop
      }
      if ((retval = existing.add(work)) != null) break;
    }

    if (key < next_execution_time || no_tasks.compareAndSet(true, false)) {
      if (key >= next_execution_time) key = 0L;
      taskReady(key);
    }

    return retval;
  }
Ejemplo n.º 5
0
 /*
  * Given a protocol objects and a client, ensure there's an entry for the
  * client and add the protocol object.
  */
 private void addObject(Client c, Map<Client, Entry> entries, ProtocolObject o) {
   Entry e = ensureEntry(c, entries);
   e.add(o);
 }