org.xnio.IoUtils.safeClose()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(204)

本文整理了Java中org.xnio.IoUtils.safeClose()方法的一些代码示例,展示了IoUtils.safeClose()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtils.safeClose()方法的具体详情如下:
包路径:org.xnio.IoUtils
类名称:IoUtils
方法名:safeClose

IoUtils.safeClose介绍

[英]Close a resource, logging an error if an error occurs.
[中]关闭资源,在发生错误时记录错误。

代码示例

代码示例来源:origin: wildfly/wildfly

@Override
  protected void finalize() throws Throwable {
    IoUtils.safeClose(selector);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
  public void run() {
    IoUtils.safeClose(i);
  }
});

代码示例来源:origin: wildfly/wildfly

@Override
  public void handleException(Channel channel, IOException exception) {
    IoUtils.safeClose(channel);
    IoUtils.safeClose(toClose);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
  public void run() {
    IoUtils.safeClose(channel);
  }
});

代码示例来源:origin: wildfly/wildfly

@Override
  public void handleEvent(StreamConnection channel) {
    IoUtils.safeClose(channel); // Close the channel right away
  }
}, options);

代码示例来源:origin: spring-projects/spring-framework

public void onSuccess() {
  if (this.outputStream.size() > 0) {
    handleFrame();
  }
  if (logger.isTraceEnabled()) {
    logger.trace("XHR receive request completed.");
  }
  IoUtils.safeClose(this.connection);
  executeReceiveRequest(this.request, this.url, this.headers, this.session, this.connectFuture);
}

代码示例来源:origin: wildfly/wildfly

@Override
public void close() throws IOException {
  this.stopped = true;
  watchThread.interrupt();
  IoUtils.safeClose(watchService);
}

代码示例来源:origin: wildfly/wildfly

@Override
  public void handleException(final StreamSourceChannel channel, final IOException e) {
    //make sure the listeners have been invoked
    //unless the connection has been killed this is a no-op
    invokeExchangeCompleteListeners();
    UndertowLogger.REQUEST_LOGGER.debug("Exception draining request stream", e);
    IoUtils.safeClose(connection);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public void run() {
  try {
    mh.handle(dis, correlationId);
  } catch (IOException e) {
    log.error(e);
  } finally {
    IoUtils.safeClose(dis);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
  public void handleException(StreamSinkChannel channel, IOException exception) {
    IoUtils.safeClose(exchange.getConnection());
  }
}));

代码示例来源:origin: wildfly/wildfly

protected void closeAction() throws IOException {
  try {
    cancelKey(sourceConduit);
    cancelKey(sinkConduit);
    closeChannel(sourceChannel);
    closeChannel(sinkChannel);
  } finally {
    safeClose(sourceChannel);
    safeClose(sinkChannel);
  }
}

代码示例来源:origin: wildfly/wildfly

private void handleError(IOException exception) {
  UndertowLogger.REQUEST_IO_LOGGER.ioException(exception);
  currentRequest.setFailed(exception);
  currentRequest = null;
  pendingResponse = null;
  safeClose(connection);
}

代码示例来源:origin: wildfly/wildfly

@Override
  public void handleEvent(StreamSinkChannel channel) {
    if(timerKey != null) {
      timerKey.remove();
    }
    for (ChannelListener<ServerSentEventConnection> listener : closeTasks) {
      ChannelListeners.invokeChannelListener(ServerSentEventConnection.this, listener);
    }
    IoUtils.safeClose(ServerSentEventConnection.this);
  }
});

代码示例来源:origin: wildfly/wildfly

private void handleFailedRead(ConduitStreamSourceChannel channel, int res) {
  if (res == 0) {
    channel.setReadListener(this);
    channel.resumeReads();
  } else if (res == -1) {
    IoUtils.safeClose(connection);
  }
}

代码示例来源:origin: spring-projects/spring-framework

public void onFailure(Throwable failure) {
    IoUtils.safeClose(this.connection);
    if (this.connectFuture.setException(failure)) {
      return;
    }
    if (this.session.isDisconnected()) {
      this.session.afterTransportClosed(null);
    }
    else {
      this.session.handleTransportError(failure);
      this.session.afterTransportClosed(new CloseStatus(1006, failure.getMessage()));
    }
  }
}

代码示例来源:origin: wildfly/wildfly

public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException {
  try {
    if (state != 0) {
      return IoUtils.transfer(source, count, throughBuffer, new ConduitWritableByteChannel(this));
    } else {
      return next.transferFrom(source, count, throughBuffer);
    }
  } catch (IOException| RuntimeException | Error e) {
    IoUtils.safeClose(connection);
    throw e;
  }
}

代码示例来源:origin: spring-projects/spring-framework

IoUtils.safeClose(connection);

代码示例来源:origin: wildfly/wildfly

protected void write(MessageWriter writer) throws IOException {
  CancellableDataOutputStream output = new CancellableDataOutputStream(channel.writeMessage());
  try {
    writer.write(output);
  } catch (IOException e) {
    output.cancel();
    throw e;
  } finally {
    IoUtils.safeClose(output);
  }
}

代码示例来源:origin: wildfly/wildfly

static void handleFailure(HttpServerExchange exchange, ProxyClientHandler proxyClientHandler, Predicate idempotentRequestPredicate, IOException e) {
  UndertowLogger.PROXY_REQUEST_LOGGER.proxyRequestFailed(exchange.getRequestURI(), e);
  if(exchange.isResponseStarted()) {
    IoUtils.safeClose(exchange.getConnection());
  } else if(idempotentRequestPredicate.resolve(exchange) && proxyClientHandler != null) {
    proxyClientHandler.failed(exchange); //this will attempt a retry if configured to do so
  } else {
    exchange.setStatusCode(StatusCodes.SERVICE_UNAVAILABLE);
    exchange.endExchange();
  }
}

代码示例来源:origin: wildfly/wildfly

public void exchangeComplete(final HttpServerExchange exchange) {
  if (!exchange.isUpgrade() && exchange.isPersistent()) {
    startRequest();
    ConduitStreamSourceChannel channel = ((AjpServerConnection) exchange.getConnection()).getChannel().getSourceChannel();
    channel.getReadSetter().set(this);
    channel.wakeupReads();
  } else if(!exchange.isPersistent()) {
    safeClose(exchange.getConnection());
  }
}

相关文章