@Override
 public void run() {
   log.trace("started");
   Session session = sessionFactory.withOptions().tenantIdentifier(tenantId).openSession();
   session.setFlushMode(FlushMode.MANUAL);
   session.setCacheMode(cacheMode);
   session.setDefaultReadOnly(true);
   try {
     loadAllFromQueue(session);
   } catch (Exception exception) {
     errorHandler.handleException(log.massIndexerExceptionWhileTransformingIds(), exception);
   } finally {
     producerEndSignal.countDown();
     session.close();
   }
   log.trace("finished");
 }
  private void indexAllQueue(
      Session session, List<?> entities, InstanceInitializer sessionInitializer)
      throws InterruptedException {
    ConversionContext contextualBridge = new ContextualExceptionBridgeHelper();

    if (entities == null || entities.isEmpty()) {
      return;
    } else {
      log.tracef("received a list of objects to index: %s", entities);
      for (Object object : entities) {
        try {
          index(object, session, sessionInitializer, contextualBridge);
          monitor.documentsBuilt(1);
        } catch (RuntimeException e) {
          String errorMsg =
              log.massIndexerUnableToIndexInstance(object.getClass().getName(), object.toString());
          errorHandler.handleException(errorMsg, e);
        }
      }
    }
  }