Skip to content
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

Use static errors in RSocket default method implementations #933

Closed
wants to merge 7 commits into from
Closed
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ repositories {
mavenCentral()
}
dependencies {
implementation 'io.rsocket:rsocket-core:1.0.1'
implementation 'io.rsocket:rsocket-transport-netty:1.0.1'
implementation 'io.rsocket:rsocket-core:1.0.2'
implementation 'io.rsocket:rsocket-transport-netty:1.0.2'
}
```

Expand All @@ -40,8 +40,8 @@ repositories {
maven { url 'https://oss.jfrog.org/oss-snapshot-local' }
}
dependencies {
implementation 'io.rsocket:rsocket-core:1.0.2-SNAPSHOT'
implementation 'io.rsocket:rsocket-transport-netty:1.0.2-SNAPSHOT'
implementation 'io.rsocket:rsocket-core:1.0.3-SNAPSHOT'
implementation 'io.rsocket:rsocket-transport-netty:1.0.3-SNAPSHOT'
}
```

Expand Down
7 changes: 3 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ subprojects {
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.sherter.google-java-format'

ext['reactor-bom.version'] = 'Dysprosium-BUILD-SNAPSHOT'
ext['reactor-bom.version'] = 'Dysprosium-SR11'
ext['logback.version'] = '1.2.3'
ext['findbugs.version'] = '3.0.2'
ext['netty-bom.version'] = '4.1.50.Final'
ext['netty-boringssl.version'] = '2.0.30.Final'
ext['netty-bom.version'] = '4.1.51.Final'
ext['netty-boringssl.version'] = '2.0.31.Final'
ext['hdrhistogram.version'] = '2.1.10'
ext['mockito.version'] = '3.2.0'
ext['slf4j.version'] = '1.7.25'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
version=1.0.2
perfBaselineVersion=1.0.1
version=1.0.3
perfBaselineVersion=1.0.2
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
78 changes: 78 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,78 @@
/*
* 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.
*
* @since 1.0.3
*/
class RSocketAdapter {

private static final Mono<Void> UNSUPPORTED_FIRE_AND_FORGET =
Mono.error(new UnsupportedInteractionException("Fire-and-Forget"));

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

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

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

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

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;
}

private static class UnsupportedInteractionException extends RuntimeException {

private static final long serialVersionUID = 5084623297446471999L;

UnsupportedInteractionException(String interactionName) {
super(interactionName + " not implemented.", null, false, false);
}
}
}
Loading