See: Description
Interface | Description |
---|---|
RemoteDataListener<T> |
Listener on the client side to get notified when the data is updated from server side.
|
Class | Description |
---|---|
RemoteEventController<T> |
Use this class to send the data at the server side that needs to
be delivered to the
rx.Observable at the client side. |
RemoteObservable<T> |
Observable across android remote services. |
RemoteObservableListener |
Listen for the remote close events
|
RemoteObservables<T> |
Helper class to create
RemoteObservable and send data through it
|
RxRemote extends the power of Rx Observables across android process.
@Remoter
public interface ISampleService {
//Define a remote method that returns a RemoteObservable <String >
RemoteObservable <String > getStateObservable();
}
At the service side :
//Controller to send events to cient
RemoteEventController <String > eventController = new RemoteEventController<>();
public RemoteObservable <String > getStateObservable() {
//wrap the controller and return
return new RemoteObservable<>(eventController);
}
...
...
//send the events
eventController.sendEvent("Idle");
eventController.sendEvent("Active");
...
//complete
eventController.sendCompleted();
public RemoteObservable <String > getStateObservable() {
//Use the factory tied to "State"
return RemoteObservables. <String > of("State").newObservable();
}
//Notify update
RemoteObservables. <String > of("State").onNext("Idle");
*
or, simply return a RemoteObservable wrapping your source Observable. Any events generated by the source Observable are delivered remotely
public RemoteObservable <String > getStateObservable() {
//wrap your observable with a RemoteObservable to return across Binder
return new RemoteObservable<>(Observable.from(new String[]{"Idle"});
}
At the client side :
Get the RxJava Observable from RemoteObervable that you get from remote service.
ISampleService sampleService = new ISampleService_Proxy( binder ); //See remoter
Observable <String > stateObservable = sampleService.getStateObservable().getObservable();
or, simply get the Data directly from the RemoteObservable
ISampleService sampleService = new ISampleService_Proxy( binder ); //See remoter
RemoteObservable <String > remoteObservable = sampleService.getStateObservable();
remoteObservable.getData(); //Get the last data
//Listen for updates
remoteObservable.setDataListener(data -> {
});
To add RxRemote to your project add these to its gradle dependencies:
implementation 'com.josesamuel:rxremote:2.0.3’