Feature - Add support for Reactive and RxJava2 interfaces for RemoteService object #2040
parent
747d073c1b
commit
042290e9bd
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2013-2019 Nikita Koksharov
|
||||
*
|
||||
* 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 org.redisson.api.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation used to mark interface as Reactive
|
||||
* client interface for remote service interface.
|
||||
* <p>
|
||||
* All method signatures must match with remote service interface,
|
||||
* but return type must be <code>reactor.core.publisher.Mono</code>.
|
||||
* <p>
|
||||
* It's not necessary to add all methods from remote service.
|
||||
* Add only those which are needed.
|
||||
*
|
||||
* @see reactor.core.publisher.Mono
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RRemoteReactive {
|
||||
|
||||
/**
|
||||
* Remote interface class used to register
|
||||
*
|
||||
* @return class used to register
|
||||
*/
|
||||
Class<?> value();
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) 2013-2019 Nikita Koksharov
|
||||
*
|
||||
* 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 org.redisson.api.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation used to mark interface as RxJava2
|
||||
* client interface for remote service interface.
|
||||
* <p>
|
||||
* All method signatures must match with remote service interface,
|
||||
* but return type must be one of the following:
|
||||
* <ul>
|
||||
* <li>io.reactivex.Completable</li>
|
||||
* <li>io.reactivex.Single</li>
|
||||
* <li>io.reactivex.Maybe</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* It's not necessary to add all methods from remote service.
|
||||
* Add only those which are needed.
|
||||
*
|
||||
* @see io.reactivex.Completable
|
||||
* @see io.reactivex.Single
|
||||
* @see io.reactivex.Maybe
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface RRemoteRx {
|
||||
|
||||
/**
|
||||
* Remote interface class used to register
|
||||
*
|
||||
* @return class used to register
|
||||
*/
|
||||
Class<?> value();
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2013-2019 Nikita Koksharov
|
||||
*
|
||||
* 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 org.redisson.remote;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
import org.redisson.executor.RemotePromise;
|
||||
import org.redisson.reactive.CommandReactiveExecutor;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
*/
|
||||
public class ReactiveRemoteProxy extends AsyncRemoteProxy {
|
||||
|
||||
public ReactiveRemoteProxy(CommandAsyncExecutor commandExecutor, String name, String responseQueueName,
|
||||
ConcurrentMap<String, ResponseEntry> responses, Codec codec, String executorId,
|
||||
String cancelRequestMapName, BaseRemoteService remoteService) {
|
||||
super(commandExecutor, name, responseQueueName, responses, codec, executorId, cancelRequestMapName,
|
||||
remoteService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Class<?>> permittedClasses() {
|
||||
return Arrays.asList(Mono.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object convertResult(RemotePromise<Object> result, Class<?> returnType) {
|
||||
return ((CommandReactiveExecutor) commandExecutor).reactive(() -> result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Copyright (c) 2013-2019 Nikita Koksharov
|
||||
*
|
||||
* 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 org.redisson.remote;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.redisson.client.codec.Codec;
|
||||
import org.redisson.command.CommandAsyncExecutor;
|
||||
import org.redisson.executor.RemotePromise;
|
||||
import org.redisson.rx.CommandRxExecutor;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Maybe;
|
||||
import io.reactivex.Single;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Nikita Koksharov
|
||||
*
|
||||
*/
|
||||
public class RxRemoteProxy extends AsyncRemoteProxy {
|
||||
|
||||
public RxRemoteProxy(CommandAsyncExecutor commandExecutor, String name, String responseQueueName,
|
||||
ConcurrentMap<String, ResponseEntry> responses, Codec codec, String executorId,
|
||||
String cancelRequestMapName, BaseRemoteService remoteService) {
|
||||
super(commandExecutor, name, responseQueueName, responses, codec, executorId, cancelRequestMapName,
|
||||
remoteService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Class<?>> permittedClasses() {
|
||||
return Arrays.asList(Completable.class, Single.class, Maybe.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object convertResult(RemotePromise<Object> result, Class<?> returnType) {
|
||||
Flowable<Object> flowable = ((CommandRxExecutor) commandExecutor).flowable(() -> result);
|
||||
|
||||
if (returnType == Completable.class) {
|
||||
return flowable.ignoreElements();
|
||||
}
|
||||
if (returnType == Single.class) {
|
||||
return flowable.singleOrError();
|
||||
}
|
||||
return flowable.singleElement();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue