-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement FileSource in Java #823
Comments
yes yes yes |
Yeah OK I will start looking into what is required on the JNI side to handle two way comms. |
Also taking a look at using JNI with arrays. A good overview is here. However it does not mention these functions that should be faster. Some JNI tips from IBM. Interesting way to remove the need to call Java from native: http://nerds-central.blogspot.com/2012/04/extreme-jni-performance.html Finally I need to read up on ByteBuffer |
We looked at Volley for the Android Raster SDK last February and again last Summer. We ultimately decided not to use it as it was a bit murky in terms of documentation / stability (see links). The Raster SDK currently uses Square's OkHttp for networking. That said we're now leaning towards using the Glide Framework based on some research in January for V4 support. The big reason is that it uses stock Java networking classes but can also make use of Volley and OkHttp if desired and has great caching support. That said it looks like Google's finally cleaned that those issues with the Tutorial / Overview that you found @ljbade. I'm not also familiar with GL's FileSource object so if you're feeling like Volley would work well for that then it's certainly worth kicking the tires again. |
The FileSource object's API is just three functions: a |
@ljbade and I just had a great discussion on the current state of Android GL and what a solution for this problem would need / look like. This was super helpful to understand what type of content was going to be downloaded, if it needed to be cached, etc as many of the Android networking libraries are tuned to specific features (ex: Glide for downloading and caching images) vs more generic HTTP access like OkHttp. Based on this info, I think it makes the most sense to investigate OkHttp and Volley for use in GL. OkHttp is a much more widely used in the Android world so it's likely many people using the Android GL SDK will also be using it in their apps. This can be good as it helps keep the overall number of dependencies (and app sizes) down, but it can also be bad especially for people who hardwire the Android GL SDK into their apps (see: Eclipse users). Summary of Discussion: Current State
Content To Download
Caching
Needs
|
Some other possibilities that have turned up during research:
Comparisons |
Native API References from @mikemorris. |
Images and Font demos are done. Next up is Styles. |
@bleege any reason we can't just treat everything as opaque binary data? It shouldn't matter to the Java request library what the contents of the files we're requesting are. |
@kkaefer Yep, we can do that. In fact the examples I've finished so far all make use of byte arrays and then use native features to make use of them (ImageView and Typeface). The next ones are JSON which is also built in to Android and ProtoBufs, which are probably going to require an additional library (I'm currently leaning towards using Square Wire for this). That said, the driving reason for looking at these different libraries is that the stock HTTP networking API in Android has some pretty severe limitations with some "highlights" being:
I've settled in on OkHttp from Square to build the examples described in previous comments. It gives us everything we need but is strictly HTTP / SPDY client and can provide data in binary format. This is in contrast to most open source libraries that try to solve these issues by also baking in other common addition features like custom JSON Support, Image processing, and POJO Marshaling. Since the GL Core is going to handle all this stuff we don't need it as addition bit weight in a library. Anyway, here's the link to the my example app on GitHub called OkGL. I"m going to try to finish up the features tomorrow (including cancel support) and then hopefully refactor it to be cleaner / easier to use. Please feel free to check it out and let me know what you think. |
The Java FileSource doesn't need to interpret the data it downloaded at all. |
Agreed. But I needed a way to test that things were behaving as they should. :-) |
Done with JSON. Investigating ProtoBuf next. |
Just finished building the PofC / Demo app using OkHttp. I didn't end us using a ProtoBuf library as this is likely to be processed by the Core GL engine so delivering it in Binary form is all what's needed. Was able to build out all required functionality though so IMHO OkHttp is going to be the library to use for implementing the FileSource in Java. For details please see the app's source code at: |
@bleege what do you mean about not being able to build all functionality? |
I've moved the completed OkGL project from my personal GitHub account to Mapbox's. I'd forgotten that the recent permissions refactor now gave me access to do so. Anyway, it'll be waiting there for us when we're ready to implement FileSource for Android GL. |
…tp Request object to help keep FileSource self contained.
Just built out the initial version of JavaFileSource for Android GL based on OkHttp. To use: // Request Resource from Web, Process with custom Callback
JavaFileSource.getInstance().request("http://www.mapbox.com", new Callback() {
@Override
public void onFailure(Request request, IOException e) {
}
@Override
public void onResponse(Response response) throws IOException {
}
});
// Cancel Request based on URL
JavaFileSource.getInstance().cancel("http://www.mapbox.com"); |
Awesome, now you need to create the C++ class and use JNI to glue them together. Let me know if you need help. |
Thanks @ljbade! I will happily take you up on your offer for assistance. 👍 |
Awesome! Thanks @ljbade! |
We are back on OkHTTP now. |
I think we should look at what it takes to implement the FileSource object in Java. This would allow us to remove the dependencies on CURL, OpenSSL and libzip, as well as SQLite.
With the FileSource refactor, we can now more easily swap out the storage backends: Either, we replace the FileSource object completely, which leaves us with implementing the FileSource API, which is essentially just a
request/cancel
method. All the underlying logic, like caching, HTTP requesting and loading from the APK file has to be implemented manually.We could also replace only part of the API, e.g. only reimplement the HTTP logic in Java. I think we should start with the latter, but potentially move our way up the chain until we have we can get rid of all of these dependencies, especially given that they have Java APIs that use the system's built-in libs.
/cc @ljbade
The text was updated successfully, but these errors were encountered: