|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.opencyc.api.CycConnection
Provides a binary connection and an ascii connection to the OpenCyc server. The ascii connection is legacy and its use is deprecated.
Collaborates with the CycAccess class which wraps the api functions. CycAccess may be specified as null in the CycConnection constructors when the binary api is used. Concurrent api requests are supported for binary (cfasl) mode. This is implemented by two socket connections, the first being for asynchronous api requests sent to Cyc, and the second for the asychronous api responses received from Cyc.
Copyright 2001 Cycorp, Inc., license is open source GNU LGPL.
THIS SOFTWARE AND KNOWLEDGE BASE CONTENT ARE PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OPENCYC ORGANIZATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND KNOWLEDGE BASE CONTENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Inner Class Summary | |
protected class |
CycConnection.TaskProcessorBinaryResponseHandler
Class TaskProcessorBinaryResponseHandler handles responses from task-processor requests in binary communication mode. |
Field Summary | |
static int |
API_TRACE_DETAILED
Detailed api trace. |
static int |
API_TRACE_MESSAGES
Message-level api trace. |
static int |
API_TRACE_NONE
No api trace. |
int |
apiRequestId
outbound request serial id |
static int |
ASCII_MODE
Ascii mode connnection to the OpenCyc server. |
static int |
ASCII_PORT_OFFSET
ASCII port offset for the OpenCyc server. |
protected int |
asciiPort
The tcp port assigned to the ascii connection to the OpenCyc server. |
protected java.net.Socket |
asciiSocket
The tcp socket assigned to the ascii connection to the OpenCyc server. |
protected int |
basePort
The tcp port from which the asciiPort and cfaslPorts are derived. |
static int |
BINARY_MODE
CFASL (binary) mode connnection to the OpenCyc server. |
static int |
CFASL_PORT_OFFSET
CFASL (binary) port offset for the OpenCyc server. |
protected CfaslInputStream |
cfaslInputStream
The binary interface input stream. |
protected CfaslOutputStream |
cfaslOutputStream
The binary interface output stream. |
protected int |
cfaslPort
The tcp port assigned to the binary connection to the OpenCyc server. |
protected java.net.Socket |
cfaslSocket
The tcp socket assigned to the binary connection to the OpenCyc server. |
protected int |
communicationMode
Indicator for whether to use the binary or acsii connection with OpenCyc. |
static int |
CONCURRENT_MESSAGING_MODE
Concurrent messaging mode to the OpenCyc server. |
protected CycAccess |
cycAccess
A reference to the parent CycAccess object for dereferencing constants in ascii symbolic expressions. |
static int |
DEFAULT_BASE_PORT
Default base tcp port for the OpenCyc server. |
static int |
DEFAULT_COMMUNICATION_MODE
Default communication mode connnection to the OpenCyc server. |
static java.lang.String |
DEFAULT_HOSTNAME
Default host name for the OpenCyc server. |
static int |
DEFAULT_MESSAGING_MODE
Default messaging mode to the OpenCyc server. |
protected static int |
DEFAULT_PRIORITY
The default priority of a task-processor request. |
protected java.lang.String |
hostName
The name of the computer hosting the OpenCyc server. |
static int |
HTTP_PORT_OFFSET
HTTP port offset for the OpenCyc server. |
protected java.io.BufferedReader |
in
The ascii interface input stream. |
protected boolean |
isSymbolicExpression
Indicates if the response from the OpenCyc server is a symbolic expression (enclosed in parentheses). |
int |
messagingMode
Messaging mode to the OpenCyc server. |
protected java.lang.String |
myClientName
name of my api client |
protected static Timer |
notimeout
The timer which optionally monitors the duration of requests to the OpenCyc server. |
protected java.io.BufferedWriter |
out
The ascii interface output stream. |
protected boolean |
quotedStrings
An indicator for ascii communications mode that strings should retain their quote delimiters. |
protected java.util.Hashtable |
responseMessages
Implements an association: apiRequestId --> response message. |
static int |
SERIAL_MESSAGING_MODE
Serial messaging mode to the OpenCyc server. |
protected boolean |
taskProcessingEnded
Indicates to the taskProcessor response handlers that the server connection is closed. |
protected CycConnection.TaskProcessorBinaryResponseHandler |
taskProcessorBinaryResponseHandler
handles responses from task-processor requests in binary communication mode. |
protected int |
trace
Parameter that, when true, causes a trace of the messages to and from the server. |
protected org.doomdark.uuid.UUID |
uuid
Universally Unique ID that identifies this CycConnection to the Cyc server. |
protected java.util.Hashtable |
waitingReplyThreads
Implements an association: apiRequestId --> waiting thread for the response. |
Constructor Summary | |
CycConnection()
Constructs a new CycConnection object using the default host name, default base port number and binary communication mode. |
|
CycConnection(CycAccess cycAccess)
Constructs a new CycConnection object using the default host name, default base port number with binary communication mode, and the given CycAccess object. |
|
CycConnection(java.net.Socket cfaslSocket)
Constructs a new CycConnection using the given socket obtained from the parent AgentManager listener. |
|
CycConnection(java.lang.String hostName,
int basePort,
int communicationMode,
CycAccess cycAccess)
Constructs a new CycConnection object using a given host name, the given base port number, the given communication mode, and the given CycAccess object |
|
CycConnection(java.lang.String hostName,
int basePort,
int communicationMode,
int messagingMode,
CycAccess cycAccess)
Constructs a new CycConnection object using a given host name, the given base port number, the given communication mode, and the given CycAccess object |
Method Summary | |
void |
close()
Close the api sockets and streams. |
java.lang.String |
connectionInfo()
Returns connection information, suitable for diagnostics. |
java.lang.Object[] |
converse(java.lang.Object message)
Send a message to Cyc and return the Boolean true as the first element of an object array, and the cyc response Symbolic Expression as the second element. |
java.lang.Object[] |
converse(java.lang.Object message,
Timer timeout)
Send a message to Cyc and return the response code as the first element of an object array, and the cyc response Symbolic Expression as the second element, spending no less time than the specified timer allows but throwing a TimeOutException at the first opportunity
where that time limit is exceeded. |
protected java.lang.Object[] |
converseAscii(java.lang.String message,
Timer timeout)
Send a message to Cyc and return the Boolean response as the first element of an object array, and the cyc response Symbolic Expression as the second element, spending no less time than the specified timer allows but throwing a TimeOutException at the first opportunity
where that time limit is exceeded. |
protected java.lang.Object[] |
converseBinary(CycList message,
Timer timeout)
Send a message to Cyc and return the response code as the first element of an object array, and the cyc response Symbolic Expression as the second element, spending no less time than the specified timer allows but throwing a TimeOutException at the first opportunity
where that time limit is exceeded. |
protected java.lang.Object[] |
converseUsingAsciiStrings(java.lang.String message,
Timer timeout)
Send a message to Cyc and return the response code as the first element of a object array, and the Cyc response string as the second element. |
protected void |
finalize()
Ensures that the api socket connections are closed when this object is garbage collected. |
int |
getAsciiPort()
Return the ASCII port to which the CycConnection is established. |
int |
getBasePort()
Return the base port to which the CycConnection is established. |
int |
getCfaslPort()
Return the CFASL port to which the CycConnection is established. |
java.lang.String |
getHostName()
Return the name of the host to which the CycConnection is established. |
int |
getTrace()
Returns the trace value. |
protected void |
initializeConcurrentProcessing()
Initializes the concurrent processing mode. |
protected void |
interruptAllWaitingReplyThreads()
Recovers from a socket error by interrupting all the waiting reply threads. |
java.lang.Integer |
nextApiRequestId()
Returns the next apiRequestId. |
java.lang.Object[] |
receiveBinary()
Receives an object from the CYC server. |
CycList |
receiveBinaryApiRequest()
Receives a binary (cfasl) api request from a cyc server. |
void |
sendBinary(java.lang.Object message)
Sends an object to the CYC server. |
void |
sendBinaryApiResponse(java.lang.Object message)
Sends a binary (cfasl) api response to a cyc server. |
void |
setTrace(int trace)
Sets the trace value. |
protected CycList |
substituteForBackquote(CycList messageCycList,
Timer timeout)
Substitute a READ-FROM-STRING expression for expressions directly containing a backquote symbol. |
void |
traceOff()
Turns off the diagnostic trace of socket messages. |
void |
traceOn()
Turns on the diagnostic trace of socket messages. |
void |
traceOnDetailed()
Turns on the detailed diagnostic trace of socket messages. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static java.lang.String DEFAULT_HOSTNAME
public static final int DEFAULT_BASE_PORT
public static final int HTTP_PORT_OFFSET
public static final int ASCII_PORT_OFFSET
public static final int CFASL_PORT_OFFSET
public static final int API_TRACE_NONE
public static final int API_TRACE_MESSAGES
public static final int API_TRACE_DETAILED
protected int trace
public static final int ASCII_MODE
public static final int BINARY_MODE
public static final int DEFAULT_COMMUNICATION_MODE
protected int communicationMode
public static final int SERIAL_MESSAGING_MODE
public static final int CONCURRENT_MESSAGING_MODE
public static final int DEFAULT_MESSAGING_MODE
public int messagingMode
protected java.io.BufferedReader in
protected java.io.BufferedWriter out
protected CfaslInputStream cfaslInputStream
protected CfaslOutputStream cfaslOutputStream
protected java.lang.String hostName
protected int basePort
protected int asciiPort
protected int cfaslPort
protected java.net.Socket asciiSocket
protected java.net.Socket cfaslSocket
protected static final Timer notimeout
protected boolean isSymbolicExpression
protected CycAccess cycAccess
protected boolean quotedStrings
public int apiRequestId
protected static final int DEFAULT_PRIORITY
protected java.lang.String myClientName
protected java.util.Hashtable waitingReplyThreads
protected java.util.Hashtable responseMessages
protected CycConnection.TaskProcessorBinaryResponseHandler taskProcessorBinaryResponseHandler
protected boolean taskProcessingEnded
protected org.doomdark.uuid.UUID uuid
Constructor Detail |
public CycConnection(java.net.Socket cfaslSocket) throws java.io.IOException
cfaslSocket
- tcp socket which forms the binary connection to the OpenCyc serverpublic CycConnection() throws java.io.IOException, java.net.UnknownHostException, CycApiException
public CycConnection(CycAccess cycAccess) throws java.io.IOException, java.net.UnknownHostException, CycApiException
cycAccess
- the given CycAccess object which provides api services over
this CycConnection objectpublic CycConnection(java.lang.String hostName, int basePort, int communicationMode, CycAccess cycAccess) throws java.io.IOException, java.net.UnknownHostException, CycApiException
host
- the name of the computer hosting the OpenCyc server.basePort
- the base tcp port on which the OpenCyc server is listening for connections.communicationMode
- either ASCII_MODE or BINARY_MODEcycAccess
- the given CycAccess object which provides api services over
this CycConnection objectpublic CycConnection(java.lang.String hostName, int basePort, int communicationMode, int messagingMode, CycAccess cycAccess) throws java.io.IOException, java.net.UnknownHostException, CycApiException
host
- the name of the computer hosting the OpenCyc server.basePort
- the base tcp port on which the OpenCyc server is listening for connections.communicationMode
- either ASCII_MODE or BINARY_MODEmessagingMode
- either SERIAL_MESSAGING_MODE or CONCURRENT_MESSAGING_MODEcycAccess
- the given CycAccess object which provides api services over
this CycConnection objectMethod Detail |
protected void initializeConcurrentProcessing() throws java.io.IOException, java.net.UnknownHostException, CycApiException
protected void finalize()
finalize
in class java.lang.Object
public void close()
close
in interface CycConnectionInterface
public java.lang.String getHostName()
public int getBasePort()
public int getAsciiPort()
public int getCfaslPort()
public java.lang.Object[] converse(java.lang.Object message) throws java.io.IOException, CycApiException
converse
in interface CycConnectionInterface
message
- the api commandpublic java.lang.Object[] converse(java.lang.Object message, Timer timeout) throws java.io.IOException, TimeOutException, CycApiException
TimeOutException
at the first opportunity
where that time limit is exceeded.
If an error occurs the second element is the error message string.converse
in interface CycConnectionInterface
message
- the api command which must be a String or a CycListtimeout
- a Timer object giving the time limit for the api callprotected CycList substituteForBackquote(CycList messageCycList, Timer timeout) throws java.io.IOException, CycApiException
messageCyclist
- the input expression to be checked for directly containing
a backquote symbol.timeout
- a Timer object giving the time limit for the api callprotected java.lang.Object[] converseBinary(CycList message, Timer timeout) throws java.io.IOException, TimeOutException, CycApiException
TimeOutException
at the first opportunity
where that time limit is exceeded.
If an error occurs the second element is the error message string.
The concurrent mode of Cyc server communication is supported by
Cyc's pool of transaction processor threads, each of which can
concurrently process an api request.message
- the api commandtimeout
- a Timer object giving the time limit for the api callpublic java.lang.Integer nextApiRequestId()
public void sendBinary(java.lang.Object message) throws java.io.IOException
message
- the api commandpublic java.lang.Object[] receiveBinary() throws java.io.IOException, CycApiException
public CycList receiveBinaryApiRequest() throws java.io.IOException, CycApiException
public void sendBinaryApiResponse(java.lang.Object message) throws java.io.IOException, CycApiException
the
- api response objectprotected java.lang.Object[] converseAscii(java.lang.String message, Timer timeout) throws java.io.IOException, TimeOutException, CycApiException
TimeOutException
at the first opportunity
where that time limit is exceeded.
If an error occurs the first element is Boolean.FALSE and the second element
is the error message string.
The concurrent mode of Cyc server communication is supported by
Cyc's pool of transaction processor threads, each of which can
concurrently process an api request.message
- the api commandtimeout
- a Timer object giving the time limit for the api callprotected java.lang.Object[] converseUsingAsciiStrings(java.lang.String message, Timer timeout) throws java.io.IOException, CycApiException, TimeOutException
public int getTrace()
getTrace
in interface CycConnectionInterface
org.opencyc.api.CycConnectionInterface
public void setTrace(int trace)
setTrace
in interface CycConnectionInterface
trace
- the trace valuepublic void traceOn()
traceOn
in interface CycConnectionInterface
public void traceOnDetailed()
traceOnDetailed
in interface CycConnectionInterface
public void traceOff()
traceOff
in interface CycConnectionInterface
public java.lang.String connectionInfo()
connectionInfo
in interface CycConnectionInterface
protected void interruptAllWaitingReplyThreads()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |