0

I would like to create prototpe using Atmosphere (1.0.12), but my current impelementation does not work with fallback transport.

Simple case scenario:
1. Client connects to server - server pushes current(full) state to that client
2. Server pushes changes in current state to all connected clients

This is a quite common scenario I think.

How i did that for websockets:

  1. When client connects (GET) I add resource to default broadcaster. This broadcaster is used to send data(changes) to all clients. In the same method I create another broadcaster, for this resource:
    Broadcaster privateBroadcaster = broadcasterFactory.lookup(DefaultBroadcaster.class, resource.uuid(), true);

  2. Client pushes data to server. POST method is invoked. This means: I'm a client and I want current full state. So server gets original resource UUID, find privateBroadcaster, and privateBroadcaster is used to push full state to that client.

  3. Server pushes data to all clients using default boradcaster. privateBroacaster is not used unless client wants full state again.

Problems:
This solution does not work for fallback transport if browser does not support websockets (ie IE9, IE 8). This solution does not work, becouse original resource in method POST is the same as current resource. So it is not possible to get private broadcaster and send full state to the client.

Questions:

  1. Does my solution has a chance to work with some modifications? If so, what should I change.
    If not
  2. How to make solution for this scenario?

I admit I'm currently lost, and need some help. If you need more details just ask. Thank you in advance.

--update
I decided to move part of code responsible for creating private broadcaster to POST method. This method is shown below. The part responsible for creating response is irrevelant thus is hidden. This still works fine for webscokets, does not work with fallback (long-polling) protocol. Initial state is not received by client, changes are received, but there is nothing to update.

@Context AtmosphereResource resource;
@Context BroadcasterFactory broadcasterFactory;

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public void sendCurrentState(Request request){

    logger.info("creating private broadcaster for uuid: " + resource.uuid());
    Broadcaster privateBroadcaster = broadcasterFactory.lookup(DefaultBroadcaster.class, resource.uuid(), true);
    privateBroadcaster.addAtmosphereResource(resource);
    //Prepare response (hidden)
    privateBroadcaster.broadcast(encodedJSON);
}

Hubert

Hubert
  • 1,125
  • 5
  • 17
  • 36

1 Answers1

0

The AtmosphereResource in the POST is not the same. The uuid is the same for long-polling and streaming, but you need to retrieve the suspended AtmosphereResource by using the AtmosphereResourceFactory.find(...).

Let's continue the discussion on the mailing list in case it doesn't work.

halfer
  • 19,824
  • 17
  • 99
  • 186
jfarcand
  • 1,705
  • 9
  • 6
  • Hello, I've updated my question. Please check it if you can. I also must say that I asked for help on the mailing group, but without success. – Hubert May 08 '13 at 00:59