3 Replies Latest reply on Jan 25, 2013 10:48 AM by jfuerth

    Continous heart beat requests after startup

      Hi all

       

      We are using Errai 2.0.2 to have server push in our application. I am observing that when we open the application in the web browser we are seing XHR requests(heart beats) continously. These requests start even before our code invokes any class of Errai.

       

      I just looked at the Errai source. It is having its own EntryPoint and it initiates heartbeat requests at application start up. The code comment in the class ClientMessageBusImpl says that heart beat is initiated at start up to avoid multiple HTTP sessions being created. I am not clear with this. Is there any way I can delay this heart beat until any errai class is used.

       

      Thanks,

      Ganesh

        • 1. Re: Continous heart beat requests after startup
          jfuerth

          Hi Ganesh,

           

          Thanks for your question!

           

          Right off the top, I recommend you update to 2.2.0.CR2, our latest release. There have been a lot of bug fixes since 2.0.2.Final. Further, the rest of the advice in this response refers to new APIs that were introduced after 2.0.2.

           

          Errai no longer uses actual heartbeat messages, but as you've observed, it does commence long-polling the server as soon as the page loads.

           

          If you don't want Errai to communicate with the server at all, you can set a javascript variable in the page header. See https://docs.jboss.org/author/display/ERRAI/Client+Configuration for details.

           

          If you instead want Errai to defer its handshake with the server until some time specified by the application, you can use the new bus lifecycle API. You can call stop() on the ClientMessageBus to tell it not to connect back to the server. If you do this early enough in the app lifecycle, you might be able to prevent even the initial handshake request. When you do want the bus to connect to the server, call ClientMessageBus.init(). Of course, stop() and init() act asynchronously. You can monitor the connection status using a BusLifecycleListener.

           

          -Jonathan

          1 of 1 people found this helpful
          • 2. Re: Continous heart beat requests after startup

            Thanks Jonathan for you reply.

             

            I have some questions:

             

            If you instead want Errai to defer its handshake with the server until some time specified by the application, you can use the new bus lifecycle API.

             

            Is this new API available in 2.0.2?

             

            You can call stop() on the ClientMessageBus to tell it not to connect back to the server. If you do this early enough in the app lifecycle, you might be able to prevent even the initial handshake request.

            Does this mean that even if I call stop(), there is still a chance that handshake requests are sent? What is the guaranteed way to stop the initial handshake?

             

            Thanks,

            Ganesh

            • 3. Re: Continous heart beat requests after startup
              jfuerth

              Hi Ganesh,

               

              No, none of the features mentioned in my reply existed yet in 2.0.2. I recommend you update to 2.2.0.CR2, our latest release. There have been a lot of bug fixes since 2.0.2.Final. Further, the rest of the advice in this response refers to new APIs that were introduced after 2.0.2.

               

               


              You can call stop() on the ClientMessageBus to tell it not to connect back to the server. If you do this early enough in the app lifecycle, you might be able to prevent even the initial handshake request.

              Does this mean that even if I call stop(), there is still a chance that handshake requests are sent? What is the guaranteed way to stop the initial handshake?

              If this is important to you (I'm interested in your use case--why is it critical that no AJAX request is made when the page loads?) then you would need to combine both approaches.

               

              First, set window.erraiBusRemoteCommunicationEnabled = false in a <script> tag in the page header. This guarantees the bus will not attempt any AJAX requests.

               

              Then, when you are ready to begin server communication, set window.erraiBusRemoteCommunicationEnabled = true (you will need to use JSNI for this; there's no GWT API in Errai for setting the variable) and then call bus.init().

               

              Note that we are not aware of anyone else who has attempted to do this before. You may run into edge cases where it doesn't work. Please let us know if you needed to apply any additional workarounds not listed here!

               

              -Jonathan