001: package com.sun.portal.rproxy.connectionhandler;
002:
003: import java.net.*;
004: import java.lang.*;
005: import java.io.*;
006: import java.util.logging.Logger;
007: import java.util.logging.Level;
008:
009: import com.sun.portal.netlet.econnection.*;
010: import com.sun.portal.netlet.eproxy.*;
011: import com.sun.portal.util.*;
012: import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
013: import com.sun.portal.util.SRAEvent;
014:
015: public class RWGroupJSSProxy extends ReaderWriterLock {
016: private Socket fromClient;
017: private Socket toServer;
018:
019: private ReaderWriterClear src_to_dst;
020: private ReaderWriterClear dst_to_src;
021: private boolean src_to_dst_clean = false;
022: private boolean dst_to_src_clean = false;
023: private long startTime;
024: private static Logger logger = null;
025:
026: public RWGroupJSSProxy(Socket fromSocket, Socket toSocket) {
027: logger = Logger.getLogger("com.sun.portal.sra.rproxy");
028: startTime = System.currentTimeMillis();
029: fromClient = fromSocket;
030: toServer = toSocket;
031: try {
032: src_to_dst = new ReaderWriterClear(this , fromClient
033: .getInputStream(), toServer.getOutputStream());
034: dst_to_src = new ReaderWriterClear(this , toServer
035: .getInputStream(), fromClient.getOutputStream());
036: } catch (Exception ex) {
037: /*
038: System.out.println("Unable to create ReaderWriter threads.");
039: ex.printStackTrace();
040: */
041: logger.log(Level.SEVERE,
042: "Unable to create ReaderWriter threads.", ex);
043: }
044: try {
045: GWThreadPool.run(src_to_dst);
046: GWThreadPool.run(dst_to_src);
047: } catch (InterruptedException e) {
048: logger.log(Level.SEVERE,
049: "Could not start ReaderWriterClear tasks", e);
050: }
051: }
052:
053: public synchronized void notifyFinished(ReaderWriter obj) {
054: if (obj == src_to_dst) {
055: if (dst_to_src.isAlive()) {
056: dst_to_src.stop();
057: }
058: } else if (obj == dst_to_src) {
059: if (src_to_dst.isAlive()) {
060: src_to_dst.stop();
061: }
062: }
063: cleanup();
064: if (obj == src_to_dst) {
065: src_to_dst_clean = true;
066: } else if (obj == dst_to_src) {
067: dst_to_src_clean = true;
068: }
069: }
070:
071: public void cleanup() {
072: if (fromClient != null) {
073: try {
074: fromClient.close();
075: if (fromClient instanceof org.mozilla.jss.ssl.SSLSocket) {
076: MonitoringSubsystem
077: .handleEvent(SRAEvent.SSL_SOCKET_DESTROYED);
078: } else {
079: MonitoringSubsystem
080: .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
081: }
082: } catch (Exception e) {
083: } finally {
084: fromClient = null;
085: }
086: }
087: if (toServer != null) {
088: try {
089: toServer.close();
090: if (toServer instanceof org.mozilla.jss.ssl.SSLSocket) {
091: MonitoringSubsystem
092: .handleEvent(SRAEvent.SSL_SOCKET_DESTROYED);
093: } else {
094: MonitoringSubsystem
095: .handleEvent(SRAEvent.PLAIN_SOCKET_DESTROYED);
096: }
097: } catch (Exception e) {
098: } finally {
099: toServer = null;
100: }
101: }
102: }
103:
104: public boolean isDone() {
105: if (dst_to_src_clean && src_to_dst_clean) {
106: dst_to_src = null;
107: src_to_dst = null;
108: }
109: return (dst_to_src_clean && src_to_dst_clean);
110: }
111:
112: /*
113: * Added by Rajesh T for RFE 4492648.
114: * @ returns the latest of the two access time of the 2
115: * ReaderWriter's associated in this Group in milliseconds
116: * @see com.sun.portal.netlet.eproxy.NetletGroup.
117: */
118:
119: public long getLastActivityTime() {
120:
121: if (src_to_dst.getLastActivityTime() > dst_to_src
122: .getLastActivityTime())
123: return src_to_dst.getLastActivityTime();
124: else
125: return dst_to_src.getLastActivityTime();
126:
127: }
128:
129: /*
130: * Added for RFE 4492648
131: * @ see com.sun.portal.econnection.ReaderWriterLock
132: */
133:
134: public synchronized void stopAll() {
135:
136: if (dst_to_src != null) {
137: dst_to_src.stop();
138: }
139: if (src_to_dst != null) {
140: src_to_dst.stop();
141: }
142: cleanup();
143:
144: }
145:
146: /*
147: * Added for Netlet PRD 1.8.1 for Lihue
148: * dummy implementation
149: */
150:
151: public int getAppletSrcPort() {
152: return 0;
153: }
154:
155: public long getStartTime() {
156: return startTime;
157: }
158:
159: }
|