Forum Stats

  • 3,838,749 Users
  • 2,262,397 Discussions
  • 7,900,750 Comments

Discussions

EventSource reconnect timeout (Jax-RS)

Kronos72it
Kronos72it Member Posts: 119
edited Sep 2, 2015 6:20AM in Java Technology & XML

Hello I am discovering Jax-Rs through Jersey 2.20 .

If I understood the javascript EventSource object behave as (default) after 3 second of disconnection it try to re connect .

From my point of view it is a strange behavior because reconnection must take place just when the first connection is lost but in my case EventSource try to reconnect after Jax-Rs endpoint do :

// on server

eventOutput.close();

Then EventSource figure there is disconnection about problem but it is just a closing of streming.

No error on client :

//on client

        czmlEventSource.onError = function(e) {

            e = e || event, msg = '';

            switch( e.target.readyState ){

                // if reconnecting

                case EventSource.CONNECTING:

                    msg = 'Reconnecting…';

                    break;

                // if error was fatal

                case EventSource.CLOSED:

                    msg = 'Connection failed. Will not retry.';

                    break;

            }

            console.error("XXX "+msg);

        }

If it is true , I need to avoid this behavior otherwise every subsequent reconnection download data from beginning .

please, help !

No effect if I leveraging Jersey to disabling reconnection :

final OutboundEvent.Builder eventBuilder= new OutboundEvent.Builder();

        eventBuilder.name("czml").reconnectDelay(-1);

        eventBuilder.data(JsonObject.class,v).mediaType(MediaType.APPLICATION_JSON_TYPE);

        final OutboundEvent event = eventBuilder.build();

        e.write(event); 

Message was edited by: kronos72it to insert a statement about eventBuilder.name("czml").reconnectDelay(-1);

This discussion has been closed.