From 6701d8300c2f125afb93a4799de4ea3c0d89a470 Mon Sep 17 00:00:00 2001 From: fhanik Date: Thu, 31 May 2007 08:48:01 +0000 Subject: [PATCH] simplify register and poller interest for comet, all can be done in one call git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@543086 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/catalina/connector/CometEventImpl.java | 39 ++++++++++------------ .../apache/coyote/http11/Http11NioProcessor.java | 24 +++++++------ java/org/apache/tomcat/util/net/NioEndpoint.java | 15 +++++++-- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/java/org/apache/catalina/connector/CometEventImpl.java b/java/org/apache/catalina/connector/CometEventImpl.java index b0b68df00..728f054d1 100644 --- a/java/org/apache/catalina/connector/CometEventImpl.java +++ b/java/org/apache/catalina/connector/CometEventImpl.java @@ -28,6 +28,7 @@ import org.apache.catalina.CometEvent; import org.apache.catalina.util.StringManager; import org.apache.coyote.ActionCode; import org.apache.tomcat.util.net.PollerInterest; +import java.util.Arrays; public class CometEventImpl implements CometEvent { @@ -160,23 +161,15 @@ public class CometEventImpl implements CometEvent { public void register(CometEvent.CometOperation... operations) throws IOException, IllegalStateException { //add it to the registered set - for (CometEvent.CometOperation co : operations) { - if (!cometOperations.contains(co)) { - cometOperations.add(co); - request.action(ActionCode.ACTION_COMET_REGISTER, translate(co)); - } - } + cometOperations.addAll(Arrays.asList(operations)); + request.action(ActionCode.ACTION_COMET_REGISTER, translate(cometOperations.toArray(new CometOperation[0]))); } public void unregister(CometOperation... operations) throws IOException, IllegalStateException { //remove from the registered set - for (CometEvent.CometOperation co : operations) { - if (cometOperations.contains(co)) { - cometOperations.remove(co); - request.action(ActionCode.ACTION_COMET_UNREGISTER, translate(co)); - } - } + cometOperations.removeAll(Arrays.asList(operations)); + request.action(ActionCode.ACTION_COMET_UNREGISTER, translate(cometOperations.toArray(new CometOperation[0]))); } public CometConfiguration[] getConfiguration() { @@ -211,15 +204,19 @@ public class CometEventImpl implements CometEvent { throw new IllegalStateException("The operation can only be performed when invoked by a Tomcat worker thread."); } - protected PollerInterest translate(CometOperation op) { - if ( op == CometEvent.CometOperation.OP_READ ) - return PollerInterest.READ; - else if ( op == CometEvent.CometOperation.OP_WRITE ) - return PollerInterest.WRITE; - else if ( op == CometEvent.CometOperation.OP_CALLBACK ) - return PollerInterest.CALLBACK; - else - throw new IllegalArgumentException(op!=null?op.toString():"null"); + protected PollerInterest[] translate(CometOperation... op) { + PollerInterest[] result = new PollerInterest[op.length]; + for (int i=0; i