Class HeartbeatBackground

  • All Implemented Interfaces:
    Runnable

    public class HeartbeatBackground
    extends Object
    implements Runnable
    This class is a singleton which is running inside driver to heartbeat snowflake server for each connection
    • Method Detail

      • addSession

        protected void addSession​(SFSession session,
                                  long masterTokenValidityInSecs,
                                  int heartbeatFrequencyInSecs)
        Method to add a session

        It will compare the master token validity and stored master token validity and if it is less, we will update the stored one and the heartbeat interval and reschedule heartbeat.

        This method is called when a session is created.

        Parameters:
        session - the session will be added
        masterTokenValidityInSecs - time interval for which client need to check validity of master token with server
      • removeSession

        protected void removeSession​(SFBaseSession session)
        Method to remove a session. This is called when a session is closed. Notice that if a session is not closed but the session object goes out of scope, then this method will not be called. And then the session will be kept in the list of sessions to be heartbeated until the object gets garbage collected since we use weak reference to the object.
        Parameters:
        session - the session will be removed
      • run

        public void run()
        Run heartbeat: for each session send a heartbeat request and schedule next heartbeat as long as there are sessions left.

        Notice that the synchronization is only around the code that visits the global sessions map and the code that schedules next heartbeat, but not around the heartbeat calls for each session in order to minimize the chance of blocking the adding of a session by performing the heartbeats. This is because adding a session is called from JDBC connection creation call which directly affects application performance.

        Specified by:
        run in interface Runnable