1 ////////////////////////////////////////////////////////////////////////////// 2 // DX SOURCEFILE // 3 ////////////////////////////////////////////////////////////////////////////// 4 5 /* 6 * $Header: /src/master/dx/src/uipp/java/dx/client/DXClientThread.java,v 1.4 2005/12/26 21:33:43 davidt Exp $ 7 */ 8 9 10 package dx.client; 11 import java.io.*; 12 import java.net.*; 13 import java.lang.*; 14 import java.util.*; 15 import java.applet.*; 16 import dx.protocol.*; 17 18 public abstract class DXClientThread extends Thread 19 { 20 private boolean failed; 21 22 protected BufferedReader inputStream; 23 protected DXClient parent; 24 protected Vector actions; 25 26 public final static int SHOWDOC = 1; 27 public final static int MESSAGE = 2; 28 protected final static int LASTMSG = 50; 29 30 DXClientThread( DXClient apple, BufferedReader is )31 public DXClientThread( DXClient apple, BufferedReader is ) 32 { 33 inputStream = is; 34 parent = apple; 35 actions = new Vector( 10 ); 36 37 try { 38 actions.addElement( ( Object ) new 39 DXClientThreadCommand( this, messageMsg.GetCommand(), DXClientThread.MESSAGE ) ); 40 } 41 42 catch ( ClassNotFoundException cnfe ) { 43 cnfe.printStackTrace(); 44 } 45 } 46 47 // 48 // Read from the server until receiving a message that says a file has 49 // been updated. Then show the document; 50 // run()51 public void run() 52 { 53 failed = false; 54 55 try { 56 String inputLine; 57 58 while ( ( failed == false ) && ( ( inputLine = inputStream.readLine() ) != null ) ) { 59 //System.out.println("InputLine: " + inputLine); 60 Enumeration enum1 = actions.elements(); 61 boolean executed = false; 62 63 while ( enum1.hasMoreElements() ) { 64 DXClientThreadCommand etc = ( DXClientThreadCommand ) enum1.nextElement(); 65 66 if ( inputLine.startsWith( etc.getCommandString() ) ) { 67 executed = etc.execute( inputLine ); 68 69 if ( executed ) break; 70 } 71 } 72 73 if ( !executed ) { 74 System.out.println ( "DXClientThread: Unrecognized - " + inputLine ); 75 } 76 } 77 } 78 79 catch ( IOException e ) { 80 failed = true; 81 } 82 83 catch ( Exception e ) { 84 e.printStackTrace(); 85 failed = true; 86 } 87 88 // 89 // Do not add any code after the call to disconnect because 90 // the applet will stop this thread 91 // 92 if ( failed ) 93 parent.disconnect( this ); 94 } 95 96 // 97 // If the error message looks fatal then terminate. 98 // The server side won't terminate before we do. 99 // message( threadMsg msg )100 public boolean message ( threadMsg msg ) 101 { 102 messageMsg mm = ( messageMsg ) msg; 103 System.out.println ( mm.getMessage() ); 104 105 if ( mm.getMessage().startsWith( "Error" ) ) 106 failed = true; 107 108 return true; 109 } 110 111 } 112 113 ; // end DXClientThread 114 115 116