Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Implement FileSource in Java #823

Closed
Closed

Description

@kkaefer

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

Activity

  1. added
    Android
    on Feb 6, 2015
  2. mikemorris commented on Feb 6, 2015

    @mikemorris
    Contributor

    yes yes yes

  3. ljbade commented on Feb 6, 2015

    @ljbade
    Contributor

    Yeah OK I will start looking into what is required on the JNI side to handle two way comms.

  4. ljbade commented on Feb 8, 2015

    @ljbade
    Contributor

    Looks like we should use Volley. @bleege Are you familiar with Volley?

    As far as JNI goes main thing is to pay attention to object references with local/global scope and ensuring Java attached to any threads.

  5. ljbade commented on Feb 8, 2015

    @ljbade
    Contributor

    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

  6. bleege commented on Feb 8, 2015

    @bleege
    Contributor

    Looks like we should use Volley. @bleege Are you familiar with Volley?

    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.

  7. kkaefer commented on Feb 9, 2015

    @kkaefer
    MemberAuthor

    The FileSource object's API is just three functions: a request() function that will request the URL, returns a cancelable Request object, and will run the provided callback in the provided loop. A request() function that only takes a URL and a callback, and will call the callback in an arbitrary thread, and finally a cancel() function that takes a Request object, and is supposed to cancel the request. In terms of the underlying implementation, it does not mandate anything, except that the functions must be threadsafe.

  8. bleege commented on Feb 10, 2015

    @bleege
    Contributor

    @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

    • Using native Linux networking logic

    Content To Download

    • Images
      • PNG and JPEG for Satellite & Maki Icons
    • Fonts
    • Styles (JSON)
    • .pbf (Gzip compress protocol buffer)
      ** Binary files

    Caching

    • Done in the GL native library so not needed at the Java side

    Needs

    • Takes URL and returns BLOB of data
    • Asynchronous
  9. ljbade commented on Feb 10, 2015

    @ljbade
    Contributor

    @bleege spot on summary,

    should also add, must support android 2.x if possible -> #555

  10. added this to the milestone on Feb 17, 2015
  11. bleege commented on Feb 17, 2015

    @bleege
    Contributor

    Some other possibilities that have turned up during research:

    Comparisons

  12. bleege commented on Feb 17, 2015

    @bleege
    Contributor
  13. bleege commented on Feb 17, 2015

    @bleege
    Contributor

    Images and Font demos are done. Next up is Styles.

  14. kkaefer commented on Feb 18, 2015

    @kkaefer
    MemberAuthor

    @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.

  15. bleege commented on Feb 18, 2015

    @bleege
    Contributor

    @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:

    • Synchronous only requests that block
    • SSL handshaking / failover issues
    • Lack of connection pooling
    • No automatic GZIP support

    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.

  16. 52 remaining items

  17. added a commit that references this issue on Nov 6, 2015
    c0bea9f
  18. modified the milestones: android-v2.3.0, on Dec 4, 2015
  19. modified the milestones: , android-v2.3.0 on Dec 4, 2015
  20. jfirebaugh commented on Jan 6, 2016

    @jfirebaugh
    Contributor

    We are back on OkHTTP now.

  21. bleege commented on Jan 6, 2016

    @bleege
    Contributor

    Yep, OkHTTP is back via #2400 , #2856 , and #2857 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Android

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions