Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions rsocket-core/src/main/java/io/rsocket/RSocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@

package io.rsocket;

import static io.rsocket.util.ExceptionUtil.noStacktrace;

import io.netty.buffer.Unpooled;
import io.netty.util.collection.IntObjectHashMap;
import io.rsocket.exceptions.ConnectionException;
import io.rsocket.exceptions.Exceptions;
import io.rsocket.internal.LimitableRequestPublisher;
import io.rsocket.util.PayloadImpl;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import reactor.core.Disposable;
import reactor.core.publisher.*;

import javax.annotation.Nullable;
import java.nio.channels.ClosedChannelException;
import java.time.Duration;
import java.util.Collection;
Expand All @@ -36,8 +32,11 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import static io.rsocket.util.ExceptionUtil.noStacktrace;
import javax.annotation.Nullable;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import reactor.core.Disposable;
import reactor.core.publisher.*;

/** Client Side of a RSocket socket. Sends {@link Frame}s to a {@link RSocketServer} */
class RSocketClient implements RSocket {
Expand All @@ -53,7 +52,7 @@ class RSocketClient implements RSocket {
private final IntObjectHashMap<Subscriber<Payload>> receivers;
private final AtomicInteger missedAckCounter;

private final EmitterProcessor<Frame> sendProcessor;
private final FluxProcessor<Frame, Frame> sendProcessor;

private @Nullable Disposable keepAliveSendSub;
private volatile long timeLastTickSentMs;
Expand Down Expand Up @@ -82,7 +81,7 @@ class RSocketClient implements RSocket {

// DO NOT Change the order here. The Send processor must be subscribed to before receiving
// connections
this.sendProcessor = EmitterProcessor.create();
this.sendProcessor = EmitterProcessor.<Frame>create().serialize();

if (!Duration.ZERO.equals(tickPeriod)) {
long ackTimeoutMs = ackTimeout.toMillis();
Expand All @@ -91,7 +90,7 @@ class RSocketClient implements RSocket {
started
.thenMany(Flux.interval(tickPeriod))
.doOnSubscribe(s -> timeLastTickSentMs = System.currentTimeMillis())
.flatMap(i -> sendKeepAlive(ackTimeoutMs, missedAcks))
.concatMap(i -> sendKeepAlive(ackTimeoutMs, missedAcks))
.doOnError(
t -> {
errorConsumer.accept(t);
Expand Down Expand Up @@ -425,7 +424,7 @@ protected void cleanup() {
synchronized (RSocketClient.this) {
subscribers = receivers.values();
publishers = senders.values();

senders.clear();
receivers.clear();
}
Expand Down
11 changes: 8 additions & 3 deletions rsocket-core/src/main/java/io/rsocket/RSocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RSocketServer implements RSocket {
private final IntObjectHashMap<Subscription> sendingSubscriptions;
private final IntObjectHashMap<UnicastProcessor<Payload>> channelProcessors;

private final EmitterProcessor<Frame> sendProcessor;
private final FluxProcessor<Frame, Frame> sendProcessor;
private Disposable receiveDisposable;

RSocketServer(
Expand All @@ -58,7 +58,7 @@ class RSocketServer implements RSocket {

// DO NOT Change the order here. The Send processor must be subscribed to before receiving
// connections
this.sendProcessor = EmitterProcessor.create();
this.sendProcessor = EmitterProcessor.<Frame>create().serialize();

connection
.send(sendProcessor)
Expand All @@ -67,7 +67,12 @@ class RSocketServer implements RSocket {
.subscribe();

this.receiveDisposable =
connection.receive().flatMap(this::handleFrame).doOnError(errorConsumer).then().subscribe();
connection
.receive()
.flatMapSequential(this::handleFrame)
.doOnError(errorConsumer)
.then()
.subscribe();

this.connection
.onClose()
Expand Down