001: package com.sun.portal.rproxy.server;
002:
003: import java.io.IOException;
004: import java.net.Socket;
005: import java.util.logging.Level;
006: import java.util.logging.Logger;
007:
008: import com.sun.portal.log.common.PortalLogger;
009: import com.sun.portal.rproxy.configservlet.client.GatewayProfile;
010: import com.sun.portal.rproxy.connectionhandler.HTTPSession;
011: import com.sun.portal.rproxy.connectionhandler.Session;
012: import com.sun.portal.rproxy.monitoring.MonitoringSubsystem;
013: import com.sun.portal.rproxy.monitoring.util.RProxyEvent;
014: import com.sun.portal.util.GWThreadPool;
015: import com.sun.portal.netlet.econnection.GWRunnable;
016:
017: public class RequestProcessor {
018:
019: private static final String TIMEOUT = "RProxyPortTimeout";
020:
021: private static final int DEFAULT_TIMEOUT = 1000 * 60;
022:
023: private final String protocol;
024:
025: private final int port;
026:
027: private static final int timeout = GatewayProfile.getInt(TIMEOUT,
028: DEFAULT_TIMEOUT) * 1000;
029:
030: private static Logger logger = PortalLogger
031: .getLogger(RequestProcessor.class);
032:
033: public RequestProcessor(String protocol, int port) {
034: this .protocol = protocol;
035: this .port = port;
036: }
037:
038: public void processRequestInGWTheadPool(final Socket socket,
039: Integer logId) {
040: this .processRequestInGWTheadPool(socket, logId, null);
041: }
042:
043: public void processRequestInGWTheadPool(final Socket socket,
044: Integer logId, final String ipAddr) {
045: Session session = null;
046:
047: try {
048: socket.setSoTimeout(timeout);
049: session = new HTTPSession(socket, ipAddr, protocol, port);
050:
051: final Session tempSession = session;
052: Runnable r = new GWRunnable() {
053:
054: private Session session = tempSession;
055:
056: public void run() {
057: boolean processStarted = false;
058: try {
059: while ((session != null)
060: && session.isStillActive()) {
061: processStarted = true;
062: session.processNextRequest();
063: processStarted = false;
064: MonitoringSubsystem
065: .handleEvent(RProxyEvent.TASK_ENDS);
066: }
067: } finally {
068: if (processStarted) {//Abnormal Exit
069: MonitoringSubsystem
070: .handleEvent(RProxyEvent.TASK_ENDS);
071: }
072: if (session != null) {
073: session.close();
074: session = null;
075: try {
076: socket.close();
077: } catch (IOException ee) {
078: }
079: }
080: }
081: }
082:
083: public String getType() {
084: return REQ_PROCESSOR;
085: }
086: };
087: GWThreadPool.run(r);
088: } catch (Exception e) {
089: // logger.log(Level.SEVERE, "RProxy caught exception", e);
090: logger.log(Level.SEVERE, "PSSRRPROXY_CSPRS000");
091: if (session != null) {
092: session.close();
093: }
094: if (socket != null) {
095: try {
096: socket.close();
097: } catch (IOException ex) {
098: }
099: }
100:
101: session = null;
102: }
103: }
104:
105: }
|