- Direct Known Subclasses:
@ApplicationScoped public abstract class ImportEntryProcessor extends ObjectThe
ImportEntryProcessoris responsible for importing/processing
ImportEntryinstances for a specific TypeOfData. The
ImportEntryProcessoris a singleton/applicationscoped, it implements a generic approach to make to make it possible to do import of
ImportEntryin parallel threads (
ImportEntryProcessor.ImportEntryProcessRunnable) if possible. It is important that a specific ImportEntry is assigned to the right processing thread to prevent for example deadlocks in the database. To make this possible a concept of
getProcessSelectionKey(ImportEntry)is used. The process selection key is a unique key derived from the
ImportEntrywhich can be used to create/identify the thread which should process the
ImportEntry. If no such thread exists a new
ImportEntryProcessor.ImportEntryProcessRunnableis created. The exact type of
ImportEntryProcessor.ImportEntryProcessRunnableis determined by the extending subclass through the
createImportEntryProcessRunnable()method. For example if ImportEntry records of the same organization should be processed after each other (so not in parallel) to prevent DB deadlocks, this means that the records of the same organization should be assigned to the same thread object. So that they are indeed processed sequential and not in parallel. The
getProcessSelectionKey(ImportEntry)should in this case return the
ImportEntryProcessor.ImportEntryProcessRunnableare keyed/registered using the organization. Other
ImportEntryrecords of the same organization are then processed by the same thread, always sequential, not parallel, preventing DB deadlocks. The
ImportEntryrecords to the the
ImportEntryProcessorby calling its
ImportEntryProcessorthen can decide how to handle this
ImportEntry, create a new thread or assign it to an existing thread (which is busy processing previous entries). This is all done in this generic class. An implementing subclass needs to implement the
getProcessSelectionKey(ImportEntry)method. This method determines which/how the correct
ImportEntryProcessor.ImportEntryProcessRunnableis chosen. The default/base implementation of the
ImportEntryProcessor.ImportEntryProcessRunnableprovides standard features related to caching of
OBContext, error handling and transaction handling. Note: this implementation uses the executorService in the
ImportEntryManager. Threads are started by using the
ImportEntryManager.submitRunnable(Runnable). Any exceptions inside the
Runnable.run()method are swallowed and won't directly show up in the console. Therefore the default implementation in the
ImportEntryProcessor.ImportEntryProcessRunnable.run()has different mechanisms to correctly log/record the error (in the
ImportEntry.getErrorinfo()). Note: the
ImportEntryProcessorshould be aware that the same
ImportEntrycan be passed multiple times to it. Also after the
ImportEntryProcessorhas already processed it. This can happen because of the parallel/multi-threaded approach followed here. So the
ImportEntryProcessorand the implementation of the
ImportEntryProcessor.ImportEntryProcessRunnableshould correctly and robustly handle this case. The default
ImportEntryProcessor.ImportEntryProcessRunnableimplementation has mechanism to prevent double processing in some cases. Note: it is save for an ImportEntryProcessor to occasionally not process an
ImportEntryManagerwill offer the
ImportEntryagain in its next cycle. But it is quite important that this only happens if the order of the entries being processed is maintained or not relevant.
Nested Class Summary
Nested Classes Modifier and Type Class Description
ImportEntryProcessor.ImportEntryProcessRunnableThe default implementation of the ImportEntryProcessRunnable.
Constructors Constructor Description
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description
assignEntryToThread(String key, ImportEntry importEntry)Assigns an import entry to a processing thread besed on its type and key.
protected abstract boolean
canHandleImportEntry(ImportEntry importEntryInformation)Can be used by implementing subclass to check that the ImportEntry can be processed now.
protected abstract ImportEntryProcessor.ImportEntryProcessRunnable
createImportEntryProcessRunnable()Create a concrete subclass of
enableArchive()Declares if the import entry will later on be archived after it has been processed
protected abstract String
handleImportEntry(ImportEntry importEntry)Is called from the
ImportEntryManagerthread, passes in a new ImportEntry to process.
shutdown()Is called when the application context/tomcat stops, is called from
public void shutdown()Is called when the application context/tomcat stops, is called from
public boolean handleImportEntry(ImportEntry importEntry)Is called from the
ImportEntryManagerthread, passes in a new ImportEntry to process. Finds the Thread which can handle this entry, if none is found a new thread is created, if one is found then the ImportEntry is passed/given to it. If the processing of the entry does not happen fast enough then it can be that the
ImportEntryis again offered to the
ImportEntryProcessorthrough a call to this method. The implementation should be able to gracefully handle duplicate entries. Also the implementation should check if the
ImportEntrywas possibly already handled and ignore it then.
- whether the importEntry has been assigned to a thread for it to be processed
protected boolean assignEntryToThread(String key, ImportEntry importEntry)Assigns an import entry to a processing thread besed on its type and key.
- whether the import entry could be assigned to a thread
protected abstract ImportEntryProcessor.ImportEntryProcessRunnable createImportEntryProcessRunnable()Create a concrete subclass of
protected abstract boolean canHandleImportEntry(ImportEntry importEntryInformation)Can be used by implementing subclass to check that the ImportEntry can be processed now. In some cases other ImportEntries should be processed first. By returning false the ImportEntry is ignored for now. It will again be picked up in a next execution cycle of the
ImportEntryManagerthread and then offered again to this
ImportEntryProcessorto be processed.
protected boolean enableArchive()Declares if the import entry will later on be archived after it has been processed