se.sics.prologbeans
Class PrologSession


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 static bool debugging()
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 null.
public QueryAnswer executeQuery(string query, Bindings bindings)
Sends a query to the Prolog server and waits for the answer before returning the null.
public QueryAnswer executeQuery(string query, Bindings bindings, string sessionID)
Sends a query to the Prolog server and waits for the answer before returning the null.
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.
protected void cancelQuery()
Called by the timeout monitor when a query takes too long.
   
Constructor Detail

PrologSession

PrologSession()
Creates a new PrologSession instance with default Prolog server settings.


 
Method Detail

debugging

public static bool debugging()


getTimeout

public int getTimeout()
Returns the timeout in milliseconds before the connection to the Prolog server is reset (when a query is not answered).


setTimeout

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). Setting the timeout to 0 will disable timeouts for this prolog session. Default is 2000 milliseconds. When a connection times out it will be closed silently.

Parameters:
timeout - int timeout in milliseconds or 0 to disable timeouts

getPrologSession

public static PrologSession getPrologSession(string name)
This method can only be used in Prologbeans/Java. If called in .NET it will throw an Error.

Parameters:
name - the name of the prolog session
Returns:
the named prolog session or null if no such session could be found

getPrologSession

public static PrologSession getPrologSession(string name, HttpSession httpSession)
This method can only be used in Prologbeans/Java. If called in .NET it will throw an Error.

Parameters:
name - the name of the prolog session
httpSession - the http session
Returns:
the named prolog session

getPort

public int getPort()
Returns the port of the Prolog server.


setPort

public void setPort(int prologServerPort)
Sets the port of the Prolog server (default 8066).

Parameters:
prologServerPort - the port of the Prolog server

getHost

public string getHost()
Returns the host of the Prolog server (exactly as registered in setHost).


setHost

public void setHost(string prologServerHost)
Sets the host of the Prolog server (default is localhost). The host can be specified as either IP-address or host name.

Parameters:
prologServerHost - the host as an IP-address or host name

isAlwaysClosing

public bool isAlwaysClosing()


setAlwaysClose

public void setAlwaysClose(bool close)


setAutoConnect

public void setAutoConnect(bool autoConnect)
Sets the connection mode of this 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 false.


isAutoConnecting

public bool isAutoConnecting()
Returns the state of the auto connect mode.


executeQuery

public QueryAnswer executeQuery(string query)
Sends a query to the Prolog server and waits for the answer before returning the null. Anonymous variables (underscore, _), will be ignored, and thus not accessible in the null. executeQuery throws null if communication problems with the server occurs. Please note: executeQuery will only return one answer.

Parameters:
query - the query to send to the prolog server. The characters in the query are restricted to ISO-8859-1.
Returns:
the answer from the prolog server
Throws:
IOException - if an error occurs. A possible cause is a timeout.

executeQuery

public QueryAnswer executeQuery(string query, Bindings bindings)
Sends a query to the Prolog server and waits for the answer before returning the null. 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."));

Parameters:
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 query
Returns:
the answer from the prolog server
Throws:
IOException - if an error occurs. A possible cause is a timeout.

executeQuery

public QueryAnswer executeQuery(string query, Bindings bindings, string sessionID)
Sends a query to the Prolog server and waits for the answer before returning the null. bindings are variable bindings for the given query and will ensure that the values are stuffed correctly.

Parameters:
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 query
sessionID - the session id to give to the prolog server
Returns:
the answer from the prolog server
Throws:
IOException - if an error occurs. A possible cause is a timeout.

connect

public void connect()
Connects to the Prolog server. By default executeQuery will automatically connect to the server when called.


isConnected

public bool isConnected()
Returns true if a connection with the Prolog server is open and false otherwise.


disconnect

public void disconnect()
Closes the connection with the Prolog server. The connection can be opened again with connect.


cancelQuery

protected void cancelQuery()
Called by the timeout monitor when a query takes too long. Override this method to handle the timeout in some way other than silently closing the connection.