KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > transport > ReaderThreadImpl


1 /*
2  * @(#)ReaderThreadImpl.java 1.13 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.transport;
9
10 import java.io.IOException JavaDoc;
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     ////////////////////////////////////////////////////
42
//
43
// ReaderThread methods.
44
//
45

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     ////////////////////////////////////////////////////
61
//
62
// Work methods.
63
//
64

65     // REVISIT - this needs alot more from previous ReaderThread.
66
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             // REVISIT - put in pool;
82
return;
83             }
84
85             if (orb.transportDebugFlag) {
86             dprint(".doWork: End ReaderThread cycle: "
87                    + connection);
88             }
89
90         } catch (Throwable JavaDoc 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 JavaDoc getName() { return "ReaderThread"; }
117
118     ////////////////////////////////////////////////////
119
//
120
// Implementation.
121
//
122

123     private void dprint(String JavaDoc msg)
124     {
125     ORBUtility.dprint("ReaderThreadImpl", msg);
126     }
127
128     protected void dprint(String JavaDoc msg, Throwable JavaDoc t)
129     {
130     dprint(msg);
131     t.printStackTrace(System.out);
132     }
133 }
134
135 // End of file.
136
Popular Tags