예제 #1
0
 public void forceQueRequest(Request request) {
   synchronized (lock) {
     if (blockingRequest == null) {
       requestQueue.add(request);
       channel.writeAndFlush(request.getRequest());
       if (request.isBlocking()) {
         blockingRequest = new BlockingRequestInProgress(request);
         request
             .getToComplete()
             .addListener(
                 new DbListener<Object>() {
                   @Override
                   public void onCompletion(DbFuture<Object> future) {
                     blockingRequest.continueWithRequests();
                   }
                 });
       }
     } else {
       if (blockingRequest.unblockBy(request)) {
         requestQueue.add(request);
         channel.writeAndFlush(request.getRequest());
       } else {
         blockingRequest.add(request);
       }
     }
   }
 }
예제 #2
0
 private void forceCloseOnPendingRequests() {
   for (Request request : requestQueue) {
     if (request.getRequest().tryCancel()) {
       request
           .getToComplete()
           .trySetException(new DbSessionClosedException("Connection is closed"));
     }
   }
   if (null != blockingRequest) {
     for (Request waitingRequest : blockingRequest.waitingRequests) {
       if (waitingRequest.getRequest().tryCancel()) {
         waitingRequest
             .getToComplete()
             .trySetException(new DbSessionClosedException("Connection is closed"));
       }
     }
   }
 }
예제 #3
0
 public Request dequeRequest() {
   synchronized (lock) {
     final Request request = requestQueue.poll();
     if (logger.isDebugEnabled()) {
       logger.debug("Dequeued request: {}", request);
     }
     if (request.getRequest().wasCancelled()) {
       if (logger.isDebugEnabled()) {
         logger.debug("Request has been cancelled: {}", request);
       }
       return dequeRequest();
     }
     return request;
   }
 }