org.symcomp.scscp
Class SCSCPServer

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

public class SCSCPServer
extends C3PO

A class to wrap the functionality of an SCSCP-server.
Whilst its superclass C3PO implements the transport layer of the SCSCP protocol, you can subclass SCSCPServer to simplify the development of an actual SCSCP compliant server.
A typical subclass looks like this (remove the _ before the @):

        _@SCSCPServerInfo(
                serviceName="MyBrilliantSCSCPServer",
                serviceVersion="0.0.1",
                serviceDescription="Solves every problem"
        )
    public class MySCSCPServer extends SCSCPServer {

                public static void MySCSCPServer(String[] args) throws Exception {
                        System.out.println(getServiceName() + " " + getServiceVersion() + " starting...");
                        breed(MySCSCPServer.class, 26134); // blocks
                }

                MySCSCPServer(String serviceId, java.io.PrintWriter out, java.io.BufferedReader inn) {
                        super(MySCSCPServer.class, serviceId, out, inn);
                        this.addHandler(new ProblemSolver());
                        // ... further Handlers go here
                }
        }
    


Field Summary
protected  CookieStore cookies
           
protected  java.util.HashSet<java.lang.String> terminatedComputations
          Keeps track of terminated computations
 
Fields inherited from class org.symcomp.scscp.C3PO
inn, loglevel, out, scscpVersion, serviceId, state, 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
SCSCPServer()
           
SCSCPServer(java.lang.Class claz, java.lang.String serviceId, java.io.PrintWriter out, java.io.BufferedReader inn)
          Creating an instance of the SCSCP server.
 
Method Summary
 void addHandler(ProcedureCallHandler pch)
          Adds a handler for a request.
 java.lang.String compute(java.lang.String input)
          This method is called from within C3POs run command.
 ProcedureCallHandler findHandler(org.symcomp.openmath.OMSymbol servicename)
          Find the appropriate Handler for a given service
protected  void receivedTerminateRequestInternal(java.lang.String callID)
          Keep track of terminated computations
 
Methods inherited from class org.symcomp.scscp.C3PO
announceRendevouz, breed, cleanup, getServiceDescription, getServiceName, getServiceVersion, log, logStackTrace, receivedInfo, receivedTerminateRequest, run, setLoglevel, spawn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cookies

protected CookieStore cookies

terminatedComputations

protected java.util.HashSet<java.lang.String> terminatedComputations
Keeps track of terminated computations

Constructor Detail

SCSCPServer

public SCSCPServer()

SCSCPServer

public SCSCPServer(java.lang.Class claz,
                   java.lang.String serviceId,
                   java.io.PrintWriter out,
                   java.io.BufferedReader inn)
Creating an instance of the SCSCP server. You may of course create a server yourself, but in general the inherited spawn and breed methods can make your life easier.

Parameters:
claz - The class itself, necessary due to the stupid inheritance-model of Java.
serviceId - The id of the instance
out - The socket to which the SCSCP server sends it output
inn - The socket from which the SCSCP server reads its input
Method Detail

compute

public java.lang.String compute(java.lang.String input)
This method is called from within C3POs run command. In this implementation the request is parsed to a tree of OpenMathBase objects, deconstructed, and the appropriate handler for the request is called.

Specified by:
compute in class C3PO
Parameters:
input - A request as an XML encoded OpenMath string.
Returns:
The answer as an XML encoded OpenMath string, or the empty string if the procedure call had option_return_nothing set.

receivedTerminateRequestInternal

protected void receivedTerminateRequestInternal(java.lang.String callID)
Keep track of terminated computations

Overrides:
receivedTerminateRequestInternal in class C3PO
Parameters:
callID - the callID of the call that could be terminated

addHandler

public void addHandler(ProcedureCallHandler pch)
Adds a handler for a request. The kind of request is determined inside the ProcedureCallHandler provided.

Parameters:
pch - The new handler.

findHandler

public ProcedureCallHandler findHandler(org.symcomp.openmath.OMSymbol servicename)
Find the appropriate Handler for a given service

Parameters:
servicename - The name of the service
Returns:
a ProcedureCallHandler that can handle the given servicename


Copyright © 2010. All Rights Reserved.