Class ImportEntryProcessor.ImportEntryProcessRunnable

  • All Implemented Interfaces:
    Runnable
    Direct Known Subclasses:
    NonBlockingImportEntryProcessRunnable, VariantChDescUpdateProcessor.VariantChDescUpdateRunnable
    Enclosing class:
    ImportEntryProcessor

    public abstract static class ImportEntryProcessor.ImportEntryProcessRunnable
    extends Object
    implements Runnable
    The default implementation of the ImportEntryProcessRunnable. It performs the following actions:
    • able to get new ImportEntry records while the processing of other ImportEntry records happens.
    • processes the ImportEntry, creates a new OBContext based on the user data of the ImportEntry
    • makes sure that there is a VariablesSecureApp in the RequestContext.
    • OBContexts are temporary cached in a WeakHashMap
    • the process checks the ImportEntry status just before it is processed, it also prevents the same ImportEntry to be processed twice by one thread
    • each ImportEntry is processed in its own connection and transaction. Note that the class delegates into the implementing subclass the ability of handling the commit/rollback of the transaction. But in order to prevent possible connection leaks, this class closes all the opened connections (if any) before ending.
    • the process sets admin mode, before calling the subclass
    • an error which ends up in the main loop here is stored in the ImportEntry in the errorInfo property
    • subclasses implement the processEntry(ImportEntry) method.
    ImportEntryProcessRunnables are linked to a ImportEntryManager's execution cycle. After they complete the execution of all the import entries that were scheduled in their cycle it is disposed.
    Author:
    mtaal
    • Field Detail

      • importEntryIds

        protected Set<String> importEntryIds
    • Constructor Detail

      • ImportEntryProcessRunnable

        public ImportEntryProcessRunnable()
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface Runnable
      • doRunCycle

        protected void doRunCycle()
      • cleanUpAndLogOnException

        protected void cleanUpAndLogOnException​(Throwable t)
        Cleans up after the import entry has failed processing and logs the exception information*
        Parameters:
        t - Throwable of the given exception
      • postProcessEntry

        protected void postProcessEntry​(String importEntryId,
                                        long t0,
                                        ImportEntry localImportEntry,
                                        String typeOfData)
        Method that is executed after processing an Import Entry, it is provided as protected because it might be useful to override it in certain cases where logic needs to be executed before/after the main postProcess. This handles marking the ImportEntry as processed and removing it from the queued list of import entries being processed.
        Parameters:
        importEntryId - Id of the import entry being processed
        t0 - Original timestamp when the import entry started processing
        localImportEntry - Import entry being processed
        typeOfData - The type of the import entry
      • getImportEntryQueue

        protected Queue<org.openbravo.service.importprocess.ImportEntryProcessor.ImportEntryProcessRunnable.QueuedEntry> getImportEntryQueue()
      • setOBContext

        protected void setOBContext​(org.openbravo.service.importprocess.ImportEntryProcessor.ImportEntryProcessRunnable.QueuedEntry queuedEntry)
      • getProcessIdForAudit

        protected String getProcessIdForAudit()
        Returns the identifier to be set for this process for audit trail:
        • It can be, at most, 32 characters length
        • If an AD_Message entry with the same value exists, it will be used in UI
      • setVariablesSecureApp

        protected void setVariablesSecureApp​(OBContext obContext)
      • cleanUpThreadForNextCycle

        protected void cleanUpThreadForNextCycle()
      • processEntry

        protected abstract void processEntry​(ImportEntry importEntry)
                                      throws Exception
        Must be implemented by a subclass. Note subclass implementation must perform a commit and close (OBDal.commitAndClose()) at the end of the processEntry, before it returns. So that at the end of processing there should not an active Session anymore the implementor is responsible for correctly closing any open session/transaction. A warning will be logged if this is somehow forgotten.
        Throws:
        Exception
      • cleanUp

        protected void cleanUp​(Set<String> importEntriesInExecution)
        This is a cleanUp function that is expected to be executed on Runner deregistering, it allows executing some code on deregistering.
        Parameters:
        importEntriesInExecution - - Import entries that are currently in execution
      • setImportEntryManager

        public void setImportEntryManager​(ImportEntryManager importEntryManager)
      • setKey

        public void setKey​(String key)
      • setImportEntryProcessor

        public void setImportEntryProcessor​(ImportEntryProcessor importEntryProcessor)
      • getKey

        public String getKey()
      • setImportEntryQueuedEntryContext

        protected void setImportEntryQueuedEntryContext​(ImportEntry importEntry)
        Sets the OBContext to a new QueuedEntry of the given ImportEntry
        Parameters:
        importEntry - Import Entry that will be used to create the QueuedEntry