Using the Java-ECLiPSe Interface

# Chapter 8 Using the Java-ECLiPSe Interface

The Java-ECLiPSe Interface is a general-purpose tool for interfacing ECLiPSe with Java, Sun’s popular object-oriented platform-independent programming language. It could be used for example to write a Java graphical front-end to an ECLiPSe optimisation program or to interface ECLiPSe with a commercial application written in Java. This document assumes a moderate level of programming in Java (e.g. how to use classes, packages, interfaces etc. and some knowledge of the java.util, java.io and java.net libraries) and a basic knowledge of how to interact with ECLiPSe (e.g. how to execute a goal, nondeterminism, what lists are etc.). There are also some diagrams in UML notation, but these are not crucial to the reader’s understanding.

Section 8.1 is intended to get you started quickly by running the example program QuickTest.java. Section 8.2 gives a brief overview of the functionality of the Java-ECLiPSe interface by taking a closer look at how QuickTest.java works. In the other sections of the document you will learn how to write Java programs which can:

- Manipulate ECLiPSe terms and other data in Java (Section 8.3).
- Execute goals in ECLiPSe and use the results of this computation in Java (Section 8.4).
- Transfer data between Java and ECLiPSe using queues. (Section 8.5).
- Initialise and terminate different kinds of connections between ECLiPSe and Java. (Section 8.7).

Throughout this document, <eclipse_dir> stands for the root location of your ECLiPSe installation. Detailed javadoc-generated HTML descriptions of the API provided by the com.parctechnologies.eclipse package can be found at:

> <eclipse_dir>/doc/javadoc/JavaEclipseInterface/index.html

You may wish to browse the API documentation after reading this document to obtain more detailed descriptions of classes and interfaces in the package.

- Getting Started
  - Check your Java SDK version
  - Make the com.parctechnologies.eclipse package available in your class path
  - Compile and run QuickTest.java
- Functionality overview: A closer look at QuickTest.java
- Java representation of ECLiPSe data
  - General correspondence between ECLiPSe and Java data types
  - Atoms and compound terms
  - Lists
  - Floats and Doubles
  - Integers
  - Variables
  - The equals() method
- Executing an ECLiPSe goal from Java and processing the result
  - Passing the goal parameter to rpc
  - Note: yield/2, remote_yield/1 and rpc
  - Retrieving the results of an rpc goal execution
  - More details about rpc goal execution
- Communicating between Java and ECLiPSe using queues
  - Opening, using and closing queues
  - Opening a queue using ECLiPSe predicates
  - Writing and reading ECLiPSe terms on queues
  - Using the QueueListener interface
  - Access to ECLiPSe’s standard streams
- Asynchronous Communicating between Java and ECLiPSe
  - Opening and closing asynchronous queues
  - Opening an asychronous queue using ECLiPSe predicates
  - Writing and reading ECLiPSe terms on queues
- Managing connections to ECLiPSe
  - A unified ECLiPSe-side interface to Java : the ‘peer’ concept
  - Creating and managing ECLiPSe engines from Java
  - Connecting to an existing ECLiPSe engine using RemoteEclipse
  - Comparison of different Java-ECLiPSe connection techniques