package org.apache.catalina.connector;
import java.io.IOException;
-
+import java.util.HashSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CometEventImpl implements CometEvent {
-
/**
* The string manager for this package.
*/
*/
protected EventSubType eventSubType = null;
+ /**
+ * Current set of operations
+ */
+ protected HashSet<CometOperation> cometOperations = new HashSet<CometOperation>(3);
+
+ protected WorkerThreadCheck threadCheck = new WorkerThreadCheck();
+ private static final Object threadCheckHolder = new Object();
// --------------------------------------------------------- Public Methods
/**
public void register(CometEvent.CometOperation... operations)
throws IOException, IllegalStateException {
- throw new UnsupportedOperationException();
+ //add it to the registered set
+ for (CometEvent.CometOperation co : operations ) {
+ if ( !cometOperations.contains(co) ) {
+ cometOperations.add(co);
+ //TODO notify poller
+ }
+ }
}
public void unregister(CometOperation... operations)
public CometOperation[] getRegisteredOps() {
throw new UnsupportedOperationException();
}
+
+ protected void setWorkerThread() {
+ threadCheck.set(threadCheckHolder);
+ }
+
+ protected void unsetWorkerThread() {
+ threadCheck.set(null);
+ }
+
+ protected void checkWorkerThread() throws IllegalStateException {
+ //throw exception if not on worker thread
+ if ( !(threadCheck.get() == threadCheckHolder) )
+ throw new IllegalStateException("The operation can only be performed when invoked by a Tomcat worker thread.");
+ }
+
+ //inner class used to keep track if the current thread is a worker thread.
+ private static class WorkerThreadCheck extends ThreadLocal {
+
+ }
}
boolean error = false;
boolean read = false;
+ CometEvent event = request.getEvent();
try {
+ if ( event!=null && (event instanceof CometEventImpl))
+ ((CometEventImpl)event).setWorkerThread();
if (status == SocketStatus.OPEN) {
if (response.isClosed()) {
// The event has been closed asynchronously, so call end instead of
error = true;
return false;
} finally {
+ if ( event!=null && (event instanceof CometEventImpl))
+ ((CometEventImpl)event).unsetWorkerThread();
+
req.getRequestProcessor().setWorkerThreadName(null);
// Recycle the wrapper request and response
if (error || response.isClosed() || !request.isComet()) {
}
boolean comet = false;
-
+ CometEvent event = null;
try {
// Parse and set Catalina and configuration specific
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()) {
// Invoke a read event right away if there are available bytes
} catch (Throwable t) {
log.error(sm.getString("coyoteAdapter.service"), t);
} finally {
+ if ( event!=null && (event instanceof CometEventImpl))
+ ((CometEventImpl)event).unsetWorkerThread();
+
req.getRequestProcessor().setWorkerThreadName(null);
// Recycle the wrapper request and response
if (!comet) {