-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
rsocket-messages/src/main/java/com/jauntsdn/rsocket/Errors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* Copyright 2020 - present Maksym Ostroverkhov. | ||
* | ||
* 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 com.jauntsdn.rsocket; | ||
|
||
import com.jauntsdn.rsocket.exceptions.ChannelException; | ||
import javax.annotation.Nullable; | ||
|
||
public final class Errors { | ||
private Errors() {} | ||
|
||
public static final class Configurer { | ||
Connection.SendErrors connectionSendErrors; | ||
Connection.ReceiveErrors connectionReceiveErrors; | ||
Stream.SendErrors streamSendErrors; | ||
Stream.ReceiveErrors streamReceiveErrors; | ||
|
||
Configurer() {} | ||
|
||
public Configurer connectionSendErrors(Connection.SendErrors connectionSendErrors) { | ||
this.connectionSendErrors = connectionSendErrors; | ||
return this; | ||
} | ||
|
||
public Configurer connectionReceiveErrors(Connection.ReceiveErrors connectionReceiveErrors) { | ||
this.connectionReceiveErrors = connectionReceiveErrors; | ||
return this; | ||
} | ||
|
||
public Configurer streamSendErrors(Stream.SendErrors streamSendErrors) { | ||
this.streamSendErrors = streamSendErrors; | ||
return this; | ||
} | ||
|
||
public Configurer streamReceiveErrors(Stream.ReceiveErrors streamReceiveErrors) { | ||
this.streamReceiveErrors = streamReceiveErrors; | ||
return this; | ||
} | ||
} | ||
|
||
public static final class Connection { | ||
|
||
private Connection() {} | ||
|
||
public interface SendErrors { | ||
|
||
String translate(int errorCode, @Nullable String errorMessage); | ||
} | ||
|
||
public interface ReceiveErrors { | ||
|
||
Exception translate(int errorCode, @Nullable String errorMessage); | ||
} | ||
} | ||
|
||
public static final class Stream { | ||
|
||
private Stream() {} | ||
|
||
public enum StreamType { | ||
REQUEST, | ||
RESPONSE | ||
} | ||
|
||
/** Converts stream {@link Throwable} error to RSocket error code and message */ | ||
public interface SendErrors { | ||
|
||
/** | ||
* @param streamType type of stream: request or response | ||
* @param t {@link Throwable} that should be converted to {@link Error} | ||
* @return one of stream errors (code and message): reject, cancel, invalid, application. Null | ||
* if default conversion should be applied. | ||
*/ | ||
@Nullable | ||
Error translate(StreamType streamType, Throwable t); | ||
|
||
/** Represents one of stream errors: reject, cancel, invalid, application */ | ||
final class Error { | ||
private final int errorCode; | ||
private final String message; | ||
|
||
private Error(int errorCode, String message) { | ||
this.errorCode = errorCode; | ||
this.message = message; | ||
} | ||
|
||
public static Error reject(String errorMessage) { | ||
return new Error(ChannelException.ErrorCodes.REJECTED, errorMessage); | ||
} | ||
|
||
public static Error cancel(String errorMessage) { | ||
return new Error(ChannelException.ErrorCodes.CANCELED, errorMessage); | ||
} | ||
|
||
public static Error invalid(String errorMessage) { | ||
return new Error(ChannelException.ErrorCodes.INVALID, errorMessage); | ||
} | ||
|
||
public static Error application(String errorMessage) { | ||
return new Error(ChannelException.ErrorCodes.APPLICATION_ERROR, errorMessage); | ||
} | ||
|
||
public String message() { | ||
return message; | ||
} | ||
|
||
public int code() { | ||
return errorCode; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Converts RSocket error code {@link ErrorType} and message to stream {@link Throwable} error | ||
*/ | ||
public interface ReceiveErrors { | ||
|
||
/** | ||
* @param streamType type of stream: request or response | ||
* @param errorType one of stream errors: reject, cancel, invalid, application | ||
* @param errorMessage stream error message | ||
* @return stream Throwable converted from error code and error message. Null if default | ||
* conversion should be applied | ||
*/ | ||
@Nullable | ||
Throwable translate(StreamType streamType, ErrorType errorType, String errorMessage); | ||
|
||
enum ErrorType { | ||
REJECTED, | ||
CANCELED, | ||
INVALID, | ||
APPLICATION; | ||
|
||
static ErrorType fromCode(int code) { | ||
switch (code) { | ||
case ChannelException.ErrorCodes.REJECTED: | ||
return REJECTED; | ||
case ChannelException.ErrorCodes.CANCELED: | ||
return CANCELED; | ||
case ChannelException.ErrorCodes.INVALID: | ||
return INVALID; | ||
default: | ||
return APPLICATION; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2021 - present Maksym Ostroverkhov. | ||
*/ | ||
|
||
plugins { | ||
id "java-library" | ||
id "signing" | ||
id "maven-publish" | ||
} | ||
|
||
dependencies { | ||
api project(":rsocket-messages") | ||
api "io.smallrye.reactive:mutiny" | ||
|
||
compileOnly "com.google.code.findbugs:jsr305" | ||
} | ||
|
||
description = "RSocket-smallrye-mutiny api library" |
3 changes: 3 additions & 0 deletions
3
rsocket-mutiny/gradle/dependency-locks/annotationProcessor.lockfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This is a Gradle generated file for dependency locking. | ||
# Manual edits can break the build and are not advised. | ||
# This file is expected to be part of source control. |
9 changes: 9 additions & 0 deletions
9
rsocket-mutiny/gradle/dependency-locks/compileClasspath.lockfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# This is a Gradle generated file for dependency locking. | ||
# Manual edits can break the build and are not advised. | ||
# This file is expected to be part of source control. | ||
com.google.code.findbugs:jsr305:3.0.2 | ||
io.netty:netty-buffer:4.1.72.Final | ||
io.netty:netty-common:4.1.72.Final | ||
io.smallrye.common:smallrye-common-annotation:1.8.0 | ||
io.smallrye.reactive:mutiny:1.2.0 | ||
org.reactivestreams:reactive-streams:1.0.3 |
10 changes: 10 additions & 0 deletions
10
rsocket-mutiny/gradle/dependency-locks/googleJavaFormat1.6.lockfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This is a Gradle generated file for dependency locking. | ||
# Manual edits can break the build and are not advised. | ||
# This file is expected to be part of source control. | ||
com.google.code.findbugs:jsr305:3.0.2 | ||
com.google.errorprone:error_prone_annotations:2.0.18 | ||
com.google.errorprone:javac-shaded:9+181-r4173-1 | ||
com.google.googlejavaformat:google-java-format:1.6 | ||
com.google.guava:guava:22.0 | ||
com.google.j2objc:j2objc-annotations:1.1 | ||
org.codehaus.mojo:animal-sniffer-annotations:1.14 |
8 changes: 8 additions & 0 deletions
8
rsocket-mutiny/gradle/dependency-locks/runtimeClasspath.lockfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# This is a Gradle generated file for dependency locking. | ||
# Manual edits can break the build and are not advised. | ||
# This file is expected to be part of source control. | ||
io.netty:netty-buffer:4.1.72.Final | ||
io.netty:netty-common:4.1.72.Final | ||
io.smallrye.common:smallrye-common-annotation:1.8.0 | ||
io.smallrye.reactive:mutiny:1.2.0 | ||
org.reactivestreams:reactive-streams:1.0.3 |
80 changes: 80 additions & 0 deletions
80
rsocket-mutiny/src/main/java/com/jauntsdn/rsocket/AbstractRSocket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright 2021 - present Maksym Ostroverkhov. | ||
* | ||
* 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 com.jauntsdn.rsocket; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
import org.reactivestreams.Publisher; | ||
|
||
public abstract class AbstractRSocket implements RSocketHandler { | ||
|
||
@Override | ||
public Uni<Void> fireAndForget(Message message) { | ||
message.release(); | ||
return Uni.createFrom() | ||
.failure(new UnsupportedOperationException("fire-and-forget not implemented")); | ||
} | ||
|
||
@Override | ||
public Uni<Message> requestResponse(Message message) { | ||
message.release(); | ||
return Uni.createFrom() | ||
.failure(new UnsupportedOperationException("request-response not implemented")); | ||
} | ||
|
||
@Override | ||
public Multi<Message> requestStream(Message message) { | ||
message.release(); | ||
return Multi.createFrom() | ||
.failure(new UnsupportedOperationException("request-stream not implemented")); | ||
} | ||
|
||
@Override | ||
public Multi<Message> requestChannel(Publisher<Message> messages) { | ||
return Multi.createFrom() | ||
.failure(new UnsupportedOperationException("request-channel(messages) not implemented")); | ||
} | ||
|
||
@Override | ||
public Multi<Message> requestChannel(Message message, Publisher<Message> messages) { | ||
message.release(); | ||
return Multi.createFrom() | ||
.failure( | ||
new UnsupportedOperationException( | ||
"request-channel(message, messages) not implemented")); | ||
} | ||
|
||
@Override | ||
public Uni<Void> metadataPush(Message message) { | ||
message.release(); | ||
return Uni.createFrom() | ||
.failure(new UnsupportedOperationException("metadata-push not implemented")); | ||
} | ||
|
||
@Override | ||
public void dispose() {} | ||
|
||
@Override | ||
public boolean isDisposed() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Uni<Void> onClose() { | ||
return Uni.createFrom().nothing(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
rsocket-mutiny/src/main/java/com/jauntsdn/rsocket/ClientAcceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2021 - present Maksym Ostroverkhov. | ||
* | ||
* 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 com.jauntsdn.rsocket; | ||
|
||
import java.util.function.Function; | ||
|
||
public interface ClientAcceptor { | ||
|
||
RSocket accept(SetupMessage setup, RSocket requesterRSocket); | ||
|
||
@FunctionalInterface | ||
interface Interceptor extends Function<ClientAcceptor, ClientAcceptor> {} | ||
} |
Oops, something went wrong.