1 7 8 package com.sun.corba.se.impl.transport; 9 10 import java.io.IOException ; 11 12 import com.sun.corba.se.pept.transport.Connection; 13 import com.sun.corba.se.pept.transport.ReaderThread; 14 import com.sun.corba.se.pept.transport.Selector; 15 16 import com.sun.corba.se.spi.orb.ORB; 17 import com.sun.corba.se.spi.orbutil.threadpool.Work; 18 19 import com.sun.corba.se.impl.orbutil.ORBUtility; 20 21 public class ReaderThreadImpl 22 implements 23 ReaderThread, 24 Work 25 { 26 private ORB orb; 27 private Connection connection; 28 private Selector selector; 29 private boolean keepRunning; 30 private long enqueueTime; 31 32 public ReaderThreadImpl(ORB orb, 33 Connection connection, Selector selector) 34 { 35 this.orb = orb; 36 this.connection = connection; 37 this.selector = selector; 38 keepRunning = true; 39 } 40 41 46 public Connection getConnection() 47 { 48 return connection; 49 } 50 51 public void close() 52 { 53 if (orb.transportDebugFlag) { 54 dprint(".close: " + connection); 55 } 56 57 keepRunning = false; 58 } 59 60 65 public void doWork() 67 { 68 try { 69 if (orb.transportDebugFlag) { 70 dprint(".doWork: Start ReaderThread: " + connection); 71 } 72 while (keepRunning) { 73 try { 74 75 if (orb.transportDebugFlag) { 76 dprint(".doWork: Start ReaderThread cycle: " 77 + connection); 78 } 79 80 if (connection.read()) { 81 return; 83 } 84 85 if (orb.transportDebugFlag) { 86 dprint(".doWork: End ReaderThread cycle: " 87 + connection); 88 } 89 90 } catch (Throwable t) { 91 if (orb.transportDebugFlag) { 92 dprint(".doWork: exception in read: " + connection,t); 93 } 94 orb.getTransportManager().getSelector(0) 95 .unregisterForEvent(getConnection().getEventHandler()); 96 getConnection().close(); 97 } 98 } 99 } finally { 100 if (orb.transportDebugFlag) { 101 dprint(".doWork: Terminated ReaderThread: " + connection); 102 } 103 } 104 } 105 106 public void setEnqueueTime(long timeInMillis) 107 { 108 enqueueTime = timeInMillis; 109 } 110 111 public long getEnqueueTime() 112 { 113 return enqueueTime; 114 } 115 116 public String getName() { return "ReaderThread"; } 117 118 123 private void dprint(String msg) 124 { 125 ORBUtility.dprint("ReaderThreadImpl", msg); 126 } 127 128 protected void dprint(String msg, Throwable t) 129 { 130 dprint(msg); 131 t.printStackTrace(System.out); 132 } 133 } 134 135 | Popular Tags |