public class PLConnection
extends java.lang.Object
CiaoJava
interface as a Java
object server (using PLConnection()
),
or as a connection to a Prolog query server
(using PLConnection(java.lang.String)
).
Working with a Prolog server using the Java side as a
client, the Prolog goals can be launched using
query(CiaoJava.PLTerm)
method with a PLTerm
object representing a goal
(PLAtoms
and PLStructures
)
or creating and using PLGoal
objects.Constructor and Description |
---|
PLConnection()
Creates a new
PLConnection object, establishing
a new socket server and listening Prolog connections on a
free port. |
PLConnection(int port,
java.lang.String[] where)
Creates a new
PLConnection object that executes the
Prolog server, and starts it. |
PLConnection(java.net.ServerSocket ss)
Creates a new PLConnection object, given an existing socket
server.
|
PLConnection(java.lang.String where)
Creates a new
PLConnection object that executes the
Prolog server, and starts it. |
PLConnection(java.lang.String[] where)
Creates a new
PLConnection object that executes the
Prolog server, and starts it. |
PLConnection(java.lang.String host,
int port)
Creates a new
PLConnection object that connects
to a Prolog server at host and port given as argument. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Deprecated.
This method is deprecated. Use
stop
method instead. |
protected void |
closeSocketStreams()
Closes interface sockets and related streams.
|
CiaoJava.PLInterpreter |
getInterpreter()
Gets the Prolog Interpreter object used to interpret
Prolog terms received from the Prolog side of the interface.
|
static PLConnection |
getPreviousConnection()
Returns the last started connection to a Prolog process.
|
java.lang.Process |
getPrologProcess() |
void |
join()
Waits until all the internal threads terminate.
|
protected void |
joinSocketHandlers()
Waits until socket handling threads terminate.
|
PLGoal |
query(PLTerm term)
Goal launching.
|
void |
start()
Starts the PLConnection for the Prolog-to-Java
interface: waits for a Prolog connection.
|
void |
start(java.lang.String host,
int port)
Starts the PLConnection for the Prolog-to-Java
interface, connecting to an already executing Prolog server,
listening at port given as argument.
|
void |
stop()
Stops the interface.
|
public PLConnection() throws PLException, java.io.IOException
PLConnection
object, establishing
a new socket server and listening Prolog connections on a
free port.
The port number on which it listens is printed out on the
standard output stream.
Once a Prolog process connects to it, starts the internal
threads to manage the communication.PLException
java.io.IOException
public PLConnection(java.lang.String[] where) throws PLException, java.io.IOException
PLConnection
object that executes the
Prolog server, and starts it.where
- The command-line to start the Prolog process.
This constructor forces that the connection be
established to the newly created Prolog
process, instead of waiting for any Prolog
client that wants to connect to it.
This constructor allows an array of strings
for command-line arguments.PLException
java.io.IOException
public PLConnection(java.lang.String where) throws PLException, java.io.IOException
PLConnection
object that executes the
Prolog server, and starts it.where
- The command-line to start the Prolog process.
This constructor forces that the connection be
established to the newly created Prolog
process, instead of waiting for any Prolog
client that wants to connect to it.PLException
java.io.IOException
public PLConnection(java.net.ServerSocket ss) throws PLException, java.io.IOException
ss
- ServerSocket
object representing a new
Prolog/Java server socket object.PLException
java.io.IOException
public PLConnection(int port, java.lang.String[] where) throws PLException, java.io.IOException
PLConnection
object that executes the
Prolog server, and starts it. The connection port between Java side
and Prolog side is fixed to the corresponding argument.port
- Port number to be used for the internal
communication to Prolog side.where
- The command-line to start the Prolog process.
This constructor forces that the connection be
established to the newly created Prolog
process, instead of waiting for any Prolog
client that wants to connect to it.
This constructor allows an array of strings
for command-line arguments.PLException
java.io.IOException
public PLConnection(java.lang.String host, int port) throws PLException, java.io.IOException
PLConnection
object that connects
to a Prolog server at host and port given as argument.host
- host name where the Prolog side is
waiting for Java connection.port
- Port number to be used for the internal
communication to Prolog side.PLException
java.io.IOException
public void start(java.lang.String host, int port) throws java.io.IOException, PLException
port
- port number to which the Prolog
server is waiting for Java connection.java.io.IOException
- if there are I/O problems.PLException
- if there are problems regarding the Prolog
process.public void start() throws java.io.IOException, PLException
java.io.IOException
- if there are I/O problems.PLException
- if there are problems regarding the Prolog
process.public CiaoJava.PLInterpreter getInterpreter()
public PLGoal query(PLTerm term) throws PLException, java.io.IOException
term
- Prolog term that will be evaluated as a Prolog
goal.PLGoal
object created to manage the goal.java.io.IOException
- if there are I/O problems.PLException
- if there are problems regarding the Prolog
process.public void close() throws java.lang.InterruptedException, java.io.IOException, PLException
stop
method instead.java.io.IOException
- if the socket stream has been broken.PLException
- if there are problems regarding the Prolog
process.java.lang.InterruptedException
public void stop() throws java.lang.InterruptedException, java.io.IOException, PLException
java.io.IOException
- if the socket stream has been broken.PLException
- if there are problems regarding the Prolog
process.java.lang.InterruptedException
protected void closeSocketStreams() throws java.lang.InterruptedException, java.io.IOException
java.io.IOException
- if the socket stream has been broken.java.lang.InterruptedException
public void join() throws java.lang.InterruptedException, java.io.IOException
java.lang.InterruptedException
java.io.IOException
protected void joinSocketHandlers() throws java.lang.InterruptedException
java.lang.InterruptedException
public static PLConnection getPreviousConnection()
public java.lang.Process getPrologProcess()