Class ImportEntryProcessor.ImportEntryProcessRunnable
- java.lang.Object
-
- org.openbravo.service.importprocess.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 otherImportEntry
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 theRequestContext
. - OBContexts are temporary cached in a
WeakHashMap
- the process checks the
ImportEntry
status just before it is processed, it also prevents the sameImportEntry
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.
- Author:
- mtaal
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<String>
importEntryIds
-
Constructor Summary
Constructors Constructor Description ImportEntryProcessRunnable()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.protected void
cleanUpAndLogOnException(Throwable t)
Cleans up after the import entry has failed processing and logs the exception information*protected void
cleanUpThreadForNextCycle()
protected void
doRunCycle()
protected Queue<org.openbravo.service.importprocess.ImportEntryProcessor.ImportEntryProcessRunnable.QueuedEntry>
getImportEntryQueue()
String
getKey()
protected String
getProcessIdForAudit()
Returns the identifier to be set for this process for audit trail: It can be, at most, 32 characters length If anAD_Message
entry with the same value exists, it will be used in UIprotected 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.protected abstract void
processEntry(ImportEntry importEntry)
Must be implemented by a subclass.void
run()
void
setImportEntryManager(ImportEntryManager importEntryManager)
void
setImportEntryProcessor(ImportEntryProcessor importEntryProcessor)
protected void
setImportEntryQueuedEntryContext(ImportEntry importEntry)
Sets the OBContext to a new QueuedEntry of the given ImportEntryvoid
setKey(String key)
protected void
setOBContext(org.openbravo.service.importprocess.ImportEntryProcessor.ImportEntryProcessRunnable.QueuedEntry queuedEntry)
protected void
setVariablesSecureApp(OBContext obContext)
String
toString()
-
-
-
Method Detail
-
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 processedt0
- Original timestamp when the import entry started processinglocalImportEntry
- Import entry being processedtypeOfData
- 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
-
-