private void lazyConnect() {
   if (terminalConnection == null) {
     TerminalConnectionFactory terminalConnectionFactory =
         applicationContext.getBean(TerminalConnectionFactory.class);
     ConnectionPropertiesProvider connectionPropertiesProvider =
         applicationContext.getBean(ConnectionPropertiesProvider.class);
     ConnectionProperties connectionProperties =
         connectionPropertiesProvider.getConnectionProperties();
     terminalConnection = terminalConnectionFactory.getConnection(connectionProperties);
     logger.info("Opened new session");
   }
   if (!isConnected()) {
     terminalConnection = null;
     throw (new SessionEndedException("Session is not connected"));
   }
 }
  public void disconnect() {
    logger.info("Disconnecting session");

    if (terminalConnection == null) {
      logger.debug("Session not connected");
      return;
    }
    TerminalConnectionFactory terminalConnectionFactory =
        applicationContext.getBean(TerminalConnectionFactory.class);
    try {
      terminalConnectionFactory.disconnect(terminalConnection);
    } catch (Exception e) {
      logger.warn("Error disconnecting session", e);
    }
    terminalConnection = null;
    terminalSnapshot = null;
  }