Skip to content

Split off api - #1378

Merged
michaz merged 13 commits into
masterfrom
split-off-api
May 25, 2018
Merged

michaz merged 13 commits into
masterfrom
split-off-api

Conversation

@michaz

@michaz michaz commented May 25, 2018 •

Copy link
Copy Markdown
Member

This does three things about sub-modules of which 1.) and 2.) are necessary to cleanly finish the across-repository Dropwizardification, and 3.) happened on the way:

1.) Split off web-bundle from web. This is minor and probably nobody will notice. Problem is that web builds into a shaded JAR (of which we don't use the shading), and such JARs are ugly to import from other projects, but we want to import the web services from other projects (to combine them to a single server), so the web services must go out of the module in which they are tied together.

2.) Split off api from core. This is, I think, a major win, also for our mobile platforms, because it means that the client-hc now doesn't pull in the entire core as a dependency, which it was doing before. I simply moved all the things needed by the client and the server and the core, transitively, until I could remove core from client-hc.

3.) Then, I also started moving some of the serialization and deserialization code to api, see #1137. But doing so requires a Jackson dependency in api, which means we now also have it (transitively) in core, in contrast to what the latest discussion in #1291 says. Read on:

  • It is possible to not put serialization / deserialization code into an api module. But then, such code would have to go into yet another module. Not framing this as "what dependencies do I need" but as "what does the module specify", it would mean that api contains the Java data classes and representation (or something) contains the wire format (JSON), of which there could be several. Again, this is possible, but the question is whether that would be practical, or maybe a bit purist. Actually, since GraphHopper is both a library and a REST service, it makes sense to say that our Java objects and our JSON representations are 1:1 and should be close together, see below.

  • Allowing on top of that the JSON library to be replaced would be totally enterprisey and over-engineered. We use Dropwizard, and Dropwizard uses Jackson, and the whole idea is to remove technical/boring/distracting stuff like serialization from code that is supposed to be about routing, and in the age of frameworks, that is made harder by wrapping it in custom interfaces, not easier.

  • We are still not using JSON (de-)serialization in the core, so we can split off the additional representation module any time if we must. Actually, this was totally easy to do, without the custom JSON facade: GraphHopper core methods can just be passed deserialized objects like JsonFeatureCollection, not JSON maps or filenames. Voilà. This is the start of another (different) discussion: Is GraphHopper core a library, or is it supposed to be exactly like web but without the web?

    • If the former, then it can stay like this: the user of the library can just de-serialize the JSON themselves (with a single call to Jackson, or whatever), or build the object in code, and pass the object, that's how pure libraries are supposed to be, and we can remove the Jackson dependency from api if we want, and from then on, GraphHopper only knows about Java objects, not about JSON or strings or files (except for GraphHopperStorage).
    • If the latter, we can just close the deal and say, fine, core includes Jackson now, and it can read JSON files by itself, and that's it.

@michaz
michaz requested a review from karussell May 25, 2018 10:41
@karussell

karussell commented May 25, 2018 •

Copy link
Copy Markdown
Member

Thanks! Looks like a huge change :)

I saw you moved some helper code into the memory mapping file, @devemux86 do you think this works with all the different Android versions?

which means we now also have it (transitively) in core, in contrast to what the latest discussion in #1291 says

Thanks for explaining this in-depth. This decision also makes sense and let's separate if there is a problem or if we have something else than JSON like pbf, kryo or whatever.

Is GraphHopper core a library, or is it supposed to be exactly like web but without the web?

I think more a library but at the same time when doing some work for #1112 I was in the need to serialize EncodedValues as "something" and if we use JSON there everything is easier compared to string or properties but then the core&storage really requires JSON. Probably the best would be if the Java library contains JSON at some point :)

@michaz

michaz commented May 25, 2018 •

Copy link
Copy Markdown
Member Author

and let's separate if there is a problem or if we have something else than JSON like pbf, kryo or whatever.

Exactly! I think a good model for a Java-library-which-is-also-a-REST-service which is allowed to evolve is: At each point in time, there is one mapping of Things-which-go-over-the-internet to Java objects which we think is current and the best, and the code for that one goes directly next to the Java objects, so that the relationship between the REST API and the Java is clean and short and one-unique-way-to-do-things. Things for "other formats" or "backward-compatibility" or "developer-sugar" go somewhere else, in pre-processors or filters or converters or something.

@devemux86

Copy link
Copy Markdown
Contributor

@karussell apparently you mean this.
If that code is accessed again with the same way probably would work on Android, but @michaz can I ask why the change?
Since it involves utility methods which handle special cases, would be preferred in some Helper class.
If need to be only in core, then can create a new Helper class there?

Regarding json, if I may express an opinion and if it's possible in the API, I'd vote for a separate module, so that core can remain pure Java.
i.e. with offline graphs there is no need for json (?), with only Java API the routing is fine.

@michaz

michaz commented May 25, 2018

Copy link
Copy Markdown
Member Author

If that code is accessed again with the same way probably would work on Android, but @michaz can I ask why the change?

@devemux86 Because it was used by StorableProperties and only by StorableProperties (and its test), so I figured it should go there. Maybe I don't get the rationale of the Helper class -- isn't it that things which don't work on Android should not go there but into Helper7?

@devemux86

Copy link
Copy Markdown
Contributor

No it's not a binary selection, Android or not. Even in Android unfortunately there are several paths in those methods, depending the Android version. 🙁

@michaz

michaz commented May 25, 2018

Copy link
Copy Markdown
Member Author

Sorry, I'm new to this, I have no idea what this is about. :-) I just see a class that's called Helper (pretty innocent name for something which is about preventing breaking platform compatibility :-) ), and I saw a method which is only used in one other place, and moved it to that place.

Why doesn't that work and what should I pay attention to?

@devemux86

Copy link
Copy Markdown
Contributor

I didn't say it won't work!
Without testing GraphHopper Android sample on Android Emulator with various Android versions, cannot be sure for anything. 🙂

@michaz

michaz commented May 25, 2018 •

Copy link
Copy Markdown
Member Author

Aha! So Helper is defined as "where things that maybe cause problems on Android go", correct? Got it.

But that's just for.. information purposes, right? I mean, suppose it works with Android, then StorableProperties works with Android. Suppose it doesn't, then it doesn't. But there's no automagic going on which replaces it with an alternative that does work on Android, right?

So either way, it will be as before.

But Helper exists as a warning sign, so that potentially-not-on-Android-working calls don't proliferate. Phew. Maybe we should write that into a comment or something.

@karussell

Copy link
Copy Markdown
Member

Sorry, maybe also my fault because Helper7 is indeed for the compatibility issues and not Helper. So let's try .... and sorry for the bubbles.

@michaz

michaz commented May 25, 2018

Copy link
Copy Markdown
Member Author

Arrrrrrgh! :-)

@michaz
michaz merged commit a7f57b7 into master May 25, 2018
@karussell karussell added this to the 0.11 milestone May 27, 2018
@michaz
michaz deleted the split-off-api branch April 22, 2020 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants