org.symcomp.scscp
Class SCSCPClient

java.lang.Object
  extended by org.symcomp.scscp.CASClient
      extended by org.symcomp.scscp.SCSCPClient
All Implemented Interfaces:
java.lang.Runnable, SCSCPConstants

public class SCSCPClient
extends CASClient
implements SCSCPConstants

A class to encapsulate the access to an SCSCP-Server. To use an SCSCP server to compute mathematical expressions that are given in OpenMath form, the SCSCP-protocol needs to be implemented. This class takes care of all the protocol stuff. To connect to an SCSCP-server running on machine www.somewhere.org on port 12345 just create an instance of SCSCPClient:

SCSCPClient client = new SCSCPClient("www.somewhere.org", 12345)

Then, you can communicate with the client in a non-blocking way by use of

or in a blocking way by use of computeBlocking.

A typical scenario would be:

 SCSCPClient client = new SCSCPClient("127.0.0.1", 12345);
 String token = client.compute("<OMOBJ>...</OMOBJ>");
 while (!client.resultAvailable(token))
         // do something reasonable with your time
 String result = client.getResult(token);
 // Now, use that result.
 
Or, in the blocking case:
 SCSCPClient client = new SCSCPClient("127.0.0.1", 12345);
 String result = client.computeBlocking("<OMOBJ>...</OMOBJ>");
 // Now, use that result.
 


Field Summary
protected  OpenMathBase.ENCODINGS activeEncoding
           
protected  OpenMathBase.ENCODINGS defaultEncoding
           
protected  java.io.BufferedReader inn
           
protected  java.lang.Integer loglevel
           
protected  java.io.PrintWriter out
           
protected  java.lang.Integer scscpPort
           
protected  java.lang.String scscpUri
           
protected  java.lang.String scscpVersion
           
protected  java.lang.String serviceId
           
protected  java.lang.String serviceName
           
protected  java.lang.String serviceVersion
           
protected  java.net.Socket socket
           
protected  java.lang.Integer state
           
protected  java.util.List<OpenMathBase.ENCODINGS> supportedEncodings
           
 
Fields inherited from class org.symcomp.scscp.CASClient
computations, currentComputation, id, resultThread, waitingComputations
 
Fields inherited from interface org.symcomp.scscp.SCSCPConstants
CLIENT_COMPUTING, CLIENT_DEAD, CLIENT_IDLE, CLIENT_QUIT, CLIENT_UNINITIALIZED, PI_SCSCP_ACK, PI_SCSCP_CANCEL, PI_SCSCP_ENCODINGS_SUPPORTED, PI_SCSCP_ENCODINGS_SUPPORTED_PATT, PI_SCSCP_END, PI_SCSCP_HELLO, PI_SCSCP_HELOPATT, PI_SCSCP_INFO, PI_SCSCP_INFOPATT, PI_SCSCP_KILL, PI_SCSCP_LEFT, PI_SCSCP_QUIT, PI_SCSCP_RIGHT, PI_SCSCP_START, PI_SCSCP_TERM, PI_SCSCP_TERMPATT, PI_SCSCP_VERPATT, PI_SCSCP_VERSION, STATE_COMPUTING, STATE_FINISHED, STATE_INMESSAGE, STATE_MSG_COMPLETED, STATE_NEGOTIATING, STATE_UNITIALIZED, STATE_WAITING
 
Constructor Summary
SCSCPClient()
           
SCSCPClient(java.lang.String uri, java.lang.Integer port)
          Creates an SCSCP-Client that connects to a server on the machine at uri port port.
 
Method Summary
 java.lang.String compute(OpenMathBase omCommand)
          Computes an OpenMath-expression, non-blocking.
 OpenMathBase computeBlocking(OpenMathBase omCommand)
          Computes an OpenMath-expression, blocking.
 OpenMathBase.ENCODINGS getActiveEncoding()
           
 java.lang.Integer getComputationState(java.lang.String token)
          Get the state of a particular computation.
 OpenMathBase getResult(java.lang.String token)
          Retrieves the result of a computation.
 java.lang.Integer getSCSCPPort()
           
 java.lang.String getSCSCPUri()
           
 java.lang.String getSCSCPVersion()
           
 java.lang.String getServiceId()
           
 java.lang.String getServiceName()
           
 java.lang.String getServiceVersion()
           
 java.lang.Integer getState()
           
 java.util.List<OpenMathBase.ENCODINGS> getSupportedEncodings()
           
protected  void log(java.lang.Integer l, java.lang.String msg)
          just for logging, quick hack, to be replaced by something better.
 void quit()
           
 java.lang.Boolean resultAvailable(java.lang.String token)
          Checks whether a given computation has finished.
 void run()
          Private method, does the actual background-communication.
 boolean setActiveEncoding(OpenMathBase.ENCODINGS enc, boolean force)
          Private method to send data to the SCSCP server
 void setLoglevel(java.lang.Integer l)
           
protected  void setSupportedEncodings(java.lang.String str)
          encoding business
 java.lang.String startComputation(Computation comp)
          Starts a Computation
 
Methods inherited from class org.symcomp.scscp.CASClient
getComputation, getComputations, getNumberOfComputations, isIdle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

scscpUri

protected java.lang.String scscpUri

scscpPort

protected java.lang.Integer scscpPort

socket

protected java.net.Socket socket

inn

protected java.io.BufferedReader inn

out

protected java.io.PrintWriter out

scscpVersion

protected java.lang.String scscpVersion

loglevel

protected java.lang.Integer loglevel

serviceName

protected java.lang.String serviceName

serviceVersion

protected java.lang.String serviceVersion

serviceId

protected java.lang.String serviceId

state

protected java.lang.Integer state

supportedEncodings

protected java.util.List<OpenMathBase.ENCODINGS> supportedEncodings

activeEncoding

protected OpenMathBase.ENCODINGS activeEncoding

defaultEncoding

protected OpenMathBase.ENCODINGS defaultEncoding
Constructor Detail

SCSCPClient

public SCSCPClient()

SCSCPClient

public SCSCPClient(java.lang.String uri,
                   java.lang.Integer port)
Creates an SCSCP-Client that connects to a server on the machine at uri port port.

Directly after the creation of the object, the version-negotiation (phase 1 of the SCSCP-protocol) is done.

Parameters:
uri - The IP-address or the hostname of the machine where the SCSCP-server is running
port - The port on which the SCSCP-Server is listening.
Method Detail

startComputation

public java.lang.String startComputation(Computation comp)
Starts a Computation

The Computation comp is sent to the attaced SCSCP-server. The function call returns immediately, returning a token which can be used to get the result using getResult.

Parameters:
comp - a Computation
Returns:
A string that is used to identify the call.

compute

public java.lang.String compute(OpenMathBase omCommand)
Computes an OpenMath-expression, non-blocking.

The OpenMath expression represented by the parameter omCommand is wrapped in a Computation and sent to the attached SCSCP-server. The function call returns immediately, returning a token which can be used to get the result using getResult.

Overrides:
compute in class CASClient
Parameters:
omCommand - an OpenMath expression
Returns:
A string that is used to identify the call.

computeBlocking

public OpenMathBase computeBlocking(OpenMathBase omCommand)
Computes an OpenMath-expression, blocking.

The OpenMath expression represented by the parameter omCommand is sent to the attaced SCSCP-server. The function call returns after the computation has finished returning an xml-string

Note, that this computation may take extremely long, so only use this call if there is really nothing you want to do in the meantime.

Parameters:
omCommand - an OpenMath expression
Returns:
An OpenMathBase object containing the OpenMath object computed by the SCSCP-Server.

getResult

public OpenMathBase getResult(java.lang.String token)
Retrieves the result of a computation.

Using the token returned by compute(), this function is used to retrieve the actual result. If the result is not yet ready, null is returned.

If a non-token is given, an Exception is raised.

Overrides:
getResult in class CASClient
Parameters:
token - A string that was created using compute()
Returns:
An OpenMathBase tree containing the OpenMath-xml computed by the SCSCP-Server.

resultAvailable

public java.lang.Boolean resultAvailable(java.lang.String token)
Checks whether a given computation has finished.

Using the token returned by compute(), this function is used to find out, whether the SCSCP-server has finished its computation.

If a non-token is given, an Exception is raised.

Overrides:
resultAvailable in class CASClient
Parameters:
token - a string that was created using compute()
Returns:
ready true if the computation is ready, false otherwise.

getComputationState

public java.lang.Integer getComputationState(java.lang.String token)
Get the state of a particular computation.

Using the token returned by compute(), this function can be used to find out what state this computation is in.

If a non-token is given, an Exception is raised.

Parameters:
token - A string that was created using compute()
Returns:
The state of the Computation

quit

public void quit()

run

public void run()
Private method, does the actual background-communication. Inherited from Runnable.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class CASClient

getServiceName

public java.lang.String getServiceName()

getServiceVersion

public java.lang.String getServiceVersion()

getServiceId

public java.lang.String getServiceId()

getSCSCPUri

public java.lang.String getSCSCPUri()

getSCSCPPort

public java.lang.Integer getSCSCPPort()

getSCSCPVersion

public java.lang.String getSCSCPVersion()

getState

public java.lang.Integer getState()

setSupportedEncodings

protected void setSupportedEncodings(java.lang.String str)
encoding business


getSupportedEncodings

public java.util.List<OpenMathBase.ENCODINGS> getSupportedEncodings()

getActiveEncoding

public OpenMathBase.ENCODINGS getActiveEncoding()

setActiveEncoding

public boolean setActiveEncoding(OpenMathBase.ENCODINGS enc,
                                 boolean force)
Private method to send data to the SCSCP server

Parameters:
enc - The requested encoding
force - Whether the encoding should be set even if it was not (known to be) supported.
Returns:
Whether the required enc was acivated.

log

protected void log(java.lang.Integer l,
                   java.lang.String msg)
just for logging, quick hack, to be replaced by something better.


setLoglevel

public void setLoglevel(java.lang.Integer l)


Copyright © 2010. All Rights Reserved.