Tuesday, June 6, 2023

JSR 376 / Java Platform Module system and Service Loader experience

 I have some pet projects I work on and I decided to convert one from a plain Java project over to using the Java Service loader and the Java Platform Module System.  The project uses a few well known libraries but isn't using Spring or other giant frameworks. I figured this should be pretty straight forward to do.

I started by converting over to the Java Service loader and after a bit of refactoring I got that working pretty well.  I expect anyone trying to convert an application or service over to it will find plenty of things that should be refactored to make it work well. It was a good experience though even though it was a good amount of work initially.

And then I started the conversion to the Java Platform Module system.  This was pretty difficult to get started and required more work and refactoring.  Some issues may simply be tooling issues in Eclipse or something along those lines.  For my first attempt, I eventually bailed on it and started from scratch again. 

At this point, I did make lots of good progress. I had things pretty much sorted out except for one thing. I had a problem with the Infinispan cache and the module system.  I didn't expect that and I tried all kinds of things to get past the issue.  I eventually ended using the JSR 107 Cache-api to abstract as much as possible from Infinispan specifics.  At this point, I expected it to work but I finally ended up at a particular error. The error indicated that there was an Infinispan package name that existed in two different jar files (with different classes) and that isn't supported by the module system.  I thought maybe it was a regression or small oversight - I mean, the module system has been around for some time now.  

I did a search of Infinispan issues for JSR 376, Jigsaw and platform module system but found no issues.  I finally put in an issue and the next day the tech lead closed the issue as a duplicate.  The original issue was reported by that tech lead back in 2019 as a high priority ticket.  If I had searched for "module", I probably would have found it.  Anyways, being that this was known since 2019 and the original ticket mentioned more packages that were split between jars - I am guessing this won't end up fixed anytime soon.

I removed Infinispan and am just using the JSR-107 support as a way to hide my use of a simple map for in-memory use for now.  I wanted to persist my data (which was a key benefit of Infinispan) so I briefly looked at creating my own file based persistence layer using some plain IO stream support along with protobuffers but even that had some issues.  

I'm planning to switch to ASN.1 - that is more standardized and has better "enterprise support" than most of the other serialization frameworks. Try finding active open source projects for "serialization" from google results related to that.  There are a few but there are many more that seem pretty dead. ASN.1 isn't going away anytime soon and there is an active Java project supporting it (along with many other language projects).

Thanks for reading!

Scott

[2023/06/11 Update] I'm coming to the conclusion that using the Java Platform Module system is both too high of a risk and too painful to do for any large software system. It is a risk because you can't guarantee it is going to work in a fully modular system because so many libraries and transitive dependencies are not modularized and/or have split packages. Based on how long the feature has been around, I don't see the situation improving without some major push that forces it. Trying to use Maven plugins such as "moditect-maven-plugin" and the "jlink" tool is way more effort than a short or mid-term payback would make worthwhile. Working with this tooling and trying to resolve the issues one at a time is a huge headache - certain errors are not found in a deterministic fashion. This means that you add a "fix" into the config and rerun your build and you don't get the error but you end up with a different one.  This doesn't mean you fixed the original error, it just means that it didn't pick the same problem point to report on.

I'm also rethinking the ASN.1 conversion. I was able to get the asn1bean project compiled (i.e. the ASN1 Compiler part) with Java 18 with some effort. I'm still determining if the generated code will really work the way I need/expect it to.  I've got some other things I want to work on now so maybe I'll come back to it later.


Jokes for my kids

My kids like to grown at my "bad dad" jokes. I come up with quite a few but I tend to quickly forget them before sharing.  I hope to capture many of the jokes here so they can be shared later.

  • What did the sheep say when a pig told them that all the cows got stuck in the mud by the pond?
    • The sheep said that is a "Cow-tastrophe".
  • What did the carrot say to the mature green onion when it saw containers of new onions?
    • You should be proud of your bunches of "bunches of [baby] onions"!

Here are my Chick-fil-a jokes from some time ago.

Random ideas and questions

  1.  Since the gravity from a black hole pulls in both light and matter, how might someone determine the effect on matter as it is drawn into a black hole?
    1. Could quantum entanglement be used? If two atoms were quantum entangled and one was released into the gravity of a black hole could you monitor the remaining atom for changes in spin patterns as the other atom is drawn into the black hole? What about trying to change the spin of the local atom and determine if there is any type of resistance to change in the spin? Would we even know if/when the quantum entanglement was broken or disrupted?
  2. Every CNC type machine I am aware of uses electric motors (servo or stepper) to drive a screw rod which then moves a platform or device. As the desired max distance increases, it becomes more difficult (or expensive) to handle larger speeds due to rod "flapping" (over a distance without any intermediate supports). Thicker/stiffer rods or reduced speeds often help. Is there a potentially better method available?  Maybe an electric motor with a hollow threaded shaft mounted to the platform instead? So instead of the long threaded shaft spinning, the electric motors threaded shaft spins and moves the platform along the threaded rod?  Downside is extra weight of electric motor on top of the normal platform/device weight. 
  3. Homes have all types of appliance that either generate, consume and/or move heat from one place to another; Clothes dryers create heat, hot water generation creates and/or consumes heat, refrigerators and HVAC move heat between locations. Would it be useful/possible to design homes with a "central heat exchanger" where waste heat could be transferred to devices needing heat? i.e. Heat produced by a clothes dryer might get transferred to a water heater instead of directly vented to outside a house. This might need intentional design support for appliances and there are likely issues with "dirty sources" like lint in dryer exhaust. Probably many other issues I'm not thinking of this second.
  4. Hot water is useful and needed for many things - showers, baths, washing dishes/clothes, pool heating, etc. In warm climates, using some form of solar heating of water usually involves use of some type of plastic piping, etc which is directly exposed to sunlight - where the heat transfers through the pipe into the water/liquid which then is moved somewhere else for use.  The piping outside is usually on a roof or possibly even taking up space in a yard.  Instead of having external piping, would it be efficient enough to use attic space?  The roof area is typically pretty significant so a huge amount of piping could be run in between rafters/trusses. Lack of direct sun reduces efficiency but the larger area and tendency to retain heat may make up for it - although cost may be a limiting factor. I also wonder if using the "waste heat" from an attic may provide a benefit of lowering cooling needs for a home? There would be obvious concerns about leaks in an attic but I wonder if techniques used for joining pipes for underground geothermal lines might work well. There is also the "my roofer used too long of a nail" type problems to avoid.
  5. If small drones were combined with helium "balloons" for lack of a better description and light weight, flexible solar panels with power storage - could it maintain flight for weeks or more? Could modular, self-assembling floating platforms be created from groups of drones? It would likely need some sort of method to prevent "flapping" of the joined drones - maybe some sort of torsion bar joined across the drones.  I visualize this like torsion bars in cars and trucks. I don't consider this "floating" drone as a close cousin to blimps, etc - it would be more aerodynamic and suited to maintaining its location with relatively low power consumption.  Applications of this might include long term monitoring of beaches and shallows (for sharks, etc), wildlife movements (pythons in Florida, turtle nests in remote areas), security, ground monitoring (sinkholes?), disaster relief deliveries, search/rescue, etc. Some domains are likely better handled by simpler technology so this would be more specialized. Domains of use should require fast setup, easy to relocate/remove/replace, reduce danger to human life for placing/operating/monitoring.