jquery - Servlet 3.0 and Comet/long-polling: What happens during these specific scenarios? -


i took @ brief overview of servlet 3.0's implementation of server push here , left more questions came in with. questions related use case: implementing dynamic notification system amongst "friends", la facebook. conceptually thinking problem, approach so:

  1. put infinite jquery loop in each page, containing code issue xmlhttprequest "get" request server
  2. allow server store request/response objects related these type of xmlhttprequests in application-scoped map (with of asynccontext , .startasync()), keyed user's website id
  3. whenever user engages in action spawns notification, query application-scoped map ids of user's friends, , using response objects stored there, send notification each friend.
  4. each of friends receive notification, , infinite loop on pages they're on issue xmlhttprequests again (due infinite loop)

assuming system conceptually sound (and if isn't, please tell me what's wrong), there couple of issues see system:

  1. what happens request/response pair in map after response used? supposed manually delete map, or wait loop on client side send request stored request/response object pair can replaced pair associated new xmlhttprequest? link above uses words "committed" , "uncommitted" in reference response objects. can explain words mean in context (i have feeling they're related longevity of response objects)?

  2. what happens if 2 or more of user's friends engage in actions cause notifications @ same time? there 1 request/response pair stored per user. whichever friend's action happens find user in question's request/response pair gets notification sent user, actions other friends? if happen @ same time, other actions won't have request/response pair use send notification until user sends xmlhttprequest stored in map. presumably other actions parse map , either find no entry user (because been manually deleted after other action used response), or find "stale" request/response object has been used. i'm assuming response object can't used 2 different responses, how go rectifying this?

  3. what happens if notification sent user when user switching pages? if view loaded web page open window receiving notification requests, , loading 1 closed window (because unable receive , process responses xmlhttprequests sent previous page), notifications sent during time frame lost. there can short of querying database new actions , generating notifications way on page load?

  4. finally, happen when user navigates away site , session expires? expected periodically iterate through map , delete requests associated no existing sessions?

sorry if long read. if can answer 1 of above questions help!

  1. the response kept until times out probably. keep pushing new info on over , on again. comet is. don't loop requests forever, handle data streaming server comes, 1 request last until times out, in complete function issue get.

  2. again, response still available, writing on it, not closing every time.

  3. one way timestamp notifications , load page data time, initial request provides timestamp , date.

  4. i assume again, hold until times out.

so better explain happening here,

  • your page loaded , sends request.
  • the request/response stored in map.
  • every update sent on same request/response pair.
  • your request listens readystate === 3 (data received) , reads data getting new has been sent.
  • when timeout/have sent amount of data/whatever removed.

Comments