org.symcomp.scscp
Class C3PO

java.lang.Object
  extended by org.symcomp.scscp.C3PO
All Implemented Interfaces:
java.lang.Runnable, SCSCPConstants
Direct Known Subclasses:
SCSCPServer

public abstract class C3PO
extends java.lang.Object
implements java.lang.Runnable, SCSCPConstants

A class to encapsulate an SCSCP-Server. To set up an SCSCP server that can 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 set up an SCSCP server this class needs to be subclassed and the methods

need to be overridden.

Whilst the latter are self-explanatory, the compute method does the actual work. Here, some call to an CAS/a Library or something similar should be inserted which ought to translate the incomin OpenMath-xml string to another OpenMath-xml string.


Field Summary
protected  java.io.BufferedReader inn
           
protected static java.lang.Integer loglevel
           
protected  java.io.PrintWriter out
           
protected  java.lang.String scscpVersion
           
protected  java.lang.String serviceId
           
protected  java.lang.Integer state
           
protected  java.util.LinkedList<java.lang.String> 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
C3PO()
           
C3PO(java.lang.String serviceId, java.io.PrintWriter out, java.io.BufferedReader inn)
          Construct a C3PO-instance that reads its iputs from inn and writes its results to out.
 
Method Summary
static boolean announceRendevouz(int port, java.lang.String name, java.lang.String description)
          Used to announce the existence of this Server to the world
static void breed(java.lang.Class clazz, int port)
          Does exactly the same as spawn but the listening on port port is not done in a seperate thread, so that breed blocks.
protected  void cleanup()
          The "destructor" that is called when communication is done, for any reason.
abstract  java.lang.String compute(java.lang.String input)
          Public method that does the actual computation.
 java.lang.String getServiceDescription()
          Returns the description of the SCSCP-server.
 java.lang.String getServiceName()
          Returns the name of the SCSCP-server.
 java.lang.String getServiceVersion()
          Returns the version of the SCSCP-server.
protected static void log(java.lang.Integer l, java.lang.String msg)
          just for logging, quick hack, to be replaced by something better.
protected static void logStackTrace(java.lang.Integer l, java.lang.Exception e)
          just for logging, quick hack, to be replaced by something better.
protected  void receivedInfo(java.lang.String s)
          Method that is called when scscp info is received; simply prints a message.
protected  void receivedTerminateRequest(java.lang.String callID)
          Method that is called when a terminate request is received; simply prints a message
protected  void receivedTerminateRequestInternal(java.lang.String callID)
          Method that is called when a terminate request is received; simply prints a message
 void run()
          The run-loop which is called for a session.
static void setLoglevel(java.lang.Integer l)
          for logging, 0 is no output, 5 is a lot.
static void spawn(java.lang.Class clazz, int port)
          Listens on Port port, then for each incoming connection, it instantiates Class clazz and starts it run-loop in a new thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

state

protected java.lang.Integer state

scscpVersion

protected java.lang.String scscpVersion

out

protected java.io.PrintWriter out

inn

protected java.io.BufferedReader inn

serviceId

protected java.lang.String serviceId

waitingComputations

protected java.util.LinkedList<java.lang.String> waitingComputations

loglevel

protected static java.lang.Integer loglevel
Constructor Detail

C3PO

public C3PO(java.lang.String serviceId,
            java.io.PrintWriter out,
            java.io.BufferedReader inn)
Construct a C3PO-instance that reads its iputs from inn and writes its results to out.

Parameters:
serviceId - the name of the SCSCP Server
out - the PrintWriter to which the SCSCP Server prints its output.
inn - the BufferedReader from which the SCSCP Server reads its input.

C3PO

public C3PO()
Method Detail

breed

public static void breed(java.lang.Class clazz,
                         int port)
                  throws java.lang.Exception
Does exactly the same as spawn but the listening on port port is not done in a seperate thread, so that breed blocks.

Parameters:
clazz - the actual class whiss shall be instantiated
port - the port on which the server shall listen
Throws:
java.lang.Exception

spawn

public static void spawn(java.lang.Class clazz,
                         int port)
                  throws java.lang.Exception
Listens on Port port, then for each incoming connection, it instantiates Class clazz and starts it run-loop in a new thread.
spawn immediately returns, internally instanziating ScscspSpawner and starting it th a new thread.

Parameters:
clazz - the actual class whiss shall be instantiated
port - the port on which the server shall listen
Throws:
java.lang.Exception

run

public void run()
The run-loop which is called for a session.

Specified by:
run in interface java.lang.Runnable

cleanup

protected void cleanup()
The "destructor" that is called when communication is done, for any reason. This should be used in subclasses to clean up behind themselves.


compute

public abstract java.lang.String compute(java.lang.String input)
Public method that does the actual computation.

This method needs to be overridden in any subclass.

Parameters:
input - a String that contains an OpenMath-xml string
Returns:
the result of the computation

receivedTerminateRequest

protected void receivedTerminateRequest(java.lang.String callID)
Method that is called when a terminate request is received; simply prints a message

This method may be overridden in a subclass.

Parameters:
callID - the callID of the call that could be terminated

receivedTerminateRequestInternal

protected void receivedTerminateRequestInternal(java.lang.String callID)
Method that is called when a terminate request is received; simply prints a message

This method may be overridden in a subclass, but one needs to call super.receivedTerminateRequestInternal if that's done.

Parameters:
callID - the callID of the call that could be terminated

receivedInfo

protected void receivedInfo(java.lang.String s)
Method that is called when scscp info is received; simply prints a message.

This method may be overridden in a subclass.

Parameters:
s - the string of info received

getServiceName

public java.lang.String getServiceName()
Returns the name of the SCSCP-server.

This string is needed for the <?scscp ?>-hello-message. The value must be set via the ScscspServerInfo Annotation

Returns:
the name of the SCSCP server

getServiceVersion

public java.lang.String getServiceVersion()
Returns the version of the SCSCP-server.

This string is needed for the <?scscp ?>-hello-message. The value must be set via the ScscspServerInfo Annotation

Returns:
the version-number of the SCSCP server

getServiceDescription

public java.lang.String getServiceDescription()
Returns the description of the SCSCP-server. The value must be set via the ScscspServerInfo Annotation

Returns:
the description of the SCSCP server

announceRendevouz

public static boolean announceRendevouz(int port,
                                        java.lang.String name,
                                        java.lang.String description)
Used to announce the existence of this Server to the world

Parameters:
port - The Port on which the server runs
name - the name of the server
description - some description
Returns:
true if everything worked

setLoglevel

public static void setLoglevel(java.lang.Integer l)
for logging, 0 is no output, 5 is a lot. Loglevel is static, so this has effect troughtout all running C3PO's in the current application.


log

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


logStackTrace

protected static void logStackTrace(java.lang.Integer l,
                                    java.lang.Exception e)
just for logging, quick hack, to be replaced by something better.



Copyright © 2010. All Rights Reserved.