From: fhanik Date: Mon, 28 May 2007 11:39:15 +0000 (+0000) Subject: Implement setTimeout using an Action instead of an attribute X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=d0d3a9199a4123f979763cdbc4969caefd58c4cc;p=tomcat7.0 Implement setTimeout using an Action instead of an attribute git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@542208 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/connector/CometEventImpl.java b/java/org/apache/catalina/connector/CometEventImpl.java index 9a1c4a9cb..9828afde5 100644 --- a/java/org/apache/catalina/connector/CometEventImpl.java +++ b/java/org/apache/catalina/connector/CometEventImpl.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletResponse; import org.apache.catalina.CometEvent; import org.apache.catalina.util.StringManager; +import org.apache.coyote.ActionCode; public class CometEventImpl implements CometEvent { @@ -121,7 +122,10 @@ public class CometEventImpl implements CometEvent { public void setTimeout(int timeout) throws IOException, ServletException, UnsupportedOperationException { if (request.getAttribute("org.apache.tomcat.comet.timeout.support") == Boolean.TRUE) { - request.setAttribute("org.apache.tomcat.comet.timeout", new Integer(timeout)); + checkWorkerThread(); + Integer to = new Integer(timeout); + request.action(ActionCode.ACTION_COMET_TIMEOUT,to); + //request.setAttribute("org.apache.tomcat.comet.timeout", to); } else { throw new UnsupportedOperationException(); } @@ -137,6 +141,10 @@ public class CometEventImpl implements CometEvent { public void configure(CometEvent.CometConfiguration... options) throws IOException, IllegalStateException { + checkWorkerThread(); + if (getEventType()!=EventType.BEGIN) { + throw new IllegalStateException("Configure can only be called during the BEGIN event."); + } throw new UnsupportedOperationException(); } @@ -164,6 +172,16 @@ public class CometEventImpl implements CometEvent { throw new UnsupportedOperationException(); } + public String toString() { + StringBuffer buf = new StringBuffer("CometEventImpl["); + buf.append(super.toString()); + buf.append("] Event:"); + buf.append(getEventType()); + buf.append(" SubType:"); + buf.append(getEventSubType()); + return buf.toString(); + } + protected void setWorkerThread() { threadCheck.set(threadCheckHolder); } diff --git a/java/org/apache/catalina/connector/CoyoteAdapter.java b/java/org/apache/catalina/connector/CoyoteAdapter.java index 594683b3e..537792776 100644 --- a/java/org/apache/catalina/connector/CoyoteAdapter.java +++ b/java/org/apache/catalina/connector/CoyoteAdapter.java @@ -263,13 +263,14 @@ public class CoyoteAdapter // request parameters req.getRequestProcessor().setWorkerThreadName(Thread.currentThread().getName()); if (postParseRequest(req, request, res, response)) { + event = request.getEvent(); + if ( event!=null && (event instanceof CometEventImpl)) + ((CometEventImpl)event).setWorkerThread(); + // Calling the container connector.getContainer().getPipeline().getFirst().invoke(request, response); if (request.isComet()) { - event = request.getEvent(); - if ( event!=null && (event instanceof CometEventImpl)) - ((CometEventImpl)event).setWorkerThread(); if (!response.isClosed() && !response.isError()) { if (request.getAvailable()) { diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java index 80709c353..e05ebdf22 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -2259,6 +2259,9 @@ public class Request // ------------------------------------------------------ Protected Methods + protected void action(ActionCode actionCode, Object param) { + coyoteRequest.action(actionCode,param); + } protected Session doGetSession(boolean create) { diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index d5e281112..f8c3c223a 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -1218,6 +1218,14 @@ public class Http11NioProcessor implements ActionHook { request.setAvailable(inputBuffer.available()); } else if (actionCode == ActionCode.ACTION_COMET_BEGIN) { comet = true; + } else if (actionCode == ActionCode.ACTION_COMET_TIMEOUT) { + if ( socket == null ) + throw new IllegalStateException("Connection must be in Comet state to set the timeout"); + NioEndpoint.KeyAttachment attach = (NioEndpoint.KeyAttachment)socket.getAttachment(false); + if ( param == null || (!(param instanceof Integer)) ) + throw new IllegalArgumentException("Action parameter must be an Integer object to set the timeout"); + Integer to = (Integer)param; + attach.setTimeout(to.longValue()); } else if (actionCode == ActionCode.ACTION_COMET_END) { comet = false; } diff --git a/java/org/apache/coyote/http11/Http11NioProtocol.java b/java/org/apache/coyote/http11/Http11NioProtocol.java index f8f4f9555..defcaa418 100644 --- a/java/org/apache/coyote/http11/Http11NioProtocol.java +++ b/java/org/apache/coyote/http11/Http11NioProtocol.java @@ -661,6 +661,7 @@ public class Http11NioProtocol implements ProtocolHandler, MBeanRegistration } } else { if (log.isDebugEnabled()) log.debug("Keeping processor["+result); + //add correct poller events here based on Comet stuff socket.getPoller().add(socket); } }