PrologSession
handles the connection with the Prolog
Server. Currently only synchronous connections with the server are
supported.
Constructor Summary | |
---|---|
PrologSession()
Creates a new PrologSession instance with default
Prolog server settings. |
Method Summary | |
---|---|
public int |
getTimeout()
Returns the timeout in milliseconds before the connection to the Prolog server is reset (when a query is not answered). |
public void |
setTimeout(int timeout)
Sets the timeout in milliseconds before the connection to the Prolog server is reset (when a query is not answered). |
public static PrologSession |
getPrologSession(string name)
|
public static PrologSession |
getPrologSession(string name, HttpSession httpSession)
|
public int |
getPort()
Returns the port of the Prolog server. |
public void |
setPort(int prologServerPort)
Sets the port of the Prolog server (default 8066 ). |
public string |
getHost()
Returns the host of the Prolog server (exactly as registered in setHost ). |
public void |
setHost(string prologServerHost)
Sets the host of the Prolog server (default is localhost ). |
public bool |
isAlwaysClosing()
|
public void |
setAlwaysClose(bool close)
|
public void |
setAutoConnect(bool autoConnect)
Sets the connection mode of this PrologSession . |
public bool |
isAutoConnecting()
Returns the state of the auto connect mode. |
public QueryAnswer |
executeQuery(string query)
Sends a query to the Prolog server and waits for the answer before returning the QueryAnswer . |
public QueryAnswer |
executeQuery(string query, Bindings bindings)
Sends a query to the Prolog server and waits for the answer before returning the QueryAnswer . |
public QueryAnswer |
executeQuery(string query, Bindings bindings, string sessionID)
Sends a query to the Prolog server and waits for the answer before returning the QueryAnswer . |
public void |
connect()
Connects to the Prolog server. |
public bool |
isConnected()
Returns true if a connection with the Prolog server
is open and false otherwise. |
public void |
disconnect()
Closes the connection with the Prolog server. |
Constructor Detail |
---|
PrologSession()
PrologSession
instance with default
Prolog server settings.
Method Detail |
---|
public int getTimeout()
public void setTimeout(int timeout)
0
will disable timeouts for this
prolog session. Default is 2000 milliseconds.
timeout
- int
timeout in milliseconds or
0
to disable timeoutspublic static PrologSession getPrologSession(string name)
name
- the name of the prolog sessionnull
if no such
session could be foundpublic static PrologSession getPrologSession(string name, HttpSession httpSession)
name
- the name of the prolog sessionhttpSession
- the http sessionpublic int getPort()
public void setPort(int prologServerPort)
8066
).
prologServerPort
- the port of the Prolog serverpublic string getHost()
setHost
).
public void setHost(string prologServerHost)
localhost
). The host can be specified as either
IP-address or host name.
prologServerHost
- the host as an IP-address or host namepublic bool isAlwaysClosing()
public void setAlwaysClose(bool close)
public void setAutoConnect(bool autoConnect)
PrologSession
. If
set to true
it will ensure that it is connected to
the Prolog server as soon as a call to executeQuery
or anything else causing a need for communication happens. This
is by default set to true
.
public bool isAutoConnecting()
public QueryAnswer executeQuery(string query)
QueryAnswer
. Anonymous
variables (underscore, _
), will be ignored, and thus
not accessible in the QueryAnswer
.
executeQuery
throws IOException
if
communication problems with the server occurs. Please note:
executeQuery
will only return one answer.
query
- the query to send to the prolog server.
The characters in the query are restricted to ISO-8859-1.public QueryAnswer executeQuery(string query, Bindings bindings)
QueryAnswer
. Bindings
are variable
bindings for the given query and will ensure that the values are
stuffed correctly.
An example:QueryAnswer answer = executeQuery("evaluate(In,Out)",
new Bindings().bind("In","4*9."));
query
- the query to send to the prolog server
The characters in the query are restricted to ISO-8859-1.bindings
- the variable bindings to use in the querypublic QueryAnswer executeQuery(string query, Bindings bindings, string sessionID)
QueryAnswer
. Bindings
are variable
bindings for the given query and will ensure that the values are
stuffed correctly.
query
- the query to send to the prolog server
The characters in the query are restricted to ISO-8859-1.bindings
- the variable bindings to use in the querysessionID
- the session id to give to the prolog serverpublic void connect()
executeQuery
will automatically connect to the
server when called.
public bool isConnected()
true
if a connection with the Prolog server
is open and false
otherwise.
public void disconnect()
connect
.