1 package org.jacorb.test.common; 2 3 22 23 import java.io.*; 24 25 34 public class StreamListener extends Thread 35 { 36 private BufferedReader in = null; 37 private String id = null; 38 private String ior = null; 39 40 public StreamListener(InputStream stream, String id) 41 { 42 this.in = new BufferedReader(new InputStreamReader(stream)); 43 this.id = id; 44 setDaemon (true); 45 } 46 47 51 public String getIOR() 52 { 53 while (true) 54 { 55 synchronized (this) 56 { 57 if (this.ior != null) 58 return this.ior; 59 else 60 try 61 { 62 this.wait(); 63 } 64 catch (InterruptedException ex) 65 { 66 } 68 } 69 } 70 } 71 72 public void run() 73 { 74 while (true) 75 { 76 try 77 { 78 String line = in.readLine(); 79 if (line == null) 80 { 81 break; 82 } 83 else if (line.startsWith("SERVER IOR: ")) 84 { 85 synchronized (this) 86 { 87 this.ior = line.substring(12); 88 this.notifyAll(); 89 } 90 } 91 else 92 { 93 System.out.println("[ SERVER " + id + " " + line + " ]"); 94 } 95 } 96 catch (Exception ex) 97 { 98 System.out.println("StreamListener exiting"); 100 break; 101 } 102 } 103 } 104 } 105 | Popular Tags |