import org.apache.catalina.CometEvent;
import org.apache.catalina.util.StringManager;
+import org.apache.coyote.ActionCode;
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();
}
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();
}
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);
}
// 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()) {
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;
}