use of org.xnio.conduits.ConduitStreamSourceChannel in project undertow by undertow-io.
the class ConnectionUtils method doDrain.
private static void doDrain(final StreamConnection connection, final Closeable... additional) {
if (!connection.getSourceChannel().isOpen()) {
IoUtils.safeClose(connection);
IoUtils.safeClose(additional);
return;
}
final ByteBuffer b = ByteBuffer.allocate(1);
try {
int res = connection.getSourceChannel().read(b);
b.clear();
if (res == 0) {
final XnioExecutor.Key key = WorkerUtils.executeAfter(connection.getIoThread(), new Runnable() {
@Override
public void run() {
IoUtils.safeClose(connection);
IoUtils.safeClose(additional);
}
}, MAX_DRAIN_TIME, TimeUnit.MILLISECONDS);
connection.getSourceChannel().setReadListener(new ChannelListener<ConduitStreamSourceChannel>() {
@Override
public void handleEvent(ConduitStreamSourceChannel channel) {
try {
int res = channel.read(b);
if (res != 0) {
IoUtils.safeClose(connection);
IoUtils.safeClose(additional);
key.remove();
}
} catch (Exception e) {
if (e instanceof IOException) {
UndertowLogger.REQUEST_IO_LOGGER.ioException((IOException) e);
} else {
UndertowLogger.REQUEST_IO_LOGGER.ioException(new IOException(e));
}
IoUtils.safeClose(connection);
IoUtils.safeClose(additional);
key.remove();
}
}
});
connection.getSourceChannel().resumeReads();
} else {
IoUtils.safeClose(connection);
IoUtils.safeClose(additional);
}
} catch (Exception e) {
if (e instanceof IOException) {
UndertowLogger.REQUEST_IO_LOGGER.ioException((IOException) e);
} else {
UndertowLogger.REQUEST_IO_LOGGER.ioException(new IOException(e));
}
IoUtils.safeClose(connection);
IoUtils.safeClose(additional);
}
}
use of org.xnio.conduits.ConduitStreamSourceChannel in project indy by Commonjava.
the class ProxyAcceptHandler method handleEvent.
@Override
public void handleEvent(AcceptingChannel<StreamConnection> channel) {
final Logger logger = LoggerFactory.getLogger(getClass());
StreamConnection accepted;
try {
accepted = channel.accept();
} catch (IOException e) {
logger.error("Failed to addMetadata httprox connection: " + e.getMessage(), e);
return;
}
if (accepted == null) {
return;
}
logger.debug("accepted {}", accepted.getPeerAddress());
final ConduitStreamSourceChannel source = accepted.getSourceChannel();
final ConduitStreamSinkChannel sink = accepted.getSinkChannel();
final ProxyRepositoryCreator creator = createRepoCreator();
final ProxyResponseWriter writer = new ProxyResponseWriter(config, storeManager, contentController, proxyAuthenticator, cacheProvider, creator);
logger.debug("Setting writer: {}", writer);
sink.getWriteSetter().set(writer);
final ProxyRequestReader reader = new ProxyRequestReader(writer, sink);
logger.debug("Setting reader: {}", reader);
source.getReadSetter().set(reader);
source.resumeReads();
}
use of org.xnio.conduits.ConduitStreamSourceChannel in project undertow by undertow-io.
the class AjpReadListener method exchangeComplete.
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());
}
}
Aggregations