Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. both intend to implement an event based model
  2. sandbox API has events as implicit subscriptions
  3. trunk API has explicits subscriptions, one must subscribe/unsubscribe for each event type
  4. both APIs have the intention of implementing non blocking read and writes
  5. the trunk API intends to allow both non blocking and blocking read/writes, but not both nor mixed for a connection
  6. both APIs will have the non blocking implementation utilize the existing servlet/stream/reader/writer APIs, which will make the initial understanding of the APIs somewhat difficult, as the servlet/stream/reader/writer APIs are originally written for blocking APIs.
  7. both APIs - A non blocking write will throw an IOException if a previous write has been done but not yet completed, this is as write has a void return signature, and it is impossible to return 0.
  8. both APIs - A non blocking read will return 0, if no data exists.
  9. both APIs will have helper methods isWriteable and isReadable to help with the state of the connection
  10. both APIs will have the ability to suspend any future events, trunk by unregistering current subscriptions, sandbox by calling sleep() (or suggested suspend())

Remember, the API's have a fairly similar idea of what the underlying implementation will look like, the main difference is probably the implicit vs explicit event subscription, here are some examples

Example of implicit vs explicit write subscriptions and non blocking write error

Implicit

No Format

if ( event.isWriteable() ) { //implicit registration of a one time the WRITE event
  event.getHttpServletResponse().getOutputStream().write(data); //non blocking write
}

Explicit

No Format

if ( event.isWriteable() ) { 
  event.getHttpServletResponse().getOutputStream().write(data); //non blocking write
  event.register(OP_WRITE); //explicit registration for the WRITE event
}

Inaccurate use of non blocking write API

No Format

if ( event.isWriteable() ) { 
  event.getHttpServletResponse().getOutputStream().write(data); //non blocking write
  event.getHttpServletResponse().getOutputStream().write(data); //will throw an IOException, if previous write wasn't complete
}

Example of implicit vs explicit read unsubscribe/subscribe

Implicit

No Format


[Thread T1] event.sleep(); //unsubscribe from READ events
...
[Thread T2] event.callback(); //results in a CALLBACK event on Thread Tx, and also implicitly subscribes to READ events 

Explicit

No Format


[Thread T1] event.unregister(event.getRegisteredOps()); //unsubscribe from ALL events OR, see next line
[Thread T1] event.unregister(OP_READ); //unsubscribe from READ events
...
[Thread T2] event.register(OP_CALLBACK); //results in a CALLBACK event on Thread Tx, OR, to subscribe to READ events
[Thread T2] event.register(OP_READ); //results in a READ event when more data arrives


xxx

Display

xxx