Class ImportEntryManager
- java.lang.Object
-
- org.openbravo.service.importprocess.ImportEntryManager
-
- All Implemented Interfaces:
ImportEntryManagerMBean
@ApplicationScoped public class ImportEntryManager extends Object implements ImportEntryManagerMBean
This class is the main manager for performing multi-threaded and parallel import of data from theImportEntry
entity/table. TheImportEntryManager
is a singleton/ApplicationScoped class.- Author:
- mtaal
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ImportEntryManager.DaemonThreadFactory
Creates threads which have deamon set to true.static class
ImportEntryManager.ImportEntryProcessorSelector
static interface
ImportEntryManager.ImportEntryQualifier
-
Constructor Summary
Constructors Constructor Description ImportEntryManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
commitCurrentTransaction()
Commits the current transaction if the current node is in charge of handling the import entries.void
createImportEntry(String id, String typeOfData, String json)
Creates and saves the import entry, calls theImportEntryPreProcessor.beforeCreate(ImportEntry)
on theImportEntryPreProcessor
instances.void
createImportEntry(String id, String typeOfData, String json, boolean commitAndClose)
Creates and saves the import entry, calls theImportEntryPreProcessor.beforeCreate(ImportEntry)
on theImportEntryPreProcessor
instances.void
createImportEntry(String id, String typeOfData, String json, boolean commitAndClose, boolean isNonBlocking)
Creates and saves the import entry, calls theImportEntryPreProcessor.beforeCreate(ImportEntry)
on theImportEntryPreProcessor
instances.static ImportEntryManager
getInstance()
long
getNumberOfActiveTasks()
long
getNumberOfQueuedTasks()
void
handleImportError(ImportEntry importEntry, Throwable t)
boolean
isExecutorRunning()
boolean
isImportEntryError(String importEntryId)
Returns whether the ImportEntry is in status Error in the same transaction as the caller.boolean
isShutDown()
void
logImportEntryManager()
Logs ImportEntryManager's current status with information about all the queued and processing entries.void
notifyEndProcessingInCluster()
This method is used to set the cluster service into an state that indicates that it is currently not processing import entries.void
notifyNewImportEntryCreated()
Is used to tell the import entry manager that a new entry was created in the import entry table, so it can go process it immediately.void
notifyStartProcessingInCluster()
This method is used to set the cluster service into an state that indicates that it is currently processing import entries.void
reportStats(String typeOfData, long timeForEntry)
void
setImportEntryError(String importEntryId, Throwable t)
Set the ImportEntry to status Error in the same transaction as the caller.void
setImportEntryErrorIndependent(String importEntryId, Throwable t)
Sets anImportEntry
in status Error but does this in its own transaction so not together with the original data.void
setImportEntryProcessed(String importEntryId)
Set the ImportEntry to status Processed in the same transaction as the caller.void
shutdown()
Shutdown all the threads being used by the import frameworkvoid
start()
String
toString()
-
-
-
Method Detail
-
getInstance
public static ImportEntryManager getInstance()
-
isShutDown
public boolean isShutDown()
- Returns:
true
if the ImportEntryManager is shut down. Otherwisefalse
is returned. The ImportEntryManager can be shut down because of any of these reasons: 1- Theshutdown()
method has been invoked
2- In a clustered environment, the current node is not in charge of handling import entries
-
start
public void start()
-
getNumberOfQueuedTasks
public long getNumberOfQueuedTasks()
-
getNumberOfActiveTasks
public long getNumberOfActiveTasks()
-
isExecutorRunning
public boolean isExecutorRunning()
-
notifyStartProcessingInCluster
public void notifyStartProcessingInCluster()
This method is used to set the cluster service into an state that indicates that it is currently processing import entries. Note that if we are not in a clustered environment, this method has no effect.
-
notifyEndProcessingInCluster
public void notifyEndProcessingInCluster()
This method is used to set the cluster service into an state that indicates that it is currently not processing import entries. Note that if we are not in a clustered environment, this method has no effect.
-
shutdown
public void shutdown()
Shutdown all the threads being used by the import framework
-
createImportEntry
public void createImportEntry(String id, String typeOfData, String json)
Creates and saves the import entry, calls theImportEntryPreProcessor.beforeCreate(ImportEntry)
on theImportEntryPreProcessor
instances. Note will commit the session/connection usingOBDal.commitAndClose()
-
createImportEntry
public void createImportEntry(String id, String typeOfData, String json, boolean commitAndClose)
Creates and saves the import entry, calls theImportEntryPreProcessor.beforeCreate(ImportEntry)
on theImportEntryPreProcessor
instances. Note will commit the session/connection usingOBDal.commitAndClose()
-
createImportEntry
public void createImportEntry(String id, String typeOfData, String json, boolean commitAndClose, boolean isNonBlocking)
Creates and saves the import entry, calls theImportEntryPreProcessor.beforeCreate(ImportEntry)
on theImportEntryPreProcessor
instances. Note will commit the session/connection usingOBDal.commitAndClose()
-
reportStats
public void reportStats(String typeOfData, long timeForEntry)
-
notifyNewImportEntryCreated
public void notifyNewImportEntryCreated()
Is used to tell the import entry manager that a new entry was created in the import entry table, so it can go process it immediately.- Specified by:
notifyNewImportEntryCreated
in interfaceImportEntryManagerMBean
-
commitCurrentTransaction
public void commitCurrentTransaction() throws SQLException
Commits the current transaction if the current node is in charge of handling the import entries. This method is intended to be used by those import entry processors which need to commit their changes in the middle of the process. If processors don't use this method for committing the changes they can leave an inconsistent state in the system if a subsequent call tosetImportEntryProcessed(String)
detects that we are not in the node that should handle the import entries.- Throws:
OBException
- if this method is invoked in a cluster node which is not handling the import entriesSQLException
-
handleImportError
public void handleImportError(ImportEntry importEntry, Throwable t)
-
setImportEntryProcessed
public void setImportEntryProcessed(String importEntryId)
Set the ImportEntry to status Processed in the same transaction as the caller.- Throws:
OBException
- if the import entry can't be set as processed because the current cluster node is not in charge of processing import entries
-
setImportEntryError
public void setImportEntryError(String importEntryId, Throwable t)
Set the ImportEntry to status Error in the same transaction as the caller.
-
isImportEntryError
public boolean isImportEntryError(String importEntryId)
Returns whether the ImportEntry is in status Error in the same transaction as the caller.
-
setImportEntryErrorIndependent
public void setImportEntryErrorIndependent(String importEntryId, Throwable t)
Sets anImportEntry
in status Error but does this in its own transaction so not together with the original data. This is relevant when the previous transaction which tried to import the data fails.
-
logImportEntryManager
public void logImportEntryManager()
Description copied from interface:ImportEntryManagerMBean
Logs ImportEntryManager's current status with information about all the queued and processing entries.- Specified by:
logImportEntryManager
in interfaceImportEntryManagerMBean
-
-