code: public ClientSessionState setState(Session.State state) {
      if (state != Session.State.UNSTABLE) {
        if (this.state != state) {
          return setStateAndCallListeners(state);
        }
      } else {
        if (this.state == Session.State.UNSTABLE) {
          if (unstabilityTimeout > 0 && (System.currentTimeMillis() - unstableSince) > unstabilityTimeout) {
            return setStateAndCallListeners(Session.State.STALE);
          }
        } else if (this.state != Session.State.STALE) {
          unstableSince = System.currentTimeMillis();
          return setStateAndCallListeners(state);
        }
      }
  
      return this;
    }
docs: Sets the session state.
  
  @param state The session state.
  @return The session state.