// Ensures that reply field is non-null
 //
 private void build() throws IOException {
   Request.Action action = request.action();
   if ((action != Request.Action.GET) && (action != Request.Action.HEAD)) {
     reply = new Reply(Reply.Code.METHOD_NOT_ALLOWED, new StringContent(request.toString()));
   }
   reply = new Reply(Reply.Code.OK, new FileContent(request.uri()), action);
 }
示例#2
0
 ExchangeImpl(String m, URI u, Request req, int len, HttpConnection connection)
     throws IOException {
   this.req = req;
   this.reqHdrs = req.headers();
   this.rspHdrs = new Headers();
   this.method = m;
   this.uri = u;
   this.connection = connection;
   this.reqContentLen = len;
   /* ros only used for headers, body written directly to stream */
   this.ros = req.outputStream();
   this.ris = req.inputStream();
   server = getServerImpl();
   server.startExchange();
 }
 // When parse is successfull, saves request and returns true
 //
 private boolean parse() throws IOException {
   try {
     request = Request.parse(rbb);
     return true;
   } catch (MalformedRequestException x) {
     reply = new Reply(Reply.Code.BAD_REQUEST, new StringContent(x));
   }
   return false;
 }
  public static void main(String args[]) throws MPIException {
    int myself, tasks;
    IntBuffer in = MPI.newIntBuffer(MAXLEN);
    Request request;

    MPI.Init(args);
    myself = MPI.COMM_WORLD.getRank();
    tasks = MPI.COMM_WORLD.getSize();

    for (int j = 1; j <= MAXLEN; j *= 10) {
      for (int i = 0; i < j; i++) {
        in.put(i, i);
      }

      request = MPI.COMM_WORLD.iAllReduce(in, j, MPI.INT, MPI.SUM);
      request.waitFor();
      request.free();

      for (int k = 0; k < j; k++) {
        if (in.get(k) != k * tasks) {
          OmpitestError.ompitestError(
              OmpitestError.getFileName(),
              OmpitestError.getLineNumber(),
              " bad answer ("
                  + in.get(k)
                  + ") at index "
                  + k
                  + " of "
                  + j
                  + " (should be "
                  + (k * tasks)
                  + ")\n");
          break;
        }
      }
    }

    MPI.COMM_WORLD.barrier();
    MPI.Finalize();
  }
  // Returns true when request is complete
  // May expand rbb if more room required
  //
  private boolean receive(SelectionKey sk) throws IOException {
    ByteBuffer tmp = null;

    if (requestReceived) {
      return true;
    }

    if (!cio.doHandshake(sk)) {
      return false;
    }

    if ((cio.read() < 0) || Request.isComplete(cio.getReadBuf())) {
      rbb = cio.getReadBuf();
      return (requestReceived = true);
    }
    return false;
  }
示例#6
0
 public void sendResponseHeaders(int rCode, long contentLen) throws IOException {
   if (sentHeaders) {
     throw new IOException("headers already sent");
   }
   this.rcode = rCode;
   String statusLine = "HTTP/1.1 " + rCode + Code.msg(rCode) + "\r\n";
   OutputStream tmpout = new BufferedOutputStream(ros);
   PlaceholderOutputStream o = getPlaceholderResponseBody();
   tmpout.write(bytes(statusLine, 0), 0, statusLine.length());
   boolean noContentToSend = false; // assume there is content
   rspHdrs.set("Date", df.format(new Date()));
   if (contentLen == 0) {
     if (http10) {
       o.setWrappedStream(new UndefLengthOutputStream(this, ros));
       close = true;
     } else {
       rspHdrs.set("Transfer-encoding", "chunked");
       o.setWrappedStream(new ChunkedOutputStream(this, ros));
     }
   } else {
     if (contentLen == -1) {
       noContentToSend = true;
       contentLen = 0;
     }
     /* content len might already be set, eg to implement HEAD resp */
     if (rspHdrs.getFirst("Content-length") == null) {
       rspHdrs.set("Content-length", Long.toString(contentLen));
     }
     o.setWrappedStream(new FixedLengthOutputStream(this, ros, contentLen));
   }
   write(rspHdrs, tmpout);
   this.rspContentLen = contentLen;
   tmpout.flush();
   tmpout = null;
   sentHeaders = true;
   if (noContentToSend) {
     WriteFinishedEvent e = new WriteFinishedEvent(this);
     server.addEvent(e);
     closed = true;
   }
   server.logReply(rCode, req.requestLine(), null);
 }
示例#7
0
 public String getProtocol() {
   String reqline = req.requestLine();
   int index = reqline.lastIndexOf(' ');
   return reqline.substring(index + 1);
 }
示例#8
0
  public static void main(String[] args) throws MPIException {
    Comm comm;
    IntBuffer sBuf, rBuf;
    int rank, size, extent;
    int[] sendCounts, recvCounts, rDispls, sDispls;
    Datatype[] sDTypes, rDTypes;
    Request req;

    MPI.Init(args);

    comm = MPI.COMM_WORLD;

    /* Create the buffer */
    size = comm.getSize();
    rank = comm.getRank();

    sBuf = MPI.newIntBuffer(size * size);
    rBuf = MPI.newIntBuffer(size * size);

    /* Load up the buffers */
    for (int i = 0; i < (size * size); i++) {
      sBuf.put(i, (i + 100 * rank));
      rBuf.put(i, -i);
    }

    /* Create and load the arguments to alltoallw */
    sendCounts = new int[size];
    recvCounts = new int[size];
    rDispls = new int[size];
    sDispls = new int[size];
    sDTypes = new Datatype[size];
    rDTypes = new Datatype[size];

    extent =
        4; // MPI.INT.getExtent(); //getExtent returns 1, but a 4 is needed for these calculations

    for (int i = 0; i < size; i++) {
      sendCounts[i] = i;
      recvCounts[i] = rank;
      rDispls[i] = (i * rank * extent);
      sDispls[i] = (((i * (i + 1)) / 2) * extent);
      sDTypes[i] = MPI.INT;
      rDTypes[i] = MPI.INT;
    }

    req = comm.iAllToAllw(sBuf, sendCounts, sDispls, sDTypes, rBuf, recvCounts, rDispls, rDTypes);
    req.waitFor();
    req.free();

    /* Check rbuf */
    for (int i = 0; i < size; i++) {
      int p = rDispls[i] / extent;
      for (int j = 0; j < rank; j++) {
        if (rBuf.get(p + j) != (i * 100 + (rank * (rank + 1)) / 2 + j)) {
          System.out.println(i + " " + j + " " + size + " " + rank + " " + extent);
          OmpitestError.ompitestError(
              OmpitestError.getFileName(),
              OmpitestError.getLineNumber(),
              "bad answer "
                  + rBuf.get(p + j)
                  + " (should be "
                  + (i * 100 + (rank * (rank + 1)) / 2 + j)
                  + ")\n");
        }
      }
    }

    MPI.COMM_WORLD.barrier();
    MPI.Finalize();
    if (rank == 0) {
      System.out.println("Test completed.");
    }
  }