سؤال

I need to store some serverside values against a suspended request and I'm not sure how I should go about it. I'd like the attributes to be cleaned up when the suspended connection is no longer live on the client. I expected AtmosphereResource to have setAttribute(name,value) and getAttribute(name) methods but they don't exist. I've thought of three possible approaches:

  1. Use AtmosphereResource.getRequest().setAttribute(name,value)
  2. Provide my own AtmosphereResource implementation and add the methods there (backed by a concurrent map).
  3. Have some form of listener / interceptor that listens for create / destroy of AtmosphereResource and maintain my own serverside state using AtmosphereResource.uuid().

Questions:

  1. Are there any issues with using the request attributes of the suspended request? Will this work for all transport methods?
  2. Are there any examples of providing a custom AtmosphereResource implementation?
  3. If I provide my own AtmosphereResource implementation, will it live for the lifetime of the suspended request? Will this work for all transport methods (eg long-polling)?
  4. Is there a hook to get events for create / destroy? I've looked at AtmosphereInterceptor but can only see inspect and postInspect events.
  5. Is there a better solution to my problem?
هل كانت مفيدة؟

المحلول

I ended up solving my problem with a AtmosphereResourceEventListener which creates and destroys a session per AtmosphereResource.

I'm surprised that other people haven't had this problem, it seems like a pretty normal requirement to want a session per client connection.

If anyone is interested in my solution, some interesting classes are:

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top