Пример #1
0
  private void sendToExecution(final PrioritizedRequest request) {
    try (CDC ignore = request.getCdc().restore()) {
      request.transfer(
          new CompletionHandler<Void, Void>() {
            @Override
            public void completed(Void result, Void attachment) {
              postprocess();
            }

            @Override
            public void failed(Throwable exc, Void attachment) {
              if (exc instanceof InterruptedException || exc instanceof InterruptedIOException) {
                request
                    .getMover()
                    .setTransferStatus(CacheException.DEFAULT_ERROR_CODE, "Transfer was killed");
              } else if (exc instanceof DiskErrorCacheException) {
                FaultEvent faultEvent =
                    new FaultEvent("transfer", FaultAction.DISABLED, exc.getMessage(), exc);
                _faultListeners.forEach(l -> l.faultOccurred(faultEvent));
              }
              postprocess();
            }

            private void postprocess() {
              try (CDC ignore = request.getCdc().restore()) {
                request
                    .getMover()
                    .close(
                        new CompletionHandler<Void, Void>() {
                          @Override
                          public void completed(Void result, Void attachment) {
                            release();
                          }

                          @Override
                          public void failed(Throwable exc, Void attachment) {
                            if (exc instanceof DiskErrorCacheException) {
                              FaultEvent faultEvent =
                                  new FaultEvent(
                                      "post-processing",
                                      FaultAction.DISABLED,
                                      exc.getMessage(),
                                      exc);
                              _faultListeners.forEach(l -> l.faultOccurred(faultEvent));
                            }
                            release();
                          }

                          private void release() {
                            request.done();
                            _jobs.remove(request.getId());
                            _moverByRequests.remove(request.getDoorUniqueId());
                            PrioritizedRequest nextRequest = nextOrRelease();
                            if (nextRequest != null) {
                              sendToExecution(nextRequest);
                            }
                          }
                        });
              }
            }
          });
    }
  }