Skip to content

Improves Loadbalance implementations and test coverage #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 27, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ abstract class MonoDeferredResolution<RESULT, R> extends Mono<RESULT>
}

@Override
public void subscribe(CoreSubscriber<? super RESULT> actual) {
public final void subscribe(CoreSubscriber<? super RESULT> actual) {
if (this.requested == STATE_UNSUBSCRIBED
&& REQUESTED.compareAndSet(this, STATE_UNSUBSCRIBED, STATE_SUBSCRIBER_SET)) {

Expand Down Expand Up @@ -145,7 +145,7 @@ public final void onNext(RESULT payload) {
}

@Override
public void onError(Throwable t) {
public final void onError(Throwable t) {
if (this.done) {
Operators.onErrorDropped(t, this.actual.currentContext());
return;
Expand All @@ -156,7 +156,7 @@ public void onError(Throwable t) {
}

@Override
public void onComplete() {
public final void onComplete() {
if (this.done) {
return;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public final void request(long n) {
}
}

public void cancel() {
public final void cancel() {
long state = REQUESTED.getAndSet(this, STATE_TERMINATED);
if (state == STATE_TERMINATED) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,16 @@ protected void doSubscribe() {

@Override
protected void doOnValueResolved(RSocket value) {
value.onClose().subscribe(null, t -> this.invalidate(), this::invalidate);
value.onClose().subscribe(null, t -> this.doCleanup(), this::doCleanup);
}

@Override
protected void doOnValueExpired(RSocket value) {
value.dispose();
this.dispose();
}
void doCleanup() {
if (isDisposed()) {
return;
}

@Override
public void dispose() {
super.dispose();
}
this.dispose();

@Override
protected void doOnDispose() {
final RSocketPool parent = this.parent;
for (; ; ) {
final PooledRSocket[] sockets = parent.activeSockets;
Expand All @@ -141,20 +135,35 @@ protected void doOnDispose() {
break;
}

final int lastIndex = activeSocketsCount - 1;
final PooledRSocket[] newSockets = new PooledRSocket[lastIndex];
if (index != 0) {
System.arraycopy(sockets, 0, newSockets, 0, index);
}
final PooledRSocket[] newSockets;
if (activeSocketsCount == 1) {
newSockets = RSocketPool.EMPTY;
} else {
final int lastIndex = activeSocketsCount - 1;

newSockets = new PooledRSocket[lastIndex];
if (index != 0) {
System.arraycopy(sockets, 0, newSockets, 0, index);
}

if (index != lastIndex) {
System.arraycopy(sockets, index + 1, newSockets, index, lastIndex - index);
if (index != lastIndex) {
System.arraycopy(sockets, index + 1, newSockets, index, lastIndex - index);
}
}

if (RSocketPool.ACTIVE_SOCKETS.compareAndSet(parent, sockets, newSockets)) {
break;
}
}
}

@Override
protected void doOnValueExpired(RSocket value) {
value.dispose();
}

@Override
protected void doOnDispose() {
Operators.terminate(S, this);
}

Expand Down Expand Up @@ -231,7 +240,7 @@ public void accept(RSocket rSocket, Throwable t) {

source.subscribe((CoreSubscriber) this);
} else {
parent.add(this);
parent.observe(this);
}
}
}
Expand Down Expand Up @@ -273,7 +282,7 @@ public void accept(RSocket rSocket, Throwable t) {

source.subscribe(this);
} else {
parent.add(this);
parent.observe(this);
}
}
}
Expand Down
Loading