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/10 13:30:29 UTC
svn commit: r536830 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina:
CometEvent.java connector/CometEventImpl.java
Author: fhanik
Date: Thu May 10 04:30:29 2007
New Revision: 536830
URL: http://svn.apache.org/viewvc?view=rev&rev=536830
Log:
New proposed API calls for Comet
Modified:
tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometEvent.java
tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometEvent.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometEvent.java?view=diff&rev=536830&r1=536829&r2=536830
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometEvent.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/CometEvent.java Thu May 10 04:30:29 2007
@@ -66,8 +66,11 @@
* been initialized in the begin method should be reset. After this event has
* been processed, the request and response objects, as well as all their dependent
* objects will be recycled and used to process other requests.
+ * NOTIFY - An event that the CometProcessor registered for has occurred.
+ * The notify event will only be thrown if CometEvent.register has been
+ * invoked and the CometProcessor has registered itself to receive certain notification
*/
- public enum EventType {BEGIN, READ, END, ERROR}
+ public enum EventType {BEGIN, READ, END, ERROR, NOTIFY}
/**
@@ -79,6 +82,8 @@
* WEBAPP_RELOAD - the webapplication is being reloaded (sub type of END)
* SERVER_SHUTDOWN - the server is shutting down (sub type of END)
* SESSION_END - the servlet ended the session (sub type of END)
+ * NOW - instant notification from the container (sub type of NOTIFY)
+ * WRITE - notification that
*/
public enum EventSubType { TIMEOUT, CLIENT_DISCONNECT, IOEXCEPTION, WEBAPP_RELOAD, SERVER_SHUTDOWN, SESSION_END }
@@ -101,6 +106,7 @@
* Returns the event type.
*
* @return EventType
+ * @see #EventType
*/
public EventType getEventType();
@@ -108,6 +114,7 @@
* Returns the sub type of this event.
*
* @return EventSubType
+ * @see #EventSubType
*/
public EventSubType getEventSubType();
@@ -143,5 +150,90 @@
*/
public void setTimeout(int timeout)
throws IOException, ServletException, UnsupportedOperationException;
+
+ /**
+ * Option bit set for allowing non blocking IO
+ * when reading from the request or writing to the response
+ * @see #configure(int)
+ */
+ public static final int COMET_NON_BLOCKING = 0x0001;
+
+ /**
+ * Option bit set to not register for any IO events
+ * Connections can be reregistered for IO events using the
+ * #register(int) method.
+ * @see #configure(int)
+ * @see #register(int)
+ */
+ public static final int COMET_NO_IO = 0x0002;
+ /**
+ * Configures the connection for desired IO options.
+ * By default a Comet connection is configured for <br/>
+ * a) Blocking IO - standard servlet usage<br/>
+ * b) Register for READ events when data arrives<br/>
+ * Tomcat Comet allows you to configure for additional options:<br/>
+ * the <code>COMET_NON_BLOCKING</code> bit signals whether writing and reading from the request
+ * or writing to the response will be non blocking.<br/>
+ * the <code>COMET_NO_IO</code> bit signals the container that you are not interested in
+ * receiving any IO events from the container.
+ * @param cometOptions int - the option bit set, see #COMET_NON_BLOCKING and #COMET_NO_IO
+ * @throws IOException -
+ * @throws ServletException
+ * @throws IllegalStateException - if this method is invoked outside of the BEGIN event
+ */
+ public void configure(int cometOptions)
+ throws IOException, ServletException, IllegalStateException;
+
+ /**
+ * notification bit to receive an event
+ * immediately, the event will be NOTIFY/WRITE
+ * @see #register(int)
+ */
+ public static final int OP_NOW = 0x001;
+
+ /**
+ * notification bit to receive an event when
+ * data has arrived on the connection
+ * Event will be READ
+ * @see #register(int)
+ * @see CometProcessor#event(CometEvent)
+ */
+ public static final int OP_READ = 0x004;
+
+ /**
+ * notification bit to receive an event
+ * when the Comet connection is writable
+ * @see #register(int)
+ * @see #isWritable
+ * @see CometProcessor#event(CometEvent)
+ *
+ */
+ public static final int OP_WRITE = 0x004;
+
+ /**
+ * Registers the Comet connection with the container for notifications.
+ * These could be notifications
+ * @param notificationOptions int
+ * @throws IOException
+ * @throws ServletException
+ * @throws IllegalStateException - if you are trying to register with a socket that already is registered
+ * or if the operation you are trying to register is invalid.
+ */
+ public void register(int notificationOptions)
+ throws IOException, ServletException, IllegalStateException;
+
+ /**
+ * Returns true if the Comet connection is blocking or non blocking and you can write
+ * without blocking data to the response
+ * @return boolean - true if you can write to the response
+ */
+ public boolean isWriteable();
+
+ /**
+ * Returns true if the Comet connection is blocking or non blocking and data is available to be read
+ * @see javax.servlet.ServletRequest#getInputStream()#available()>0
+ * @return boolean
+ */
+ public boolean isReadable();
}
Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java?view=diff&rev=536830&r1=536829&r2=536830
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/connector/CometEventImpl.java Thu May 10 04:30:29 2007
@@ -120,5 +120,23 @@
throw new UnsupportedOperationException();
}
}
+
+ public boolean isReadable() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isWriteable() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void configure(int cometOptions)
+ throws IOException, ServletException, IllegalStateException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void register(int notificationOptions)
+ throws IOException, ServletException, IllegalStateException {
+ throw new UnsupportedOperationException();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r536830 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina:
CometEvent.java connector/CometEventImpl.java
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
Remy Maucherat wrote:
> fhanik@apache.org wrote:
>> Author: fhanik
>> Date: Thu May 10 04:30:29 2007
>> New Revision: 536830
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=536830
>> Log:
>> New proposed API calls for Comet
>> + /**
>> + * notification bit to receive an event
>> + * immediately, the event will be NOTIFY/WRITE
>> + * @see #register(int)
>> + */
>> + public static final int OP_NOW = 0x001;
>> + + /**
>> + * notification bit to receive an event when
>> + * data has arrived on the connection
>> + * Event will be READ
>> + * @see #register(int)
>> + * @see CometProcessor#event(CometEvent)
>> + */
>> + public static final int OP_READ = 0x004;
>
> Besides the cute boolean tricks that are soooo cool, I think an enum
> should be used.
No problem, enum with a vararg works just fine
>
>> + public void register(int notificationOptions)
>> + throws IOException, ServletException, IllegalStateException;
>
> The throws list for all these methods is a bit abusive. IOException,
> maybe it would be useful (but I will remove it if it's not), but
> ServletException ??
I agree, ServletException should go, IOException, I'd leave it in, ie,
you don't break the API if you remove it later, but you do break the API
if you have to add it later
>
> I am ok with proceeding based on that, but I'll likely ask for
> adjustment of some behaviors. For example, I am not convinced with the
> registration for read after each read event (it could maybe cause a
> leak like the one I fixed recently; I think it could be avoided, but
> this requires passing around flags, which is a bit annoying).
I hadn't planned that you need to re-register for a READ event.
Essentially, after an event processed in CometProcessor.event, the
registrations that you had before will stand.
>
> > there is one inconsistency,
> > currently READ is a main type, while WRITE is a subtype of NOTIFY
> > thoughts on consolidate these? ie NOTIFY/READ or make WRITE a main type
>
> If you think about NOTIFY as a name, then all events could be
> NOTIFY/something. Since this is not very practical, I would not be
> using a NOTIFY in the event type.
:) totally agree, any thoughts on READ vs WRITE, should WRITE be a main
type?
>
> Rémy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r536830 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina:
CometEvent.java connector/CometEventImpl.java
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
Remy Maucherat wrote:
> Filip Hanik - Dev Lists wrote:
>> it's more than just cool, its extremely practical.
>> If I only want to "unregister READ", all I have to do is
>> register(getRegisteredOps() & (~OP_READ))
>> with the enums, that are not as cool, I need a little piece of code
>> that singles it out.
>
> For sure, with enums, you definitely don't look as cool since you'd be
> writing unregister(OP_READ) :D
yes, you are right, I'll add that in
>
>> I'll leave the enum in there, but if you change your mind, I like the
>> "and/or" tricks, and be happy to stick them back in,
>> it's just not worth delaying the impl effort for
>
> I agree and/or tricks are cool. It feels like C, and I enjoy that in
> APR, but I think it's less appropriate in a Java API (where Sun
> demonstrated you have to think that objects are free, and GC does not
> exist :D ).
he he, I keep hearing that everywhere, and folks like to believe it, and
I thought that De-Nial was a river in Egypt
>
> BTW, I don't understand why you like NIO, those Java APIs are not fun ;)
I'm cornered cause I haven't done any C since college, and even then I
sucked at it :)
Filip
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r536830 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina:
CometEvent.java connector/CometEventImpl.java
Posted by Remy Maucherat <re...@apache.org>.
Filip Hanik - Dev Lists wrote:
> it's more than just cool, its extremely practical.
> If I only want to "unregister READ", all I have to do is
> register(getRegisteredOps() & (~OP_READ))
> with the enums, that are not as cool, I need a little piece of code that
> singles it out.
For sure, with enums, you definitely don't look as cool since you'd be
writing unregister(OP_READ) :D
> I'll leave the enum in there, but if you change your mind, I like the
> "and/or" tricks, and be happy to stick them back in,
> it's just not worth delaying the impl effort for
I agree and/or tricks are cool. It feels like C, and I enjoy that in
APR, but I think it's less appropriate in a Java API (where Sun
demonstrated you have to think that objects are free, and GC does not
exist :D ).
BTW, I don't understand why you like NIO, those Java APIs are not fun ;)
Rémy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r536830 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina:
CometEvent.java connector/CometEventImpl.java
Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
Remy Maucherat wrote:
> fhanik@apache.org wrote:
>> Author: fhanik
>> Date: Thu May 10 04:30:29 2007
>> New Revision: 536830
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=536830
>> Log:
>> New proposed API calls for Comet
>> + /**
>> + * notification bit to receive an event
>> + * immediately, the event will be NOTIFY/WRITE
>> + * @see #register(int)
>> + */
>> + public static final int OP_NOW = 0x001;
>> + + /**
>> + * notification bit to receive an event when
>> + * data has arrived on the connection
>> + * Event will be READ
>> + * @see #register(int)
>> + * @see CometProcessor#event(CometEvent)
>> + */
>> + public static final int OP_READ = 0x004;
>
> Besides the cute boolean tricks that are soooo cool, I think an enum
> should be used.
it's more than just cool, its extremely practical.
If I only want to "unregister READ", all I have to do is
register(getRegisteredOps() & (~OP_READ))
with the enums, that are not as cool, I need a little piece of code that
singles it out.
I'll leave the enum in there, but if you change your mind, I like the
"and/or" tricks, and be happy to stick them back in,
it's just not worth delaying the impl effort for
Filip
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r536830 - in /tomcat/tc6.0.x/trunk/java/org/apache/catalina:
CometEvent.java connector/CometEventImpl.java
Posted by Remy Maucherat <re...@apache.org>.
fhanik@apache.org wrote:
> Author: fhanik
> Date: Thu May 10 04:30:29 2007
> New Revision: 536830
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=536830
> Log:
> New proposed API calls for Comet
> + /**
> + * notification bit to receive an event
> + * immediately, the event will be NOTIFY/WRITE
> + * @see #register(int)
> + */
> + public static final int OP_NOW = 0x001;
> +
> + /**
> + * notification bit to receive an event when
> + * data has arrived on the connection
> + * Event will be READ
> + * @see #register(int)
> + * @see CometProcessor#event(CometEvent)
> + */
> + public static final int OP_READ = 0x004;
Besides the cute boolean tricks that are soooo cool, I think an enum
should be used.
> + public void register(int notificationOptions)
> + throws IOException, ServletException, IllegalStateException;
The throws list for all these methods is a bit abusive. IOException,
maybe it would be useful (but I will remove it if it's not), but
ServletException ??
I am ok with proceeding based on that, but I'll likely ask for
adjustment of some behaviors. For example, I am not convinced with the
registration for read after each read event (it could maybe cause a leak
like the one I fixed recently; I think it could be avoided, but this
requires passing around flags, which is a bit annoying).
> there is one inconsistency,
> currently READ is a main type, while WRITE is a subtype of NOTIFY
> thoughts on consolidate these? ie NOTIFY/READ or make WRITE a main type
If you think about NOTIFY as a name, then all events could be
NOTIFY/something. Since this is not very practical, I would not be using
a NOTIFY in the event type.
Rémy
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org