001: /*
002: * $Id: ReaderWriterClear.java,v 1.7 2005/03/01 10:59:54 np145014 Exp $
003: * $Source: /m/portal/ps/srap/src/com/sun/portal/netlet/econnection/ReaderWriterClear.java,v $
004: * $Log: ReaderWriterClear.java,v $
005: * Revision 1.7 2005/03/01 10:59:54 np145014
006: * CR 6224556
007: *
008: * Revision 1.6 2005/02/23 05:44:05 ss150821
009: * RFE 6223490 - SRA Should use JDK based logging
010: *
011: * Revision 1.5 2004/12/08 10:12:30 ss144266
012: * End-2-End SSL Connection changes & Client-IP fix
013: *
014: * Revision 1.2.66.5 2004/09/03 13:03:36 ss144266
015: * Performance issue - Refer 5095315
016: *
017: * Revision 1.2.66.4 2004/09/01 16:56:49 ss144266
018: * Qwest Perf issue
019: *
020: * Revision 1.2.66.3 2004/08/18 10:24:20 ss150821
021: * 5072209 - Fix for preventing SEGV errors on using netlets
022: *
023: * Revision 1.2.66.2 2004/08/17 10:50:31 ss144266
024: * Removed debug statements
025: *
026: * Revision 1.2.66.1 2004/08/16 12:38:12 ss144266
027: * Proxylet QWEST changes for End to End SSL Support
028: *
029: * Revision 1.3 2004/07/01 10:57:13 ss144266
030: * END TO END SSL SUPPORT FOR PROXYLET - QWEST REQUIREMENT
031: *
032: * Revision 1.2 2003/03/27 11:39:48 bs126381
033: * Netlet on SSL, SunRay
034: *
035: * Revision 1.1.30.1 2003/01/27 09:42:48 bs126381
036: * Netlet on SSL
037: *
038: * Revision 1.1 2002/06/14 09:33:50 rt130506
039: * SRAP Rebranding
040: *
041: * Revision 1.3 2002/06/11 16:02:06 bv131302
042: * new branded
043: *
044: * Revision 1.2 2002/03/20 04:35:24 mm132998
045: * Bug ID # 4655269 CRT : # 602 Desc : Support for HTTP persistent connection at gateway
046: *
047: *
048: */
049: // @(#)ReaderWriterClear.java 1.11 "@(#)ReaderWriterClear.java 1.11 99/09/23 Sun Microsystems"
050: package com.sun.portal.netlet.econnection;
051:
052: import java.io.InputStream;
053: import java.io.InterruptedIOException;
054: import java.io.OutputStream;
055:
056: import com.sun.portal.rproxy.connectionhandler.Session;
057:
058: // End of Code Lihue - KeepAlive
059:
060: public class ReaderWriterClear extends ReaderWriter implements
061: GWRunnable {
062:
063: /*
064: * Added for RFE 4492648
065: */
066:
067: private long activityTime = System.currentTimeMillis();
068:
069: boolean processKeepAliveConnections = false;
070:
071: public static final long maxTimeOutSetting = Session.maxTimeOutSetting;
072: private static final long THREAD_SLEEP_TIME = Session.THREAD_SLEEP_TIME;
073:
074: private boolean readConnectResp = false;
075:
076: private String unqPortID;
077: private Integer logId;
078: final Object lock = new Object();
079:
080: public Thread readerThread = null;
081:
082: public boolean isreadTRunning = false;
083:
084: public boolean canProceed = false;
085:
086: public OutputStream clientOut = null;
087:
088: public boolean interruptedException = false;
089:
090: public ReaderWriterClear(ReaderWriterLock l, InputStream inStream,
091: OutputStream outStream) {
092: super (l, inStream, outStream);
093: }
094:
095: public ReaderWriterClear(ReaderWriterLock l, InputStream inStream,
096: OutputStream outStream, Integer logId) {
097: super (l, inStream, outStream);
098: //unqPortID = Port;
099: }
100:
101: public ReaderWriterClear(ReaderWriterLock l, InputStream inStream,
102: OutputStream outStream, Integer logId,
103: OutputStream clientOut) {
104: super (l, inStream, outStream);
105: this .clientOut = clientOut;
106: //unqPortID = Port;
107: }
108:
109: public void run() {
110: final ReaderWriterClear _obj = this ;
111:
112: int numBytes = 0;
113: byte[] buffer = new byte[MAXBUFFERSIZE];
114: byte[] sessID = new byte[5];
115:
116: boolean FIN_RCVD = false;
117:
118: isreadTRunning = true;
119: try {
120: while (go) {
121:
122: numBytes = in.read(buffer);
123:
124: System.arraycopy(buffer, 0, sessID, 0, sessID.length);
125:
126: if (new String(sessID).equals("FP1.0")) {
127: FIN_RCVD = true;
128: String ack = "ACKFP1.0\r\n\r\n";
129: clientOut.write(ack.getBytes());
130: clientOut.flush();
131: sessID = null;
132: break;
133: }
134:
135: if (numBytes > 0) {
136: out.write(buffer, 0, numBytes);
137: out.flush();
138: activityTime = System.currentTimeMillis();
139: } else if (numBytes == 0) {
140: System.out
141: .println("ReaderWriterClear got a 0 length read");
142: } else {
143: if (processKeepAliveConnections) {
144: long now = System.currentTimeMillis();
145: if (now - rwLock.getLastActivityTime() < maxTimeOutSetting) {
146: try {
147: Thread.currentThread().sleep(
148: THREAD_SLEEP_TIME);
149: } catch (InterruptedException iex) {
150: }
151: } else {
152: go = false;
153: //return;
154: }
155: } else {
156: go = false;
157: //return;
158: }
159: }
160:
161: } //end of while
162:
163: } catch (InterruptedIOException intrExp) {
164:
165: interruptedException = true;
166: } catch (Exception e) {
167: //e.printStackTrace();
168: return;
169: } finally {
170: buffer = null;
171:
172: if (FIN_RCVD == false) {
173: stop();
174: rwLock.notifyFinished(_obj);
175: rwLock = null;
176: }
177: }
178:
179: }
180:
181: public int getID() {
182: return lock.hashCode();
183: }
184:
185: public InputStream getInputStream() {
186: return in;
187: }
188:
189: public Thread getReaderThread() {
190: return readerThread;
191: }
192:
193: public boolean getInterruptedException() {
194: return interruptedException;
195: }
196:
197: public Object getLockObject() {
198: return lock;
199: }
200:
201: public synchronized boolean isreadTRunning() {
202: return isreadTRunning;
203: }
204:
205: public synchronized boolean canProceed() {
206: return canProceed;
207: }
208:
209: public synchronized void proceed(boolean proceed) {
210: canProceed = proceed;
211: }
212:
213: // Lihue - KeepAlive
214: public void useKeepAliveLogic() {
215: processKeepAliveConnections = Session.processKeepAliveConnections;
216: return;
217: }
218:
219: // End of Code : Lihue - KeepAlive
220:
221: /*
222: * Added by Rajesh T for RFE 4492648.
223: *
224: * @ returns the time in milliseconds
225: * when the last activity took place in this
226: * ReaderWriter
227: * @see com.sun.portal.netlet.eproxy.NetletGroup.
228: */
229: public long getLastActivityTime() {
230: return activityTime;
231: }
232:
233: //Methods of GWRunnable
234: public String getType() {
235: return RDR_WRITER_CLEAR;
236: }
237: //Methods of GWRunnable
238: }
|