You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2007/05/24 17:47:30 UTC
svn commit: r541337 - in /tomcat/trunk/java/org/apache/catalina/connector:
CometEventImpl.java CoyoteAdapter.java
Author: fhanik
Date: Thu May 24 08:47:29 2007
New Revision: 541337
URL: http://svn.apache.org/viewvc?view=rev&rev=541337
Log:
Add in support to check if the current thread is a Tomcat 'worker' thread or not, that way we can decide if the invokations are appropriate or not
Modified:
tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java
tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
Modified: tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java?view=diff&rev=541337&r1=541336&r2=541337
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CometEventImpl.java Thu May 24 08:47:29 2007
@@ -19,7 +19,7 @@
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;
@@ -29,7 +29,6 @@
public class CometEventImpl implements CometEvent {
-
/**
* The string manager for this package.
*/
@@ -69,7 +68,14 @@
*/
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
/**
@@ -136,7 +142,13 @@
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)
@@ -150,6 +162,25 @@
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 {
+
}
}
Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?view=diff&rev=541337&r1=541336&r2=541337
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Thu May 24 08:47:29 2007
@@ -119,7 +119,10 @@
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
@@ -198,6 +201,9 @@
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()) {
@@ -250,7 +256,7 @@
}
boolean comet = false;
-
+ CometEvent event = null;
try {
// Parse and set Catalina and configuration specific
@@ -261,6 +267,10 @@
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
@@ -291,6 +301,9 @@
} 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) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r541337 - in /tomcat/trunk/java/org/apache/catalina/connector:
CometEventImpl.java CoyoteAdapter.java
Posted by Remy Maucherat <re...@apache.org>.
Filip Hanik - Dev Lists wrote:
> I know you do, however, it's not expensive, it's not a lot of code, and
> it will avoid a lot of bugs and questions on the user list.
> Servlet programmers aren't really familiar with connection/poller
> mechanics, and we can't expect them to be either.
> so what we need to do is that the API is so straight forward and throws
> the correct exceptions if they invoke methods that would interfere with
> the underlying connection asynchronously.
It's exactly the same issue with adding syncs in some places in an
unsynced API, and pretend it's more robust. Some users will hack things
and run into horrible problems, but will complain (after looking into
the code) that place Y is not synced while place X was, and it's not
consistent :|
I will revisit this eventually, but it's not urgent at all.
Rémy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r541337 - in /tomcat/trunk/java/org/apache/catalina/connector:
CometEventImpl.java CoyoteAdapter.java
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
Remy Maucherat wrote:
> fhanik@apache.org wrote:
>> Author: fhanik
>> Date: Thu May 24 08:47:29 2007
>> New Revision: 541337
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=541337
>> Log:
>> Add in support to check if the current thread is a Tomcat 'worker'
>> thread or not, that way we can decide if the invokations are
>> appropriate or not
>
> I dislike this sort checks (mostly because of the ugly mechanics that
> goes along, obviously). I don't really see the point either.
I know you do, however, it's not expensive, it's not a lot of code, and
it will avoid a lot of bugs and questions on the user list.
Servlet programmers aren't really familiar with connection/poller
mechanics, and we can't expect them to be either.
so what we need to do is that the API is so straight forward and throws
the correct exceptions if they invoke methods that would interfere with
the underlying connection asynchronously.
Filip
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r541337 - in /tomcat/trunk/java/org/apache/catalina/connector:
CometEventImpl.java CoyoteAdapter.java
Posted by Remy Maucherat <re...@apache.org>.
fhanik@apache.org wrote:
> Author: fhanik
> Date: Thu May 24 08:47:29 2007
> New Revision: 541337
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=541337
> Log:
> Add in support to check if the current thread is a Tomcat 'worker' thread or not, that way we can decide if the invokations are appropriate or not
I dislike this sort checks (mostly because of the ugly mechanics that
goes along, obviously). I don't really see the point either.
Rémy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org