Multi session / multi-tenant web app with SWI-Prolog

Part of the Linux origins story is that when its creator Linus Torvalds requested a copy of the Posix standard as a student, he was asked for money, which he refused to pay and proceeded to create a Unix clone untrammelled by bureaucracy.

This was a rallying cry for many developers working at various corporations who hated the standards.

Free BSD, on the other hand, tried to slavishly implement standards, leading to it now being a very marginal player.

Hi Boris

well, I try to avoid working with those companies’ software (except with java of course). Especially microsoft build real “clubs” reselling information and you need to spend thousands of dollars just to get the information. Well, I understand, that is also the richest company … not by chance. Regarding the reasonabilty of what I was expecting, well I am grateful to Jan for his gentle example. An example using something I do not find explained is more or less like a black box. Since SWI provides a quite extended help I was assuming that everything that can be used is also documented. Leave it undocumented, it was just a question. I do think it was a good idea of mine trying to look on this and that component in that nice looking client-server example, I was interested for. Thank you for your suggested readings :slight_smile: - have a nice evening.

:slight_smile: yeah, standards are not what they used to be. I also vaguely remember reading somewhere (in a “Linux textbook” probably?):

backwards compatibility is the hobgoblin of little minds

(citing from memory)

It is supposed to be a reference to the popular (and usually editorialized) quote. The word that tends to get skipped the most is “foolish”, along with the rest of the essay of course.

1 Like

The code is the explanation. This is Prolog, not C :wink: Otherwise we all need to use English to communicate with each other, which is very difficult, since for the majority of us English is a foreign language.

Thank you Jan, problem with encapsulation solved. Of course I kept sending tons of newlines and of flushes (thank you anyway for the hint) … swipl has a peculiarity using output streams. I observed that it mixes both output streams (stdout and stderr) while responding to the console. This is a behaviour I was not expecting, so the software was waiting endless for something to come in the output stream while this had come in the error stream.

More concretely this happened on the prompt used just before a read() function.
The prompt came in the output stream, the “:” symbol came in the error stream.

The reason, why this is so, is to find in the implementation. If you ask me, I find this could be fixed or controlled.

Anyway my encapsulation is now perfect and without problem after having fused together both streams.

Thank you for explaining me about the servers and clients, I keep still of the idea that such a shell encapsulation be really tenant-safe (since I did not have the chance to look at the code of the servers or to get a reliable answer on this issue). Every shell is the best encapsulation for a prolog instance. A bit waste of resources - I admit, but for the moment I am happy so, since I have the tenant-stuff under my control (or OS control). JPL is very nice (got it running, thank you) but it fuse every use into a single prolog instance, so I keep away from it for the moment. Cheers

1 Like

@jan sir, can you kindly take a look of this error? So I’m trying to run prolog file in Eclipse IDE via JPL.jar and this error shows up, java.lang.UnsatisfiedLinkError but i know what that error means but not quite sure about “image not found”. I do not use any image in my java project and the error keeps showing “image not found”, but referring what you said about “Prolog image”, I’m wondering if you might know from your knowledge.Thanks!

Caused by: java.lang.UnsatisfiedLinkError: /usr/local/Cellar/swi-prolog/8.0.3_1/libexec/lib/swipl/lib/x86_64-darwin/libjpl.dylib: dlopen(/usr/local/Cellar/swi-prolog/8.0.3_1/libexec/lib/swipl/lib/x86_64-darwin/libjpl.dylib, 1): Library not loaded: /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/lib/server/libjsig.dylib
Referenced from: /usr/local/Cellar/swi-prolog/8.0.3_1/libexec/lib/swipl/lib/x86_64-darwin/libjpl.dylib
Reason: image not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at jpl.JPL.loadNativeLibrary(JPL.java:100)
at jpl.fli.Prolog.(Prolog.java:85)
at jpl.Query.open(Query.java:286)
at jpl.Util.textToTerm(Util.java:162)
at jpl.Query.(Query.java:198)
at application.Main.start(Main.java:29)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)

For connectivity of prolog and java in OS X, I followed this guideline, which is a further elaboration from Sebastian Sardina to the original guide by Theo Champion in the context of my AOPD course in 2018.

I live in the happy world without Java, but the message suggests that JPL was compiled against a JDK that provides libjsig.dylib and you now try to run in against one that doesn’t. That is at least how I read the error message. I know very little about such issues. Getting this stuff to run requires knowledge on how different JDKs are organized on MacOS as well as some basics on dynamic linking on that platform. The latter helps me understanding more or less what the message is about, but don’t ask me what to do.

IMO, do not mix Prolog and Java in one process unless it is really unavoidable …

Humm may be I’ll try with different JDK version. Yeah I also don’t want to mix Prolog and Java but I’m assigned a Prolog Project at my university and teachers told us to use Java/JavaFx for UI. Although using JPL in swi-prolog software can create UI but I’m more comfortable to create UI in Eclipse IDE so yeah. Anyway, thanks for your suggestion :grin:

The suggestion, as I understand it:

means, don’t do it in the same process. It is surprisingly easy to run a web server with SWI-Prolog. So one way to avoid the hassle would be to have a UI in Java and a “backend” in Prolog. You don’t need RPC, use JSON over HTTP instead. It depends on what you are doing, exactly, but many of Jan’s posts higher up in this thread outline how exactly to approach it.