/** * $OpenXM: OpenXM/src/OpenMath/ORG/openxm/tam/OpenXMControlServer.java,v 1.1 2001/01/30 05:55:14 tam Exp $ */ package ORG.openxm.tam; import java.io.*; import java.net.*; /** * OpenXM クライアントからの接続を行なうソケットを作成する抽象クラス. * 新たな ox コマンドの実装により, 廃止になる予定. */ public abstract class OpenXMControlServer{ private OpenXMControlServer server = null; private OpenXMstream control = null; private OpenXMstream stream = null; private Thread computeThread = null; final protected boolean debug = false; public OpenXMControlServer(){ this("localhost",1200,1300); } public OpenXMControlServer(String host,int CtrlPort,int StreamPort){ server = this; try{ control = new OpenXMstream(host,CtrlPort,true); stream = new OpenXMstream(host,StreamPort,true); this.start(); }catch(IOException e){} } final public void start(){ // control process of OpenXM try{ control.sendByteOrder(); debug("control: wait OX"); computeThread = new Thread(){ final public void run(){ try{ stream.sendByteOrder(); }catch(IOException e){} server.computeProcess(stream); } }; debug("control: compute process starting"); computeThread.start(); while(true){ OXmessage message = control.receive(); switch(message.getTag()){ case OXmessage.OX_COMMAND: switch(((SM)message.getBody()).getCode()){ case SM.SM_control_kill: return; case SM.SM_control_reset_connection: //resetConnection(); break; } break; default: break; } } }catch(IOException e){ System.err.println(e.getMessage()); }finally{ debug("computer process interrupting..."); computeThread.stop(); debug("interrupted. OK! I'll shutdown."); try{stream.close();}catch(IOException e){} try{control.close();}catch(IOException e){} } } abstract protected void computeProcess(OpenXMstream DataStream); /* private void computeProcess(OpenXMstream DataStream){ while(true){ debug("test process executing"); try{ DataStream.receive(); }catch(IOException e){} } } */ /* final public synchronized void resetConnection(){ debug("control: stopping computer process..."); try{ control.send(new CMO_INT32(0)); }catch(IOException e){ }catch(MathcapViolation e){} synchronized(stream){ computeThread.stop(); } debug("control: stopped."); try{ debug("control: sending SYNC BALL."); stream.sendOX_SYNC_BALL(); debug("control: waiting to receive SYNC BALL."); while(true){ OXmessage message = stream.receive(); debug("control: received "+ message); if(message.getTag() == OXmessage.OX_SYNC_BALL){ break; } } debug("control: received SYNC BALL and restart computer process"); computeThread = new Thread(this); computeThread.start(); }catch(IOException e){}catch(MathcapViolation e){} } */ final private void debug(String str){ if(debug){ System.err.println(str); } } /* public static void main(String[] argv){ String hostname = "localhost"; int ControlPort = 1200, DataPort = 1300; OpenXMserver ox; for(int i=0;i