[BACK]Return to OpenXMserver.java CVS log [TXT][DIR] Up to [local] / OpenXM / src / OpenMath / ORG / openxm / tam

Annotation of OpenXM/src/OpenMath/ORG/openxm/tam/OpenXMserver.java, Revision 1.1

1.1     ! tam         1: /**
        !             2:  * $OpenXM$
        !             3:  */
        !             4: package ORG.openxm.tam;
        !             5:
        !             6: import java.io.*;
        !             7: import java.net.*;
        !             8:
        !             9: /**
        !            10:  * OpenXM $B%/%i%$%"%s%H$+$i$N@\B3$r9T$J$&Cj>]%/%i%9(B.
        !            11:  * OpenXM $B%5!<%P$O$3$N%/%i%9$NGI@8%/%i%9$H$7$F=q$/(B.
        !            12:  * $B?7$?$J(B ox $B%3%^%s%I$N<BAu$K$h$j(B, $BITI,MW$K$J$kM=Dj(B.
        !            13:  */
        !            14: public abstract class OpenXMserver{
        !            15:   private OpenXMserver server = null;
        !            16:   private OpenXMconnection control = null;
        !            17:   private OpenXMconnection stream = null;
        !            18:   private Thread computeThread = null;
        !            19:   final protected boolean debug = false;
        !            20:
        !            21:   public OpenXMserver(){
        !            22:     this("localhost",1200,1300);
        !            23:   }
        !            24:
        !            25:   public OpenXMserver(String host,int CtrlPort,int StreamPort){
        !            26:     server = this;
        !            27:
        !            28:     try{
        !            29:       control = new OpenXMconnection(host,CtrlPort,true);
        !            30:       stream = new OpenXMconnection(host,StreamPort,true);
        !            31:
        !            32:       this.start();
        !            33:     }catch(IOException e){}
        !            34:   }
        !            35:
        !            36:   final public void start(){ // control process of OpenXM
        !            37:     try{
        !            38:       control.sendByteOrder();
        !            39:
        !            40:       debug("control: wait OX");
        !            41:       computeThread = new Thread(){
        !            42:        final public void run(){
        !            43:          try{
        !            44:            stream.sendByteOrder();
        !            45:          }catch(IOException e){}
        !            46:          server.computeProcess(stream);
        !            47:        }
        !            48:       };
        !            49:
        !            50:       debug("control: compute process starting");
        !            51:       computeThread.start();
        !            52:       while(true){
        !            53:        OXmessage message = control.receive();
        !            54:
        !            55:        switch(message.getTag()){
        !            56:        case OXmessage.OX_COMMAND:
        !            57:          switch(((SM)message.getBody()).getCode()){
        !            58:          case SM.SM_control_kill:
        !            59:            return;
        !            60:
        !            61:          case SM.SM_control_reset_connection:
        !            62:            //resetConnection();
        !            63:            break;
        !            64:          }
        !            65:          break;
        !            66:
        !            67:        default:
        !            68:          break;
        !            69:        }
        !            70:       }
        !            71:     }catch(IOException e){
        !            72:       System.err.println(e.getMessage());
        !            73:     }finally{
        !            74:       debug("computer process interrupting...");
        !            75:       computeThread.stop();
        !            76:       debug("interrupted. OK! I'll shutdown.");
        !            77:       try{stream.close();}catch(IOException e){}
        !            78:       try{control.close();}catch(IOException e){}
        !            79:     }
        !            80:   }
        !            81:
        !            82:   abstract protected void computeProcess(OpenXMconnection DataStream);
        !            83:   /*
        !            84:   private void computeProcess(OpenXMconnection DataStream){
        !            85:     while(true){
        !            86:       debug("test process executing");
        !            87:       try{
        !            88:        DataStream.receive();
        !            89:       }catch(IOException e){}
        !            90:     }
        !            91:   }
        !            92:   */
        !            93:
        !            94:   /*
        !            95:   final public synchronized void resetConnection(){
        !            96:     debug("control: stopping computer process...");
        !            97:     try{
        !            98:       control.send(new CMO_INT32(0));
        !            99:     }catch(IOException e){
        !           100:     }catch(MathcapViolation e){}
        !           101:     synchronized(stream){
        !           102:       computeThread.stop();
        !           103:     }
        !           104:     debug("control: stopped.");
        !           105:
        !           106:     try{
        !           107:       debug("control: sending SYNC BALL.");
        !           108:       stream.sendOX_SYNC_BALL();
        !           109:
        !           110:       debug("control: waiting to receive SYNC BALL.");
        !           111:       while(true){
        !           112:        OXmessage message = stream.receive();
        !           113:
        !           114:        debug("control: received "+ message);
        !           115:        if(message.getTag() == OXmessage.OX_SYNC_BALL){
        !           116:          break;
        !           117:        }
        !           118:       }
        !           119:       debug("control: received SYNC BALL and restart computer process");
        !           120:       computeThread = new Thread(this);
        !           121:       computeThread.start();
        !           122:     }catch(IOException e){}catch(MathcapViolation e){}
        !           123:   }
        !           124:   */
        !           125:
        !           126:   final private void debug(String str){
        !           127:     if(debug){
        !           128:       System.err.println(str);
        !           129:     }
        !           130:   }
        !           131:
        !           132:   /*
        !           133:   public static void main(String[] argv){
        !           134:     String hostname = "localhost";
        !           135:     int ControlPort = 1200, DataPort = 1300;
        !           136:     OpenXMserver ox;
        !           137:
        !           138:     for(int i=0;i<argv.length;i++){
        !           139:       if(argv[i].equals("-h")){
        !           140:         System.out.println("");
        !           141:         System.exit(0);
        !           142:       }else if(argv[i].equals("-host")){
        !           143:         hostname = argv[++i];
        !           144:       }else if(argv[i].equals("-data")){
        !           145:         DataPort = Integer.valueOf(argv[++i]).intValue();
        !           146:       }else if(argv[i].equals("-control")){
        !           147:         ControlPort = Integer.valueOf(argv[++i]).intValue();
        !           148:       }else{
        !           149:         System.err.println("unknown option :"+ argv[i]);
        !           150:         System.exit(1);
        !           151:       }
        !           152:     }
        !           153:
        !           154:     try{
        !           155:       ox = new OpenXMserver(hostname,ControlPort,DataPort);
        !           156:     }catch(UnknownHostException e){
        !           157:       System.err.println("host unknown.");
        !           158:       System.err.println(e.getMessage());
        !           159:       return;
        !           160:     }catch(IOException e){
        !           161:       System.err.println("connection failed.");
        !           162:       System.err.println("IOException occuer !!");
        !           163:       System.err.println(e.getMessage());
        !           164:       return;
        !           165:     }
        !           166:
        !           167:     ox.start();
        !           168:
        !           169:     System.out.println("breaking...");
        !           170:   }
        !           171:   */
        !           172: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>