Package jp.ameba.mongo.protocol

Examples of jp.ameba.mongo.protocol.RequestFuture


   
    Response response = (Response) e.getMessage();
    if (response != null) {
      Request request = requestMap.remove(response.getHeader().getResponseTo());
      if (request != null) {
        RequestFuture future = request.getFuture();
        if (future != null) {
          future.setResponse(response)
          future.setDone(true);
          synchronized (future) {
            future.notifyAll()
          }
        }
      }
    }
   
View Full Code Here


      MessageEvent e)
        throws Exception {
   
    // リクエストをバッファに変換して送信
    Request request = (Request) e.getMessage();
    RequestFuture future = new RequestFuture(request);
    request.setFuture(future);
   
    // チャネルを通して送信
    try {
      // バッファを確保
      OutputBuffer outputBuffer = new BasicOutputBuffer();
      BSONEncoder encoder = new BSONEncoder();
      encoder.set(outputBuffer);
      // リクエスト内容を出力
      writeRequest(request, encoder, outputBuffer);
     
      // Safeリクエストの場合は、 getLastError クエリを付加
      Request getLastError = null;
      BSONObject query = request.getConsistency().getLastErrorQuery();
      if (query != null) {
        getLastError = new Query(
            request.getDatabaseName(),
            "$cmd",
            0,
            1,
            query,
            null
        );
        getLastError.setFuture(future);
        writeRequest(getLastError, encoder, outputBuffer);
      }
     
      // ChannelBuffer を生成
      ChannelBuffer channelBuffer = ChannelBuffers.buffer(outputBuffer.size());
      outputBuffer.pipe(new ChannelBufferOutputStream(channelBuffer));
     
      // ChannelFuture を取得し RequestFuture に設定
      ChannelFuture channelFuture = e.getFuture();
      future.setChannelFuture(channelFuture);
     
      // 送信リエクスト一覧に future を追加
      OperationCode opCode = request.getHeader().getOpCode();
      // safeモード、もしくは返信が見込める場合は、リクエストIDを設定
      if (opCode.hasReply() || getLastError != null) {
        if (getLastError == null) {
          requestMap.put(future.getRequetId(), request);
          request.setWaitingRequestId(request.getRequestId());
        } else {
          requestMap.put(getLastError.getRequestId(), request);
          request.setWaitingRequestId(getLastError.getRequestId());
        }
      }
      Channels.write(ctx, channelFuture, channelBuffer);
     
    } catch (Exception ex) {
      // 例外が発生してしまった場合は、リクエスト一覧から future を除去
      if (future.getGetLastError() == null) {
        requestMap.remove(future.getRequetId());
      } else {
        requestMap.remove(future.getGetLastError().getRequestId());
      }
      throw ex;
    }
  }
View Full Code Here

   * @param request
   * @return
   */
  private Response sendQueryRequest(Request request) {
    channel.write(request);
    RequestFuture requestFuture = request.getFuture();
    try {
      Response response = requestFuture.get();
      if (!response.isOk()) {
        throw new MongoException("Query failure: " + response.getErrorMessage());
      } else {
        return response;
      }
View Full Code Here

   *
   * @param request
   */
  private void waitLastError(Request request) {
    // ResponseFuture を取得
    RequestFuture requestFuture = request.getFuture();
    if (requestFuture != null) {
      try {
        Response response = requestFuture.get();
        BSONObject object = response.getDocuments().get(0);
        // OK でない場合は、例外を発する
        if (!response.isOk()) {
          String error = (String) object.get("errmsg");
          throw new MongoException(error);
View Full Code Here

TOP

Related Classes of jp.ameba.mongo.protocol.RequestFuture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.