[BACK]Return to OMproxy.java CVS log [TXT][DIR] Up to [local] / OpenXM / src / OpenMath

Diff for /OpenXM/src/OpenMath/OMproxy.java between version 1.1 and 1.42

version 1.1, 1999/11/02 11:52:34 version 1.42, 2001/01/30 05:55:13
Line 1 
Line 1 
 import JP.ac.kobe_u.math.tam.OpenXM.*;  /**
    * $OpenXM: OpenXM/src/OpenMath/OMproxy.java,v 1.41 2000/10/11 08:32:13 ohara Exp $
    */
   
   import ORG.openxm.tam.*;
 import java.util.Stack;  import java.util.Stack;
 import java.io.*;  import java.io.*;
   
 class OMproxy implements Runnable{  public class OMproxy extends OpenXMControlServer{
   private OpenXM ox;  
   private Stack stack = new Stack();    private Stack stack = new Stack();
     protected boolean debug = false;
     final int version = 200006130;
   
   public OMproxy(String host,int ControlPort,int DataPort) throws IOException{    public OMproxy(String hostname,int ControlPort,int DataPort){
     ox = new OpenXM(this,host,ControlPort,DataPort);      super(hostname,ControlPort,DataPort);
   }    }
   
   public void run(){    public void computeProcess(OpenXMstream stream){
     OM2OXM P = new OM2OXM();      OM2OXM P = new OM2OXM();
   
       debug("OMproxy started.");
     try{      try{
       while(true){        while(true){
         synchronized(ox){          try{
           int ox_tag = ox.receiveOXtag();            OXmessage message = stream.receive();
             int ox_tag = message.getTag();
   
           switch(ox_tag){            switch(ox_tag){
           case OpenXM.OX_COMMAND:            case OXmessage.OX_COMMAND:
             StackMachine(ox.receiveSM());              StackMachine((SM)message.getBody(),stream);
             break;              break;
   
           case OpenXM.OX_DATA:            case OXmessage.OX_DATA:
             stack.push(ox.receiveCMO());              stack.push(message.getBody());
             System.out.println("push: "+ stack.peek());              debug("push: "+ stack.peek());
             break;              break;
           }            }
           }catch(RuntimeException e){
             System.err.println(e.getMessage());
             e.printStackTrace();
             debug("error occured. stack was cleared.");
             stack = new Stack();
         }          }
       }        }
     }catch(java.io.IOException e){      }catch(IOException e){
       System.err.println(e.getMessage());        System.err.println(e.getMessage());
       e.printStackTrace();        e.printStackTrace();
         System.err.println("error occured, and recovering processes seems to be impossible.");
       }catch(Exception e){
         System.err.println(e.getMessage());
         e.printStackTrace();
         System.err.println("error occured, and recovering processes seems to be impossible.");
       }finally{
         System.err.println("breaking...");
     }      }
   
     System.out.println("breaking...");  
   }    }
   
     /*
   public void stop(){    public void stop(){
     System.out.println("OMproxy Stoping...");      System.err.println("OMproxy Stoping...");
     synchronized(ox){      synchronized(ox){
       //this.stop();        //this.stop();
       while(!stack.empty()){        while(!stack.empty()){
         stack.pop();          stack.pop();
       }        }
       System.out.println("OMproxy Stopped");        System.err.println("OMproxy Stopped");
     }      }
   }    }
     */
   
   private void SM_popCMO() throws java.io.IOException{    private void SM_popCMO(OpenXMstream stream) throws java.io.IOException{
     if(stack.empty()){      try{
       ox.send(new CMO_NULL());        if(stack.empty()){
     }else{          stream.send(new CMO_NULL());
       ox.send(stack.pop());        }else{
           debug("sending CMO: "+ stack.peek());
           stream.send((CMO)stack.pop());
           debug("test");
         }
       }catch(MathcapViolation e){
         try{
           stream.send(new CMO_ERROR2(new CMO_STRING("MathcapViolation: "+
                                                 e.getMessage())));
         }catch(MathcapViolation tmp){}
     }      }
   }    }
   
Line 63  class OMproxy implements Runnable{
Line 91  class OMproxy implements Runnable{
     int argc;      int argc;
   
     if(!(stack.peek() instanceof CMO_STRING)){      if(!(stack.peek() instanceof CMO_STRING)){
       stack.push(new CMO_ERROR2());        stack.push(new CMO_ERROR2(new CMO_NULL()));
       return;        return;
     }      }
     function_name = ((CMO_STRING)stack.pop()).getString();      function_name = ((CMO_STRING)stack.pop()).getString();
Line 74  class OMproxy implements Runnable{
Line 102  class OMproxy implements Runnable{
     }      }
   
     if(argc != 1){      if(argc != 1){
       stack.push(new CMO_ERROR2());        stack.push(new CMO_ERROR2(new CMO_NULL()));
       return;        return;
     }      }
   
Line 86  class OMproxy implements Runnable{
Line 114  class OMproxy implements Runnable{
       return;        return;
     }      }
   
     stack.push(new CMO_ERROR2());      stack.push(new CMO_ERROR2(new CMO_NULL()));
     return;      return;
   }    }
   
   private void StackMachine(SM mesg) throws java.io.IOException{    private void SM_mathcap(OpenXMstream stream) throws java.io.IOException{
       CMO[] mathcap = new CMO[3];
   
       {
         CMO[] list = {new CMO_INT32(version),
                     new CMO_STRING("Ox_system=OMproxy.class"),
                     new CMO_STRING("Version=0."+ version),
                     new CMO_STRING("HOSTTYPE=JAVA")};
         mathcap[0] = new CMO_LIST(list);
       }
   
       {
         CMO[] list = {new CMO_INT32(SM.SM_popCMO),
                       new CMO_INT32(SM.SM_executeFunction),
                       new CMO_INT32(SM.SM_mathcap),
                       new CMO_INT32(SM.SM_setMathCap),
                       new CMO_INT32(SM.SM_control_kill),
                       new CMO_INT32(SM.SM_control_reset_connection)};
         mathcap[1] = new CMO_LIST(list);
       }
   
       {
         CMO[] CMOFormat = {new CMO_INT32(CMO.NULL),
                            new CMO_INT32(CMO.INT32),
                            new CMO_INT32(CMO.STRING),
                            new CMO_INT32(CMO.LIST),
                            new CMO_INT32(CMO.MONOMIAL32),
                            new CMO_INT32(CMO.ZZ),
                            new CMO_INT32(CMO.QQ),
                            new CMO_INT32(CMO.ZERO),
                            new CMO_INT32(CMO.DMS_GENERIC),
                            new CMO_INT32(CMO.RECURSIVE_POLYNOMIAL),
                            new CMO_INT32(CMO.DISTRIBUTED_POLYNOMIAL),
                            new CMO_INT32(CMO.POLYNOMIAL_IN_ONE_VARIABLE),
                            new CMO_INT32(CMO.BIGFLOAT),
                            new CMO_INT32(CMO.INDETERMINATE),
                            new CMO_INT32(CMO.TREE)};
         CMO[] DataFormat1 = {new CMO_INT32(OXmessage.OX_DATA),
                              new CMO_LIST(CMOFormat)};
         CMO[] list = {new CMO_LIST(DataFormat1)};
   
         mathcap[2] = new CMO_LIST(list);
       }
   
       stack = new Stack();
       stack.push(new CMO_MATHCAP(new CMO_LIST(mathcap)));
       debug("push: "+ stack.peek());
     }
   
     private void SM_setMathCap(OpenXMstream stream)
          throws java.io.IOException{
       Object mathcap = stack.pop();
   
       if(mathcap instanceof CMO_MATHCAP){
         stack.push(new CMO_ERROR2(new CMO_NULL()));
       }
       stream.setMathCap((CMO_MATHCAP)mathcap);
     }
   
     private void StackMachine(SM mesg,OpenXMstream stream)
          throws java.io.IOException{
       debug("receive: "+mesg);
   
     switch(mesg.getCode()){      switch(mesg.getCode()){
     case SM.SM_popCMO:      case SM.SM_popCMO:
       SM_popCMO();        SM_popCMO(stream);
       break;        break;
   
     case SM.SM_executeFunction:      case SM.SM_executeFunction:
       SM_executeFunction();        SM_executeFunction();
       break;        break;
   
       case SM.SM_mathcap:
         SM_mathcap(stream);
         break;
   
       case SM.SM_setMathCap:
         SM_setMathCap(stream);
         break;
   
     default:      default:
       System.out.println("received "+ mesg);        System.err.println("received "+ mesg);
     }      }
   }    }
   
   private CMO CMO2OMXML(CMO obj){    private CMO CMO2OMXML(CMO obj){
     String str = OM2OXM.CMO2OM(obj);      String str;
   
       try{
         str = OM2OXM.CMO2OM(obj);
       }catch(NumberFormatException e){
         debug("CMO2OMXML occuered error in trans");
         return new CMO_ERROR2(new CMO_STRING(e.toString()));
       }
   
     return new CMO_STRING(str);      return new CMO_STRING(str);
   }    }
   
Line 117  class OMproxy implements Runnable{
Line 222  class OMproxy implements Runnable{
     ByteArrayInputStream stream;      ByteArrayInputStream stream;
     CMO ret;      CMO ret;
   
     if(obj instanceof CMO_STRING){      debug("OMXML2CMO called: "+obj);
       return new CMO_ERROR2();      if(!(obj instanceof CMO_STRING)){
         return new CMO_ERROR2(new CMO_STRING("It's not CMO_STRING."));
     }      }
   
     try{      try{
       stream = new ByteArrayInputStream(((CMO_STRING)obj).getString().getBytes());        stream = new ByteArrayInputStream(((CMO_STRING)obj).getString().getBytes());
       ret = trans.parse(stream);        ret = trans.parse(stream);
     }catch(IOException e){      }catch(IOException e){
         debug("OMXML2CMO occuered error in trans");
       return new CMO_ERROR2(new CMO_STRING(e.toString()));        return new CMO_ERROR2(new CMO_STRING(e.toString()));
       }catch(NumberFormatException e){
         debug("OMXML2CMO occuered error in trans");
         return new CMO_ERROR2(new CMO_STRING(e.toString()));
     }      }
   
       debug("push: "+ret);
     return ret;      return ret;
   }    }
   
   public static void main(String argv[]){    private void debug(String str){
     String host = "localhost";      if(debug){
     int DataPort = 1300, ControlPort = 1200;        System.err.println(str);
       }
     }
   
     private static String usage(){
       String ret = "";
   
       ret += "usage\t: java OMproxy [options]\n";
       ret += "options\t:\n";
       ret += "\t -h \t show this message\n";
       ret += "\t -host hostname \t (default localhost)\n";
       ret += "\t -data port \t (default 1300)\n";
       ret += "\t -control port \t (default 1200)\n";
       ret += "\t -insecure \t this version ignore this option\n";
       ret += "\t -debug \t display debug messages\n";
   
       return ret;
     }
   
     public static void main(String[] argv){
       String hostname = "localhost";
       int ControlPort = 1200, DataPort = 1300;
       OpenXMControlServer ox;
   
     for(int i=0;i<argv.length;i++){      for(int i=0;i<argv.length;i++){
       if(argv[i].equals("-h")){        if(argv[i].equals("-h")){
         System.out.println("");          System.err.println("");
         System.exit(0);          System.exit(0);
       }else if(argv[i].equals("-host")){        }else if(argv[i].equals("-host")){
         host = argv[++i];          hostname = argv[++i];
       }else if(argv[i].equals("-data")){        }else if(argv[i].equals("-data")){
         DataPort = Integer.valueOf(argv[++i]).intValue();          DataPort = Integer.valueOf(argv[++i]).intValue();
       }else if(argv[i].equals("-control")){        }else if(argv[i].equals("-control")){
         ControlPort = Integer.valueOf(argv[++i]).intValue();          ControlPort = Integer.valueOf(argv[++i]).intValue();
       }else{        }else{
         System.err.println("unknown option :"+ argv[i]);          System.err.println("unknown option :"+ argv[i]);
         System.exit(1);          System.exit(1);
       }        }
     }      }
     System.out.println("host(ctrl,data): "+ host  
                        +"("+ ControlPort +","+ DataPort +")");  
   
       //ox = new OpenXMserver(hostname,ControlPort,DataPort);
       ox = new OMproxy(hostname,ControlPort,DataPort);
       /*
     try{      try{
       new OMproxy(host,ControlPort,DataPort);      }catch(java.net.UnknownHostException e){
       System.out.println("connected.");        System.err.println("host unknown.");
         System.err.println(e.getMessage());
         return;
     }catch(IOException e){      }catch(IOException e){
       System.err.println("Error occured: "+ e);        System.err.println("connection failed.");
       System.err.println(e.getLocalizedMessage());        System.err.println("IOException occuer !!");
       System.err.println(e.getMessage());        System.err.println(e.getMessage());
         return;
     }      }
       */
   
       ox.start();
   
       System.err.println("breaking...");
   }    }
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.42

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