main
Class DataGatherer

java.lang.Object
  extended by main.DataGatherer

public class DataGatherer
extends java.lang.Object

The DataGatherer class serves as a connection to Sophia. Its methods allow to send queries to sophia and to retrieve the results. A query must be set before it is executed and a query must be executed before its result can be seen.


Nested Class Summary
(package private)  class DataGatherer.ReadLine
           
 
Field Summary
private  java.lang.String query
           
private  java.lang.String result
           
private  int timeout
           
 
Constructor Summary
DataGatherer()
          Creates a new, uninitialized DataGatherer with a time-out value of 10 seconds.
DataGatherer(int timeout)
          Creates a new, uninitialized DataGatherer with a specified time before a query times out.
 
Method Summary
 void executeQuery()
          Executes the query and stores the results.
 void executeQuery(int timeout)
          Executes the query and stores the results.
 java.lang.String getResult()
          Returns the results from Sophia from executing the query.
private  java.lang.String sendQuery(java.lang.String host, java.lang.String port, int timeout)
           
 void setQuery(java.lang.String query)
          Sets the Prolog query that will be sent to Sophia.
 java.lang.String toString()
          Returns a string representation of the DataGatherer.
private  java.lang.String tryHosts(int timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

query

private java.lang.String query

result

private java.lang.String result

timeout

private int timeout
Constructor Detail

DataGatherer

public DataGatherer()
Creates a new, uninitialized DataGatherer with a time-out value of 10 seconds.


DataGatherer

public DataGatherer(int timeout)
Creates a new, uninitialized DataGatherer with a specified time before a query times out.

Parameters:
timeout - the time in seconds a query has before it times out
Method Detail

setQuery

public void setQuery(java.lang.String query)
Sets the Prolog query that will be sent to Sophia.

Parameters:
query - a String

executeQuery

public void executeQuery()
                  throws java.net.UnknownHostException,
                         java.io.IOException
Executes the query and stores the results. If the query times out, an exception will be thrown.

Throws:
java.net.UnknownHostException - the host is not accessible
java.io.IOException - an I/O error occurred

executeQuery

public void executeQuery(int timeout)
                  throws java.net.UnknownHostException,
                         java.io.IOException
Executes the query and stores the results. If the query times out as specified by the argument, an exception is thrown. The argument overrides the time-out value set by the constructor.

Parameters:
timeout - the time in seconds the query has before it times out
Throws:
java.net.UnknownHostException - if the host is not accessible
java.io.IOException - if an I/O error occurred

getResult

public java.lang.String getResult()
Returns the results from Sophia from executing the query.

Returns:
the query results

tryHosts

private java.lang.String tryHosts(int timeout)
                           throws java.net.UnknownHostException,
                                  java.io.IOException
Throws:
java.net.UnknownHostException
java.io.IOException

sendQuery

private java.lang.String sendQuery(java.lang.String host,
                                   java.lang.String port,
                                   int timeout)
                            throws java.io.IOException,
                                   java.net.UnknownHostException
Throws:
java.io.IOException
java.net.UnknownHostException

toString

public java.lang.String toString()
Returns a string representation of the DataGatherer.

Overrides:
toString in class java.lang.Object
Returns:
a string representation