Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use static errors in default RSocket methods
Closes gh-865

Signed-off-by: Rossen Stoyanchev <rstoyanchev@vmware.com>
  • Loading branch information
rstoyanchev committed Sep 24, 2020
commit c4f54673320eb14a2a24624e11087df89072afce
16 changes: 6 additions & 10 deletions rsocket-core/src/main/java/io/rsocket/RSocket.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2015-2018 the original author or authors.
* Copyright 2015-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,8 +34,7 @@ public interface RSocket extends Availability, Closeable {
* handled, otherwise errors.
*/
default Mono<Void> fireAndForget(Payload payload) {
payload.release();
return Mono.error(new UnsupportedOperationException("Fire-and-Forget not implemented."));
return RSocketAdapter.fireAndForget(payload);
}

/**
Expand All @@ -46,8 +45,7 @@ default Mono<Void> fireAndForget(Payload payload) {
* response.
*/
default Mono<Payload> requestResponse(Payload payload) {
payload.release();
return Mono.error(new UnsupportedOperationException("Request-Response not implemented."));
return RSocketAdapter.requestResponse(payload);
}

/**
Expand All @@ -57,8 +55,7 @@ default Mono<Payload> requestResponse(Payload payload) {
* @return {@code Publisher} containing the stream of {@code Payload}s representing the response.
*/
default Flux<Payload> requestStream(Payload payload) {
payload.release();
return Flux.error(new UnsupportedOperationException("Request-Stream not implemented."));
return RSocketAdapter.requestStream(payload);
}

/**
Expand All @@ -68,7 +65,7 @@ default Flux<Payload> requestStream(Payload payload) {
* @return Stream of response payloads.
*/
default Flux<Payload> requestChannel(Publisher<Payload> payloads) {
return Flux.error(new UnsupportedOperationException("Request-Channel not implemented."));
return RSocketAdapter.requestChannel(payloads);
}

/**
Expand All @@ -79,8 +76,7 @@ default Flux<Payload> requestChannel(Publisher<Payload> payloads) {
* handled, otherwise errors.
*/
default Mono<Void> metadataPush(Payload payload) {
payload.release();
return Mono.error(new UnsupportedOperationException("Metadata-Push not implemented."));
return RSocketAdapter.metadataPush(payload);
}

@Override
Expand Down
67 changes: 67 additions & 0 deletions rsocket-core/src/main/java/io/rsocket/RSocketAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2015-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.rsocket;

import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
* Package private class with default implementations for use in {@link RSocket}. The main purpose
* is to hide static {@link UnsupportedOperationException} declarations.
*/
class RSocketAdapter {

private static final Mono<Void> UNSUPPORTED_FIRE_AND_FORGET =
Mono.error(new UnsupportedOperationException("Fire-and-Forget not implemented."));
Comment thread
rstoyanchev marked this conversation as resolved.
Outdated

private static final Mono<Payload> UNSUPPORTED_REQUEST_RESPONSE =
Mono.error(new UnsupportedOperationException("Request-Response not implemented."));

private static final Flux<Payload> UNSUPPORTED_REQUEST_STREAM =
Flux.error(new UnsupportedOperationException("Request-Stream not implemented."));

private static final Flux<Payload> UNSUPPORTED_REQUEST_CHANNEL =
Flux.error(new UnsupportedOperationException("Request-Channel not implemented."));

private static final Mono<Void> UNSUPPORTED_METADATA_PUSH =
Mono.error(new UnsupportedOperationException("Metadata-Push not implemented."));

static Mono<Void> fireAndForget(Payload payload) {
payload.release();
return RSocketAdapter.UNSUPPORTED_FIRE_AND_FORGET;
}

static Mono<Payload> requestResponse(Payload payload) {
payload.release();
return RSocketAdapter.UNSUPPORTED_REQUEST_RESPONSE;
}

static Flux<Payload> requestStream(Payload payload) {
payload.release();
return RSocketAdapter.UNSUPPORTED_REQUEST_STREAM;
}

static Flux<Payload> requestChannel(Publisher<Payload> payloads) {
return RSocketAdapter.UNSUPPORTED_REQUEST_CHANNEL;
}

static Mono<Void> metadataPush(Payload payload) {
payload.release();
return RSocketAdapter.UNSUPPORTED_METADATA_PUSH;
}
}