Code Monkey home page Code Monkey logo

rxremote's Introduction

RxRemote

RxRemote extends the power of Rx Observables across android process.

Example

@Remoter
public interface ISampleService {
     //Returns a RemoteObservable<String> 
     RemoteObservable<String> getRemoteObservable();
}

(Above example uses Remoter interface instead of aidl, but it could be used with aidl too)

At server side

  • Use Factory class RemoteObservables to create/notify
@Override
public RemoteObservable<Integer> getDownloadObservable() {
	//Use the factory tied to "Download"	
	return RemoteObservables.<Integer>of("Download").newObservable();
}	
   ...
   	...
        	
//send the events
RemoteObservables.<Integer>of("Download").onNext(50);
RemoteObservables.<Integer>of("Download").onNext(100);

...
//complete
RemoteObservables.<Integer>of("Download").onCompleted();

OR

simply return a RemoteObservable wrapping your source Observable. Any events generated by the source Observable are delivered remotely

 			
@Override
public RemoteObservable<String> getRemoteObservable() {
	//wrap your observable with a RemoteObservable to return across Binder
	return new RemoteObservable<>(Observable.from(new String[]{"Hello", "World"}););
}	

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> observable = sampleService.getRemoteObservable().getObservable();

//This is an Rx Java observable that can be subsribed to get data from your remote service

OR

directly access the data from RemoteObservable, and listen for updates by registering a listener

ISampleService sampleService = new ISampleService_Proxy( binder ); //See remoter
RemoteObservable<String> remoteData = sampleService.getRemoteObservable();

//get last data
String data = remoteData.getData();

//listen for updates
remoteData.setDataListener(data -> {});

That's it!

Getting RxRemote

Gradle dependency

dependencies {
    implementation 'com.josesamuel:rxremote:2.0.8'
}

License

Copyright 2017 Joseph Samuel

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.

rxremote's People

Contributors

josesamuel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rxremote's Issues

Does RxRemote is affected by binder 1mb limit ?

From this link, I can read:
http://developer.android.com/reference/android/os/TransactionTooLargeException.html

"During a remote procedure call, the arguments and the return value of the call are transferred as Parcel objects stored in the Binder transaction buffer. If the arguments or the return value are too large to fit in the transaction buffer, then the call will fail and TransactionTooLargeException will be thrown.
The Binder transaction buffer has a limited fixed size, currently 1Mb, which is shared by all transactions in progress for the process. "

I bypass this limitation in aidl by sending a ParcelFileDescriptor, create a pipe and send data thought it. I am new to Observable and I don't know your implementation, if I use RemoteObservable<List> with List greater than 1mb, will it work?

Remoter dependency

Hey !
I tried your RxRemote with AIDL file directly and noticed that I need the Remoter dependency to make it work. Is it really necessary? If yes, it should be mentioned in the readMe.

Thank you !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.