Re: Storing data across webserver calls
Jan Wielemaker <[email protected]> Wed, 28 May 2014 13:23:20 +0200
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
On 05/28/2014 12:34 PM, Parker Jones wrote: > [Hope this list address still works, I haven't got around to moving across to google yet] Send an empty message to [email protected] and you are done. This still works, but many active members have gone. Cc'ed to the new place. > I am converting a text-based Prolog application to have a GUI via a webserver. In the code I have a predicate where data is threaded through the body. > > p(DataOut) :- > q1(Data1), % q1(-Data) > q2(Data1, Data2), % q2(+Data, -Data) > q3(Data2, DataOut). % q3(+Data, -Data) > > As part of the conversion to a UI application p/1 will be replaced > by button presses for each of q1, q2, and q3 and a handler for each button press. > > % for webserver > handler(q1_button, q1). > handler(q2_button, q2). > handler(q3_button, q3). > > The question then arises, how should data be threaded across > handlers q1, q2 and q3. > > Option 1: use the clause database, asserting and retracting intermediate data. Each handler retrieves data, performs a calculation and then stores the data again. > Option 2: use http session data. This moves the intermediate data > back and forth to the client. Not so good if the data is substantial. Nope. http session data is just a layer around assert/retract that makes sure that data is registered with the session. This fixes the issue with 1: you can get concurrent requests from different clients, messing up your single global state. It also ensures that the data is destroyed if the session gets a timeout. > My question is are these the only options or are there any other > ways to thread data across web handlers? Yes. You can create a thread and associate that with the session and make the thread wait for a message from an HTTP handler. You can find how that works in an old talk, which is still online at http://www.swi-prolog.org/download/publications/ICLP09-Tutorial.ppt, starting from slide 58. The Pengines work provides another way to do this, although this expects you to do the client work in JavaScript. It is a lot easier though. See also some of the examples on the scratchpad of http://pengines.swi-prolog.org. Use SWI-Prolog 7.1.16 (to appear very soon). Cheers --- Jan > > Many thanks for any suggestions, > Parker > > -------------- next part -------------- > HTML attachment scrubbed and removed > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog >