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