Java to Prolog interface

Author(s): Jesús Correas.

This module defines the Prolog side of the Java to Prolog interface. This side of the interface only has one public predicate: a server that listens at the socket connection with Java, and executes the commands received from the Java side.

In order to evaluate the goals received from the Java side, this module can work in two ways: executing them in the same engine, or starting a thread for each goal. The easiest way is to launch them in the same engine, but the goals must be evaluated sequentially: once a goal provides the first solution, all the subsequent goals must be finished before this goal can backtrack to provide another solution. The Prolog side of this interface works as a top-level, and the goals partially evaluated are not independent.

The solution of this goal dependence is to evaluate the goals in a different prolog engine. Although Ciao includes a mechanism to evaluate goals in different engines, the approach used in this interface is to launch each goal in a different thread.

The decision of what kind of goal evaluation is selected is done by the Java side. Each evaluation type has its own command terms, so the Java side can choose the type it needs.

A Prolog server starts by calling the prolog_server/0 predicate, or by calling prolog_server/1 predicate and providing the port number as argument. The user predicates and libraries to be called from Java must be included in the executable file, or be accesible using the built-in predicates dealing with code loading.


Usage and interface

Documentation on exports

PREDICATE

Usage:

Prolog server entry point. Reads from the standard input the node name and port number where the java client resides, and starts the prolog server listening at the jp socket. This predicate acts as a server: it includes an endless read-process loop until the prolog_halt command is received.

However, from the low-level communication point of view, this Prolog server actually works as a client of the Java side. This means that Java side waits at the given port to a Prolog server trying to create a socket; Prolog side connects to that port, and then waits for Java requests (acting as a 'logical' server). To use this Prolog server as a real server waiting for connections at a given port, use prolog_server/1.

    PREDICATE

    Usage:

    Waits for incoming Java connections to act as a Prolog goal server for Java requests.This is the only prolog_server/* predicate that works as a true server: given a port number, waits for a connection from Java and then serves Java requests. When a termination request is received, finishes the connection to Java and waits next Java connection request. This behaviour is different with respect to previous versions of this library. To work as before, use prolog_server/2.

    Although it currently does not support simultaneous Java connections, some work is being done in that direction.

    • Call and exit should be compatible with:
      (basic_props:atm/1)Arg1 is an atom.

    PREDICATE

    Usage:

    Prolog server entry point. Given a network node and a port number, starts the prolog server trying to connect to Java side at that node:port address, and then waits for Java requests. This predicate acts as a server: it includes an endless read-process loop until the prolog_halt command is received.

    However, from the low-level communication point of view, this Prolog server actually works as a client of the Java side. This means that Java side waits at the given port to a Prolog server trying to create a socket; Prolog side connects to that port, and then waits for Java requests (acting as a 'logical' server). To use this Prolog server as a real server waiting for connections at a given port, use prolog_server/1.

    • Call and exit should be compatible with:
      (basic_props:atm/1)Arg1 is an atom.
      (basic_props:atm/1)Arg2 is an atom.

    PREDICATE

    Usage:

    Command execution loop. This predicate is called when the connection to Java is established, and performs an endless loop processing the commands received. This predicate is only intended to be used by the Prolog to Java interface and it should not be used by a user program.

      PREDICATE
      No further documentation available for this predicate. The predicate is of type concurrent.

      PREDICATE
      No further documentation available for this predicate. The predicate is of type concurrent.

      PREDICATE
      No further documentation available for this predicate. The predicate is of type concurrent.