use of reactor.netty.Connection in project spring-framework by spring-projects.
the class ReactorServerHttpRequest method initSslInfo.
@Override
@Nullable
protected SslInfo initSslInfo() {
Channel channel = ((Connection) this.request).channel();
SslHandler sslHandler = channel.pipeline().get(SslHandler.class);
if (sslHandler == null && channel.parent() != null) {
// HTTP/2
sslHandler = channel.parent().pipeline().get(SslHandler.class);
}
if (sslHandler != null) {
SSLSession session = sslHandler.engine().getSession();
return new DefaultSslInfo(session);
}
return null;
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class Http2Pool method drainLoop.
void drainLoop() {
recordInteractionTimestamp();
int maxPending = poolConfig.maxPending();
for (; ; ) {
@SuppressWarnings("unchecked") ConcurrentLinkedQueue<Slot> resources = CONNECTIONS.get(this);
@SuppressWarnings("unchecked") ConcurrentLinkedDeque<Borrower> borrowers = PENDING.get(this);
if (resources == null || borrowers == TERMINATED) {
return;
}
int borrowersCount = borrowers.size();
if (borrowersCount != 0) {
// find a connection that can be used for opening a new stream
Slot slot = findConnection(resources);
if (slot != null) {
Borrower borrower = borrowers.pollFirst();
if (borrower == null) {
resources.offer(slot);
continue;
}
if (isDisposed()) {
borrower.fail(new PoolShutdownException());
return;
}
if (slot.incrementConcurrencyAndGet() > 1) {
borrower.stopPendingCountdown();
if (log.isDebugEnabled()) {
log.debug(format(slot.connection.channel(), "Channel activated"));
}
ACQUIRED.incrementAndGet(this);
// we are ready here, the connection can be used for opening another stream
slot.deactivate();
poolConfig.acquisitionScheduler().schedule(() -> borrower.deliver(new Http2PooledRef(slot)));
} else {
borrowers.offerFirst(borrower);
continue;
}
} else {
int permits = poolConfig.allocationStrategy().getPermits(1);
if (permits <= 0) {
if (maxPending >= 0) {
borrowersCount = borrowers.size();
int toCull = borrowersCount - maxPending;
for (int i = 0; i < toCull; i++) {
Borrower extraneous = borrowers.pollFirst();
if (extraneous != null) {
pendingAcquireLimitReached(extraneous, maxPending);
}
}
}
} else {
Borrower borrower = borrowers.pollFirst();
if (borrower == null) {
continue;
}
if (isDisposed()) {
borrower.fail(new PoolShutdownException());
return;
}
borrower.stopPendingCountdown();
Mono<Connection> allocator = poolConfig.allocator();
Mono<Connection> primary = allocator.doOnEach(sig -> {
if (sig.isOnNext()) {
Connection newInstance = sig.get();
assert newInstance != null;
Slot newSlot = new Slot(this, newInstance);
if (log.isDebugEnabled()) {
log.debug(format(newInstance.channel(), "Channel activated"));
}
ACQUIRED.incrementAndGet(this);
newSlot.incrementConcurrencyAndGet();
newSlot.deactivate();
borrower.deliver(new Http2PooledRef(newSlot));
} else if (sig.isOnError()) {
Throwable error = sig.getThrowable();
assert error != null;
poolConfig.allocationStrategy().returnPermits(1);
borrower.fail(error);
}
}).contextWrite(borrower.currentContext());
primary.subscribe(alreadyPropagated -> {
}, alreadyPropagatedOrLogged -> drain(), this::drain);
}
}
}
if (WIP.decrementAndGet(this) == 0) {
recordInteractionTimestamp();
break;
}
}
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class Application method main.
public static void main(String[] args) {
Connection server = UdpServer.create().bindAddress(// <1>
Application::newDomainSocketAddress).handle((in, out) -> out.sendObject(in.receiveObject().map(o -> {
if (o instanceof DomainDatagramPacket) {
DomainDatagramPacket p = (DomainDatagramPacket) o;
return new DomainDatagramPacket(p.content().retain(), p.sender());
} else {
return Mono.error(new Exception("Unexpected type of the message: " + o));
}
}))).bindNow();
server.onDispose().block();
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class Application method main.
public static void main(String[] args) {
Connection server = UdpServer.create().wiretap(// <1>
true).bindNow(Duration.ofSeconds(30));
server.onDispose().block();
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class Application method main.
public static void main(String[] args) {
Connection connection = UdpClient.create().host("example.com").port(80).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000).connectNow(Duration.ofSeconds(30));
connection.onDispose().block();
}
Aggregations