Re: Networking in Prolog - a survey
- From: Alessio Stalla <alessiostalla@xxxxxxxxx>
- Date: Wed, 21 May 2008 10:49:23 -0700 (PDT)
On 21 Mag, 11:24, "rupertlssm...@xxxxxxxxxxxxxx"
<rupertlssm...@xxxxxxxxxxxxxx> wrote:
Reading this, one thing that occurs to me is that you can protect your
main prolog interpreter loop from needing to be multi-threaded by
putting a 'synchronized' block around it.
So if the user submits a query on the command line it gets passed to
the interpreter. If at the same time some data arrives on a socket and
invokes your event handler predicate which in turn triggers the
interpreter loop to run, it will have to wait for the users query to
complete before it gets processed. Perhaps not ideal for super
responsive io, but maybe good enough for your purposes. Also, only one
incoming packet at a time will be able to be processed. Once you
figure out how to make it multi-threaded, one day when you find the
time ;), you can remove this limitation.
I think the current architecture (with small modifications) could
allow to run the event handler code with a separate prolog stack, so
there's no need to make the interpreter loop synchronized. My main
concern is not multithreading per se, but giving the user access to a
full-blown threading api in prolog, which would require some effort.
If I limit the handling of threads to be only on the Java side, I can
avoid that concern for now. Of course that doesn't really solve the
problem in general since the code triggered by events will eventually
have to cooperate with code running on the main thread, but in my
limited scenario, in which event handling will simply be some limited
processing of the received data and possibly an assert to augment the
current theory, that problem isn't influent.
I think 'asynchronous' and 'event driven' io are pretty much the same
concept. Worth bearing in mind that computers are essentially event
driven machines at the hardware level (hardware devices create
interrupts when hardware events occurr). You can also simulate real
asynchronous io in Java by using threads. Basically you encode all
your io events as objects, then pass them into a concurrent producer/
consumer queue, then have a thread (or more) consuming and processing
the io events as they occurr. You need a reasonable amount of code on
top of the java.io blocking sockets or java.nio non-blocking sockets
to set up an event driven system like this. Fortunately there are such
libraries already in existence for you to use. You could look at:
http://www.eecs.harvard.edu/~mdw/proj/seda/
or
http://mina.apache.org/
for example.
Using these libraries mostly what you will have to do is to write an
event handler for incoming data that invokes you prolog interpreter
loop in an appropriate way, and to encode a library call in Java that
is callable from your prolog to output data to a socket.
Thanks for the pointers, I'll check them out, they might be useful for
other projects too ;)
Have you any plans to release the fruits of your labour as open
source? I am working in both of these areas myself at the moment,
logic programming and asynchronous io in Java, that is. Although I am
still a long way off attempting to marry them together. I have a
sourceforge project for real asynchronous io in Java:
https://sourceforge.net/projects/jsr203nio2
Which is just a stub at the moment. I have some code to upload into it
for asynchronous file io, asynchronous socket io is not done yet but
is planned in the coming months. I also have code for a prolog-like
logic engine, which has a byte code interpreter in Java, one in C, and
also compiles down to native using the LLVM back-end. I intend to
realease that as open source too. Yes, once I find the time to
complete it!
I have no problems in principle with releasing my work as open source
(in fact, I'll put online the current interpreter code as soon as I'll
have time to review it a bit). The fact is, such work doesn't
currently exist, and I'm afraid it'll continue to not exist for a good
amount of time... the extension of the interpreter is only a proposal
by my professor, we'll write an article about it but it is only a
theoretical speculation for now, since I work full time and don't have
much time for university :(
Good luck with your project,
And good luck with your projects too!
Rupert
Alessio
.
- Follow-Ups:
- Re: Networking in Prolog - a survey
- From: rupertlssmith@xxxxxxxxxxxxxx
- Re: Networking in Prolog - a survey
- From: A . L .
- Re: Networking in Prolog - a survey
- References:
- Networking in Prolog - a survey
- From: Alessio Stalla
- Re: Networking in Prolog - a survey
- From: rupertlssmith@xxxxxxxxxxxxxx
- Networking in Prolog - a survey
- Prev by Date: Re: large databases
- Next by Date: Re: Networking in Prolog - a survey
- Previous by thread: Re: Networking in Prolog - a survey
- Next by thread: Re: Networking in Prolog - a survey
- Index(es):
Relevant Pages
|