本文整理了Java中org.xnio.IoUtils
类的一些代码示例,展示了IoUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtils
类的具体详情如下:
包路径:org.xnio.IoUtils
类名称:IoUtils
[英]General I/O utility methods.
[中]通用I/O实用程序方法。
代码示例来源:origin: wildfly/wildfly
void cancel(final HttpServerExchange exchange) {
final ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
if (connectionAttachment != null) {
ClientConnection clientConnection = connectionAttachment.getConnection();
UndertowLogger.PROXY_REQUEST_LOGGER.timingOutRequest(clientConnection.getPeerAddress() + "" + exchange.getRequestURI());
IoUtils.safeClose(clientConnection);
} else {
UndertowLogger.PROXY_REQUEST_LOGGER.timingOutRequest(exchange.getRequestURI());
}
if (exchange.isResponseStarted()) {
IoUtils.safeClose(exchange.getConnection());
} else {
exchange.setStatusCode(StatusCodes.SERVICE_UNAVAILABLE);
exchange.endExchange();
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException {
try {
return IoUtils.transfer(new ConduitReadableByteChannel(this), count, throughBuffer, target);
} catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection());
throw e;
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Get the executor used to run asynchronous notifiers. By default, this implementation simply returns the direct
* executor.
*
* @return the executor to use
*/
protected Executor getNotifierExecutor() {
return IoUtils.directExecutor();
}
代码示例来源:origin: wildfly/wildfly
@Override
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException {
try {
return IoUtils.transfer(new ConduitReadableByteChannel(this), count, throughBuffer, target);
} catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(closeable);
throw e;
}
}
代码示例来源:origin: wildfly/wildfly
public void handleEvent(final StreamSourceChannel channel) {
if(connection.getOriginalSinkConduit().isWriteShutdown() || connection.getOriginalSourceConduit().isReadShutdown()) {
safeClose(connection);
channel.suspendReads();
return;
res = channel.read(buffer);
} catch (IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
safeClose(connection);
return;
try {
channel.shutdownReads();
final StreamSinkChannel responseChannel = connection.getChannel().getSinkChannel();
responseChannel.shutdownWrites();
safeClose(connection);
} catch (IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
safeClose(connection);
return;
UndertowLogger.REQUEST_LOGGER.requestHeaderWasTooLarge(connection.getPeerAddress(), maxRequestSize);
safeClose(connection);
return;
safeClose(connection);
safeClose(connection);
代码示例来源: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
invokeExchangeCompleteListeners();
return;
if (isResponseChannelAvailable()) {
if(!getRequestMethod().equals(Methods.CONNECT) && !(getRequestMethod().equals(Methods.HEAD) && getResponseHeaders().contains(Headers.CONTENT_LENGTH)) && Connectors.isEntityBodyAllowed(this)) {
getResponseHeaders().put(Headers.CONTENT_LENGTH, "0");
responseChannel.getWriteSetter().set(ChannelListeners.flushingChannelListener(
new ChannelListener<StreamSinkChannel>() {
@Override
} else {
if (anyAreClear(state, FLAG_RESPONSE_TERMINATED)) {
UndertowLogger.ROOT_LOGGER.responseWasNotTerminated(connection, this);
IoUtils.safeClose(connection);
UndertowLogger.REQUEST_IO_LOGGER.ioException((IOException) t);
} else {
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
invokeExchangeCompleteListeners();
IoUtils.safeClose(connection);
代码示例来源:origin: wildfly/wildfly
@Override
public void handleException(Channel channel, IOException exception) {
IoUtils.safeClose(channel);
IoUtils.safeClose(clientConnection);
if (exchange.isResponseStarted()) {
UndertowLogger.REQUEST_IO_LOGGER.debug("Exception reading from target server", exception);
if (!exchange.isResponseStarted()) {
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
exchange.endExchange();
} else {
IoUtils.safeClose(exchange.getConnection());
}
} else {
UndertowLogger.REQUEST_IO_LOGGER.ioException(exception);
exchange.setStatusCode(StatusCodes.INTERNAL_SERVER_ERROR);
exchange.endExchange();
}
}
}
代码示例来源:origin: wildfly/wildfly
fileChannel = FileChannel.open(file, StandardOpenOption.READ);
} catch (FileNotFoundException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
exchange.endExchange();
return;
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
exchange.endExchange();
return;
throw new RuntimeException(e);
exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, size);
final StreamSinkChannel response = exchange.getResponseChannel();
exchange.addExchangeCompleteListener(new ExchangeCompletionListener() {
log.tracef("Failed to serve %s: %s", fileChannel, ignored);
exchange.endExchange();
IoUtils.safeClose(response);
} finally {
IoUtils.safeClose(fileChannel);
代码示例来源:origin: wildfly/wildfly
if (exchange.isInIoThread()) {
channel.getSourceChannel().setReadListener(HttpReadListener.this);
channel.getSourceChannel().resumeReads();
requestStateUpdater.set(this, 0);
} else {
while (true) {
if (connection.getOriginalSourceConduit().isReadShutdown() || connection.getOriginalSinkConduit().isWriteShutdown()) {
channel.getSourceChannel().suspendReads();
channel.getSinkChannel().suspendWrites();
IoUtils.safeClose(connection);
return;
} else {
if (exchange.isInIoThread()) {
requestStateUpdater.set(this, 0); //no need to CAS, as we don't actually resume
newRequest();
channel.getSinkChannel().suspendWrites();
IoUtils.safeClose(connection);
return;
} else if (requestStateUpdater.compareAndSet(this, 1, 2)) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
IoUtils.safeClose(connection);
} catch (Throwable t) {
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
IoUtils.safeClose(connection);
代码示例来源:origin: wildfly/wildfly
public void handleEventWithNoRunningRequest(final ConduitStreamSourceChannel channel) {
PooledByteBuffer existing = connection.getExtraBytes();
if ((existing == null && connection.getOriginalSourceConduit().isReadShutdown()) || connection.getOriginalSinkConduit().isWriteShutdown()) {
IoUtils.safeClose(connection);
channel.suspendReads();
return;
buffer.clear();
try {
res = channel.read(buffer);
} catch (IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.debug("Error reading request", e);
IoUtils.safeClose(connection);
return;
httpServerExchange = new HttpServerExchange(connection, maxEntitySize);
httpServerExchange.setRequestScheme(connection.getSslSession() != null ? "https" : "http");
this.httpServerExchange = null;
requestStateUpdater.set(this, 1);
if(httpServerExchange.getProtocol() == Protocols.HTTP_2_0) {
free = handleHttp2PriorKnowledge(pooled, httpServerExchange);
return;
channel.suspendReads();
代码示例来源:origin: wildfly/wildfly
@Override
public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(exception);
try {
exchange.endExchange();
} finally {
IoUtils.safeClose(exchange.getConnection());
}
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void handleEvent(final StreamSourceChannel channel) {
try {
doParse(channel);
if (state == 4) {
exchange.dispatch(SameThreadExecutor.INSTANCE, handler);
}
} catch (IOException e) {
IoUtils.safeClose(channel);
UndertowLogger.REQUEST_IO_LOGGER.ioExceptionReadingFromChannel(e);
exchange.endExchange();
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void close() {
try {
exchange.endExchange();
} finally {
IoUtils.safeClose(exchange.getConnection());
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void handleEvent(final StreamConnection channel) {
if (UndertowLogger.REQUEST_LOGGER.isTraceEnabled()) {
UndertowLogger.REQUEST_LOGGER.tracef("Opened connection with %s", channel.getPeerAddress());
Integer readTimeout = channel.getOption(Options.READ_TIMEOUT);
Integer idle = undertowOptions.get(UndertowOptions.IDLE_TIMEOUT);
if(idle != null) {
IdleTimeoutConduit conduit = new IdleTimeoutConduit(channel);
channel.getSourceChannel().setConduit(conduit);
channel.getSinkChannel().setConduit(conduit);
channel.getSourceChannel().setConduit(new ReadTimeoutStreamSourceConduit(channel.getSourceChannel().getConduit(), channel, this));
Integer writeTimeout = channel.getOption(Options.WRITE_TIMEOUT);
if (writeTimeout != null && writeTimeout > 0) {
channel.getSinkChannel().setConduit(new WriteTimeoutStreamSinkConduit(channel.getSinkChannel().getConduit(), channel, this));
IoUtils.safeClose(channel);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
代码示例来源:origin: wildfly/wildfly
public IoFuture<SslConnection> openSslConnection(final XnioIoThread ioThread, final InetSocketAddress bindAddress, final InetSocketAddress destination, final ChannelListener<? super SslConnection> openListener, final ChannelListener<? super BoundChannel> bindListener, final OptionMap optionMap) {
final FutureResult<SslConnection> futureResult = new FutureResult<>(ioThread);
final IoFuture<StreamConnection> connection = ioThread.openStreamConnection(bindAddress, destination, new ChannelListener<StreamConnection>() {
public void handleEvent(final StreamConnection connection) {
} catch (IOException e) {
if (futureResult.setException(e)) {
IoUtils.safeClose(connection);
if (! futureResult.setResult(wrappedConnection)) {
IoUtils.safeClose(connection);
} else {
ChannelListeners.invokeChannelListener(wrappedConnection, openListener);
代码示例来源:origin: wildfly/wildfly
if (allAreSet(state, FLAG_REQUEST_TERMINATED | FLAG_RESPONSE_TERMINATED)) {
if(blockingHttpExchange != null) {
IoUtils.safeClose(blockingHttpExchange);
UndertowLogger.REQUEST_LOGGER.debug("Exception running default response listener", e);
if (anyAreClear(state, FLAG_REQUEST_TERMINATED)) {
connection.terminateRequestChannel(this);
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
IoUtils.safeClose(connection);
} catch (Throwable t) {
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
IoUtils.safeClose(connection);
if (anyAreClear(state, FLAG_REQUEST_TERMINATED)) {
getRequestChannel();
UndertowLogger.REQUEST_IO_LOGGER.handleUnexpectedFailure(t);
invokeExchangeCompleteListeners();
IoUtils.safeClose(connection);
return this;
代码示例来源:origin: wildfly/wildfly
if (contentLength != null) {
if (!"0".equals(contentLength)) {
future.setException(new IOException("Upgrade responses must have a content length of zero."));
return;
future.setException(new IOException("Upgrade responses cannot have a transfer coding"));
return;
safeClose(connection);
future.setException(e);
return;
future.setResult(connection);
ChannelListeners.invokeChannelListener(connection, openListener);
代码示例来源:origin: wildfly/wildfly
@Override
public void handleException(StreamSinkChannel channel, IOException exception) {
IoUtils.safeClose(exchange.getConnection());
}
}));
代码示例来源:origin: wildfly/wildfly
@Override
public void handleException(T t, IOException e) {
UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
IoUtils.safeClose(t);
IoUtils.safeClose(closable);
}
}
内容来源于网络,如有侵权,请联系作者删除!