From 5df17b812037f221ea18449e8ff52675406abe0b Mon Sep 17 00:00:00 2001 From: fhanik Date: Wed, 13 Jun 2007 18:51:38 +0000 Subject: [PATCH] simplify API a bit based on feedback git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@546999 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/CometEvent.java | 30 +++++----------------- .../apache/catalina/connector/CometEventImpl.java | 22 ++++++++-------- java/org/apache/coyote/ActionCode.java | 2 +- .../apache/coyote/http11/Http11NioProcessor.java | 4 ++- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/java/org/apache/catalina/CometEvent.java b/java/org/apache/catalina/CometEvent.java index 2d180a87a..520d3b67e 100644 --- a/java/org/apache/catalina/CometEvent.java +++ b/java/org/apache/catalina/CometEvent.java @@ -163,44 +163,28 @@ public interface CometEvent { public void setTimeout(int timeout) throws ServletException, UnsupportedOperationException; - - - /** - * Enumeration for a comet connection state. - * A comet session can be blocking or non blocking. - * COMET_NON_BLOCKING
- * Option bit set for allowing non blocking IO - * when reading from the request or writing to the response
- * COMET_BLOCKING
- * Configure the comet connection for blocking IO, this is the default setting - * - * @see #configure(int) - */ - public enum CometConfiguration {COMET_BLOCKING, COMET_NON_BLOCKING}; - + /** * Configures the connection for desired IO options. * By default a Comet connection is configured for
* a) Blocking IO - standard servlet usage
* b) Register for READ events when data arrives
* Tomcat Comet allows you to configure for additional options:
- * the COMET_NON_BLOCKING bit signals whether writing and reading from the request + * the configureBlocking(false) bit signals whether writing and reading from the request * or writing to the response will be non blocking.
- * the COMET_BLOCKING bit signals the container you wish for read and write to be done in a blocking fashion - * @param cometOptions int - the option bit set + * the configureBlocking(true) bit signals the container you wish for read and write to be done in a blocking fashion + * @param blocking - true to make read and writes blocking * @throws IllegalStateException - if this method is invoked outside of the BEGIN event - * @see #CometConfiguration * @see #isReadable() * @see #isWriteable() */ - public void configure(CometConfiguration... options) throws IllegalStateException; + public void configureBlocking(boolean blocking) throws IllegalStateException; /** * Returns the configuration for this Comet connection - * @return CometConfiguration[] - * @see #configure(CometConfiguration...) + * @return true if the connection is configured to be blocking, false for non blocing */ - public CometConfiguration[] getConfiguration(); + public boolean isBlocking(); /** * OP_CALLBACK - receive a CALLBACK event from the container diff --git a/java/org/apache/catalina/connector/CometEventImpl.java b/java/org/apache/catalina/connector/CometEventImpl.java index ea279d54f..89339ab8e 100644 --- a/java/org/apache/catalina/connector/CometEventImpl.java +++ b/java/org/apache/catalina/connector/CometEventImpl.java @@ -29,6 +29,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 org.apache.tomcat.util.MutableBoolean; public class CometEventImpl implements CometEvent { @@ -79,9 +80,9 @@ public class CometEventImpl implements CometEvent { protected HashSet cometOperations = new HashSet(3); /** - * Current set of configurations + * Blocking or not blocking */ - protected HashSet cometConfigurations = new HashSet(3); + protected boolean blocking = true; protected WorkerThreadCheck threadCheck = new WorkerThreadCheck(); @@ -95,7 +96,7 @@ public class CometEventImpl implements CometEvent { public void clear() { request = null; response = null; - cometConfigurations.clear(); + blocking = true; cometOperations.clear(); } @@ -151,13 +152,12 @@ public class CometEventImpl implements CometEvent { return cometOperations.contains(op); } - public void configure(CometEvent.CometConfiguration... options) throws IllegalStateException { + public void configureBlocking(boolean blocking) throws IllegalStateException { checkWorkerThread(); - cometConfigurations.clear(); - for (CometEvent.CometConfiguration cc : options) { - cometConfigurations.add(cc); - } - request.action(ActionCode.ACTION_COMET_CONFIGURE,options); + if ( getEventType() != EventType.BEGIN ) throw new IllegalStateException("Can only be configured during the BEGIN event."); + MutableBoolean bool = new MutableBoolean(blocking); + request.action(ActionCode.ACTION_COMET_CONFIGURE_BLOCKING,bool); + this.blocking = bool.get(); } public void register(CometEvent.CometOperation... operations) throws IllegalStateException { @@ -172,8 +172,8 @@ public class CometEventImpl implements CometEvent { request.action(ActionCode.ACTION_COMET_REGISTER, translate(cometOperations.toArray(new CometOperation[0]))); } - public CometConfiguration[] getConfiguration() { - return (CometConfiguration[])cometConfigurations.toArray(new CometConfiguration[0]); + public boolean isBlocking() { + return blocking; } public CometOperation[] getRegisteredOps() { diff --git a/java/org/apache/coyote/ActionCode.java b/java/org/apache/coyote/ActionCode.java index d46f8ad55..3f809bcd3 100644 --- a/java/org/apache/coyote/ActionCode.java +++ b/java/org/apache/coyote/ActionCode.java @@ -159,7 +159,7 @@ public final class ActionCode { /** * Configure a Comet connection */ - public static final ActionCode ACTION_COMET_CONFIGURE = new ActionCode(25); + public static final ActionCode ACTION_COMET_CONFIGURE_BLOCKING = new ActionCode(25); /** * Register notifications for events for a certain comet connection diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index a503e7403..351dcb0ef 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -1227,7 +1227,9 @@ public class Http11NioProcessor implements ActionHook { RequestInfo rp = request.getRequestProcessor(); if ( rp.getStage() != org.apache.coyote.Constants.STAGE_SERVICE ) socket.getPoller().cometInterest(socket); - } else if (actionCode == ActionCode.ACTION_COMET_CONFIGURE) { + } else if (actionCode == ActionCode.ACTION_COMET_CONFIGURE_BLOCKING) { + MutableBoolean bool = (MutableBoolean)param; + if ( bool.get() ) throw new IllegalStateException("Not yet implemented"); } else if (actionCode == ActionCode.ACTION_COMET_READABLE) { MutableBoolean bool = (MutableBoolean)param; try { -- 2.11.0