Example #1
0
  @Override
  public void start(String adaptorID, String type, long offset, ChunkReceiver dest)
      throws AdaptorException {
    try {
      String dummyAdaptorID = adaptorID;
      this.dest = dest;

      outBuf = new File(BUF_DIR, adaptorID);
      long newOffset = offset;
      if (outBuf.length() > 0) {
        DataInputStream dis = new DataInputStream(new FileInputStream(outBuf));
        while (dis.available() > 0) {
          Chunk c = ChunkImpl.read(dis);
          fSize += c.getData().length;
          long seq = c.getSeqID();
          if (seq > offset) {
            dest.add(c);
            newOffset = seq;
          }
        }
        // send chunks that are outstanding
        dis.close();
      }
      outToDisk = new DataOutputStream(new FileOutputStream(outBuf, true));

      inner.start(dummyAdaptorID, innerType, newOffset, this);
    } catch (IOException e) {
      throw new AdaptorException(e);
    } catch (InterruptedException e) {
      throw new AdaptorException(e);
    }
  }
Example #2
0
  @Override
  public void committed(long l) {

    try {
      long bytesOutstanding = highestSentOffset - l;
      if (fSize - bytesOutstanding > COMPACT_AT) {
        fSize = 0;
        outToDisk.close();
        File outBufTmp = new File(outBuf.getAbsoluteFile(), outBuf.getName() + ".tmp");
        if (!outBuf.renameTo(outBufTmp)) {
          log.warn(
              "Cannot rename temp file "
                  + outBuf.getAbsolutePath()
                  + " to "
                  + outBufTmp.getAbsolutePath());
        }
        ;
        outToDisk = new DataOutputStream(new FileOutputStream(outBuf, false));
        DataInputStream dis = new DataInputStream(new FileInputStream(outBufTmp));
        while (dis.available() > 0) {
          Chunk c = ChunkImpl.read(dis);
          if (c.getSeqID() > l) { // not yet committed
            c.write(outToDisk);
            fSize += c.getData().length;
          }
        }
        dis.close();
        if (!outBufTmp.delete()) {
          log.warn("Can not delete temp file: " + outBufTmp.getAbsolutePath());
        }
        ;
      }
    } catch (IOException e) {
      log.error(e);
      // should this be fatal?
    }
  }