Ejemplo n.º 1
0
  protected void eq(Buf buf, String expected) {
    eq(buf.size(), expected.getBytes().length);
    eq(buf.data(), expected);

    byte[] bbytes = new byte[buf.size()];
    ByteBuffer bufy = ByteBuffer.wrap(bbytes);
    buf.writeTo(bufy);
    eq(new String(bbytes), expected);

    int size = (int) Math.ceil(expected.length() * 1.0 / buf.unitSize());
    isTrue(buf.unitCount() == size || buf.unitCount() == size + 1);

    byte[] bytes = expected.getBytes();
    synchronized (buf) {
      for (int i = 0; i < bytes.length; i++) {
        eq((char) buf.get(i), (char) bytes[i]);
      }
    }

    for (int len = 2; len < 10; len++) {
      for (int p = 0; p <= buf.size() - len; p++) {
        String sub = buf.get(new BufRange(p, len));
        eq(sub, expected.substring(p, p + len));
      }
    }
  }
Ejemplo n.º 2
0
  protected Buf buf(String content) {
    BufGroup bufs = new BufGroup(4);
    Buf buf = bufs.newBuf();

    eq(buf, "");

    buf.append(content);

    return buf;
  }
Ejemplo n.º 3
0
 @Override
 public void sendReceive(
     int toRank, int sendTag, Buf sendBuf, int fromRank, int recvTag, Buf recvBuf)
     throws IOException {
   comm.sendReceive(
       toRank,
       sendTag,
       (edu.rit.mp.Buf) sendBuf.getBuffer(),
       fromRank,
       recvTag,
       (edu.rit.mp.Buf) recvBuf.getBuffer());
 }
Ejemplo n.º 4
0
  @Override
  public void scatter(int root, int tag, Buf[] srcBuffers, Buf dstBuffer) throws IOException {
    if (srcBuffers == null) {
      comm.scatter(root, null, (edu.rit.mp.Buf) dstBuffer.getBuffer());
      return;
    }

    edu.rit.mp.Buf[] srcarray = new edu.rit.mp.Buf[srcBuffers.length];

    for (int i = 0; i < srcBuffers.length; i++)
      srcarray[i] = (edu.rit.mp.Buf) srcBuffers[i].getBuffer();

    comm.scatter(root, tag, srcarray, (edu.rit.mp.Buf) dstBuffer.getBuffer());
  }
Ejemplo n.º 5
0
  public static void main(String... args) throws Exception {
    DefaultObjectModel om = new DefaultObjectModel(args[1]);
    om.setWrapper(Class.forName(args[2]));

    CompactReader rd = new CompactReader(om);
    String task = args[0];

    if (task.equals("roundtrip")) {
      DefaultBlock result = new DefaultBlock();
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      CompactWriter wr = new CompactWriter(om, os);
      int count = 0;
      long decTime = 0;
      long encTime = 0;

      FileInputStream is = new FileInputStream(args[3]);

      Buf buf = DirectBuf.newInstance();

      try {
        for (; ; ) {
          if (!buf.fillFrom(is)) break;

          buf.flip();
          result.clear();
          os.reset();

          long t1 = System.currentTimeMillis();
          rd.read(buf, result);
          long t2 = System.currentTimeMillis();
          for (Object o : result) wr.write(o);
          wr.flush();
          long t3 = System.currentTimeMillis();
          decTime += t2 - t1;
          encTime += t3 - t2;
          count += result.size();
        }
      } finally {
        is.close();
      }

      System.out.printf(
          "Decoded %d msgs in %d ms (%.2f msgs/s)%n",
          count, decTime, 1000 * (double) count / (double) decTime);
      System.out.printf(
          "Encoded %d msgs in %d ms (%.2f msgs/s)%n",
          count, encTime, 1000 * (double) count / (double) encTime);
    } else throw new RuntimeException("Unknown PerfTest task: " + task);
  }
Ejemplo n.º 6
0
  @Override
  public void gather(int root, int tag, Buf srcBuffer, Buf[] dstBuffers) throws IOException {
    if (dstBuffers == null) {
      comm.gather(root, tag, (edu.rit.mp.Buf) srcBuffer.getBuffer(), null);
      return;
    }

    edu.rit.mp.Buf[] dstarray = new edu.rit.mp.Buf[dstBuffers.length];

    for (int i = 0; i < dstBuffers.length; i++) {
      dstarray[i] = (edu.rit.mp.Buf) dstBuffers[i].getBuffer();
    }

    comm.gather(root, tag, (edu.rit.mp.Buf) srcBuffer.getBuffer(), dstarray);
  }
Ejemplo n.º 7
0
 public void write() {
   if (!isPopulated()) {
     Flog.warn("Unable to write %s because it's not populated yet.", path);
     return;
   }
   VirtualFile virtualFile = getVirtualFile();
   if (virtualFile == null) {
     virtualFile = createFile();
     if (virtualFile == null) {
       context.errorMessage("The Floobits plugin was unable to write to a file.");
       return;
     }
   }
   Document d = Buf.getDocumentForVirtualFile(virtualFile);
   if (d != null) {
     try {
       Listener.flooDisable();
       d.setReadOnly(false);
       d.setText(buf);
     } finally {
       Listener.flooEnable();
     }
     return;
   }
   Flog.warn("Tried to write to null document: %s", path);
   try {
     virtualFile.setBinaryContent(buf.getBytes());
   } catch (IOException e) {
     Flog.warn(e);
     context.errorMessage("The Floobits plugin was unable to write to a file.");
   }
 }
Ejemplo n.º 8
0
 public void send_patch(VirtualFile virtualFile) {
   Document d = Buf.getDocumentForVirtualFile(virtualFile);
   if (d == null) {
     Flog.warn("Can't get document to read from disk for sending patch %s", path);
     return;
   }
   send_patch(d.getText());
 }
Ejemplo n.º 9
0
 public Long readBuf(Buf buf, long n) {
   try {
     long read = buf.pipeFrom(in, n);
     if (read < 0) return null;
     return Long.valueOf(read);
   } catch (IOException e) {
     throw IOErr.make(e);
   }
 }
Ejemplo n.º 10
0
 public void read() {
   VirtualFile virtualFile = this.getVirtualFile();
   if (virtualFile == null) {
     Flog.warn("Can't get virtual file to read from disk %s", this);
     return;
   }
   Document d = Buf.getDocumentForVirtualFile(virtualFile);
   if (d == null) {
     Flog.warn("Can't get document to read from disk %s", this);
     return;
   }
   this.buf = d.getText();
   this.md5 = DigestUtils.md5Hex(this.buf);
 }
Ejemplo n.º 11
0
 @Override
 public synchronized long checkpoint() {
   return buf.checkpoint();
 }
Ejemplo n.º 12
0
 @Override
 public synchronized void checkpoint(long checkpoint) {
   buf.checkpoint(checkpoint);
 }
Ejemplo n.º 13
0
 @Override
 public synchronized void setReadOnly(boolean readOnly) {
   buf.setReadOnly(readOnly);
 }
Ejemplo n.º 14
0
 @Override
 public synchronized void append(byte[] bytes, int offset, int length) {
   buf.append(bytes, offset, length);
 }
Ejemplo n.º 15
0
 @Override
 public synchronized long append(String s) {
   return buf.append(s);
 }
Ejemplo n.º 16
0
 @Override
 public synchronized void append(ByteBuffer wrap) {
   buf.append(wrap);
 }
Ejemplo n.º 17
0
 @Override
 public synchronized void put(long position, byte[] bytes, int offset, int length) {
   buf.put(position, bytes, offset, length);
 }
Ejemplo n.º 18
0
 @Override
 public synchronized void put(long position, byte value) {
   buf.put(position, value);
 }
Ejemplo n.º 19
0
 @Override
 public synchronized byte get(long position) {
   return buf.get(position);
 }
Ejemplo n.º 20
0
 @Override
 public synchronized String readLn() {
   return buf.readLn();
 }
Ejemplo n.º 21
0
 @Override
 public synchronized void append(byte value) {
   buf.append(value);
 }
Ejemplo n.º 22
0
 @Override
 public synchronized String readN(long count) {
   return buf.readN(count);
 }
Ejemplo n.º 23
0
 @Override
 public synchronized long size() {
   return buf.size();
 }
Ejemplo n.º 24
0
 @Override
 public synchronized byte[] readNbytes(int count) {
   return buf.readNbytes(count);
 }
Ejemplo n.º 25
0
 @Override
 public synchronized long append(ReadableByteChannel channel) throws IOException {
   return buf.append(channel);
 }
Ejemplo n.º 26
0
 @Override
 public synchronized void scanTo(byte sep, Range range, boolean failOnLimit) {
   buf.scanTo(sep, range, failOnLimit);
 }
Ejemplo n.º 27
0
 @Override
 public synchronized void append(byte[] bytes) {
   buf.append(bytes);
 }
Ejemplo n.º 28
0
 @Override
 public synchronized long scanTo(byte sep1, byte sep2, Range range, boolean failOnLimit) {
   return buf.scanTo(sep1, sep2, range, failOnLimit);
 }
Ejemplo n.º 29
0
 @Override
 public synchronized String data() {
   return buf.data();
 }
Ejemplo n.º 30
0
 @Override
 public synchronized void scanLnLn(Ranges ranges, LongWrap result, byte end1, byte end2) {
   buf.scanLnLn(ranges, result, end1, end2);
 }