001: // @(#)KeepAlive.java 1.6 "@(#)KeepAlive.java 1.6 99/09/23 Sun Microsystems"
002:
003: package com.sun.portal.netlet.eproxy;
004:
005: import java.util.logging.Logger;
006:
007: import com.sun.portal.log.common.PortalLogger;
008: import com.sun.portal.netlet.econnection.ReaderWriter;
009:
010: public class KeepAlive implements Runnable {
011:
012: // public final int TIMEOUT = 1200000; // 20 minutes
013: public final int TIMEOUT = 30000; // 30 seconds
014:
015: private SessionAuthenticator sa;
016:
017: private SessionRequest req;
018:
019: private RWGroupCrypt rwg;
020:
021: private ReaderWriter src_to_dst;
022:
023: private ReaderWriter dst_to_src;
024:
025: private boolean go = true;
026:
027: private String tname;
028:
029: private static Logger logger = PortalLogger
030: .getLogger(KeepAlive.class);
031:
032: public KeepAlive(SessionAuthenticator s, SessionRequest r,
033: RWGroupCrypt rg, ReaderWriter src, ReaderWriter dst) {
034: sa = s;
035: req = r;
036: rwg = rg;
037: src_to_dst = src;
038: dst_to_src = dst;
039: }
040:
041: public void exit() {
042: // logger.info("KeepAlive: exiting KeepAlive timer");
043: logger.info("PSSRNTLT_CSPNEPROX040");
044: }
045:
046: public void run() {
047: tname = Thread.currentThread().getName();
048:
049: boolean alive = false;
050: while (go) {
051: try {
052: Thread.sleep(TIMEOUT);
053: } catch (InterruptedException e) {
054: // logger.info("KeepAlive: interrupted sleep");
055: logger.info("PSSRNTLT_CSPNEPROX041");
056: go = false;
057: continue;
058: }
059: if (src_to_dst != null) {
060: alive = src_to_dst.sentDataFlag();
061: src_to_dst.clearDataFlag();
062: }
063:
064: if (dst_to_src != null) {
065: alive = alive || dst_to_src.sentDataFlag();
066: dst_to_src.clearDataFlag();
067: }
068:
069: if (alive) {
070: if (sendRequest() != 0) {
071: rwg.stopAll();
072: go = false;
073: }
074: alive = false;
075: } else {
076: if (checkRequest() != 0) {
077: // logger.info("KeepAlive: request expired!");
078: logger.info("PSSRNTLT_CSPNEPROX042");
079: rwg.stopAll();
080: go = false;
081: }
082: }
083: }
084: }
085:
086: public void stop() {
087: // System.out.println("stopping KeepAlive timer");
088: go = false;
089: src_to_dst.stop();
090: src_to_dst = null;
091: dst_to_src.stop();
092: dst_to_src = null;
093: }
094:
095: public int sendRequest() {
096: // System.out.println("KeepAlive: should send acm request! " + tname);
097: return (sa.authenticate(req));
098: }
099:
100: public int checkRequest() {
101: // System.out.println("KeepAlive: should send acm request! " + tname);
102: return (sa.authenticate(req));
103: }
104: }
|