Package org.corpus_tools.pepper.core
Class PepperJobImpl
- java.lang.Object
-
- org.corpus_tools.pepper.common.PepperJob
-
- org.corpus_tools.pepper.core.PepperJobImpl
-
public class PepperJobImpl extends PepperJob
This class represents a single, but entire conversion process in Pepper, containing the entire workflow like import, manipulation and export.
This object contains a list of single steps. Each of such steps represent one task in processing by a specific module. Such a step is represented by theStepclass. To get the list of all steps, see#getSteps(). Note: Do not use this list to add a further step. Use#addStep(PepperModule)instead.Order of tasks to be done for start of processing
If you do not follow this order in calling, and for instance call task 3 fist, than task 1 and task 2 will be done automatically.- wiring of
ModuleControllerImpl,DocumentBusandPepperJobImpl - import of corpus structure
- start
- Author:
- Florian Zipser
- wiring of
-
-
Field Summary
Fields Modifier and Type Field Description protected List<DocumentBus>documentBusesA list of all buses between theModuleControllerImplobjectsprotected List<DocumentController>documentControllersA list of allDocumentControllerImplobjects corresponding to eachSDocumentbelonging to this job.protected List<DocumentBus>initialDocumentBusesall documentBusses which are connected withPepperImportermodulesprotected ReentrantLockinProgressSpecifies if this job currently runs a conversion.protected booleanisImportedCorpusStructureflag to determine, if corpus structure has already been importedprotected booleanisReadyToStartDetermines ifcheckReadyToStart()was already calledprotected booleanisWiredDetermines, if steps are already wired.protected MEMORY_POLICYmemPolicyprotected ModuleResolvermoduleResolverA reference to the OSGi module resolver, to find modules matching to the step descriptionprotected org.corpus_tools.salt.common.SaltProjectsaltProjectTheSaltProjectwhich is converted by this job.
-
Constructor Summary
Constructors Constructor Description PepperJobImpl(String jobId)Initializes aPepperJobImpland sets its unique identifier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StepaddStep(StepDesc stepDesc)Creates a newStepobject containing all values of the passedStepDescobject and adds it to the workflow covered by thisPepperJobImpl.voidaddStep(Step step)Adds the passedStepobject to the workflow covered by thisPepperJobImplobject and tries to resolve the describedPepperModule.voidaddStepDesc(StepDesc stepDesc)Overrides methodPepperJob.addStepDesc(StepDesc), but calls it via super and than callsaddStep(Step).
{@inheritDoc PepperJob#addStepDesc(StepDesc)}voidcancelConversion()Cancels the current conversion.protected Collection<org.apache.commons.lang3.tuple.Pair<Step,Collection<String>>>checkReadyToStart()Checks for eachPepperModulein all steps, if it is ready to start, via callingPepperModule.isReadyToStart().voidclear(){@inheritDoc PepperJob#clear()}voidconvert()Starts the conversion of this job.voidconvertFrom()Imports aSaltProjectfrom any format.voidconvertTo()Exports theSaltProjectinto any format.Set<DocumentController>getActiveDocuments()Returns a set of all currently active documents.List<Step>getAllSteps()Returns a of all steps belonging no matter, to which phase they belong.PepperConfigurationgetConfiguration()returns the properties to customize the behavior of conversion for this single job.protected List<DocumentBus>getDocumentBuses()List<DocumentController>getDocumentControllers()Returns a list of allDocumentControllerImplobjects corresponding to eachSDocumentbelonging to this job.List<Step>getExportSteps()Returns the list of all steps belonging to the export phase.List<Step>getImportSteps()Returns the list of all steps belonging to the import phase.List<Step>getManipulationSteps()Returns the list of all steps belonging to the manipulation phase.intgetMaxNumberOfDocuments()Returns the maximal number ofSDocumentobjects which could be processed at the same timeMEMORY_POLICYgetMemPolicy()Returns the set memory policy.ModuleResolvergetModuleResolver()Returns a reference to the OSGi module resolver, to find modules matching to the step description.intgetNumOfActiveDocuments()Returns the current number ofSDocumentobjects which could be processed at the same timebooleangetPermissionForProcessDoument(DocumentController controller)Returns true, if aSDocumentor more precisely spoken aSDocumentGraphcould be woken up or imported.LonggetProcessingTime()Returns the amount of time the job already took.org.corpus_tools.salt.common.SaltProjectgetSaltProject()Returns theSaltProjectwhich is converted by this job.StringgetStatusReport(){@inheritDoc PepperJob#getStatusReport()}protected voidimportCorpusStructures()Imports corpus structures of all registeredImportCorpusStructureTeststeps.booleanisCancellationRequested()Get if someone requested to cancel this job.voidload(org.eclipse.emf.common.util.URI uri){@inheritDoc PepperJob#load(URI)}voidreleaseDocument(DocumentController controller)Releases a document and reduces the internal counter for the number of currently processed documents (getNumOfActiveDocuments()).org.eclipse.emf.common.util.URIsave(org.eclipse.emf.common.util.URI uri){@inheritDoc PepperJob#save(URI)}voidsetConfiguration(PepperConfiguration conf)Sets the properties to customize the behavior of conversion for this single jobprotected voidsetMaxNumerOfDocuments(int maxNumOfDocuments)protected voidsetMemPolicy(MEMORY_POLICY memPolicy)Sets the memory policy.voidsetModuleResolver(ModuleResolver moduleResolver)Sets a reference to the OSGi module resolver, to find modules matching to the step description.voidsetSaltProject(org.corpus_tools.salt.common.SaltProject saltProject)Sets theSaltProjectwhich is converted by this job.StringtoString()Returns a textual representation of this Pepper job.protected List<org.corpus_tools.salt.graph.Identifier>unifyProposedImportOrders(org.corpus_tools.salt.common.SCorpusGraph sCorpusGraph)Returns a list ofIdentifiers corresponding to theSDocumentobjects contained in the passedSCorpusGraphobject.protected voidwire()Wires allStepobjects being contained by this object to be ready for#start().-
Methods inherited from class org.corpus_tools.pepper.common.PepperJob
createStepDesc, getBaseDir, getId, getStatus, getStepDescs, setBaseDir
-
-
-
-
Field Detail
-
saltProject
protected org.corpus_tools.salt.common.SaltProject saltProject
TheSaltProjectwhich is converted by this job.
-
moduleResolver
protected ModuleResolver moduleResolver
A reference to the OSGi module resolver, to find modules matching to the step description
-
documentBuses
protected List<DocumentBus> documentBuses
A list of all buses between theModuleControllerImplobjects
-
initialDocumentBuses
protected List<DocumentBus> initialDocumentBuses
all documentBusses which are connected withPepperImportermodules
-
isWired
protected boolean isWired
Determines, if steps are already wired. This is necessary for#start().
-
isImportedCorpusStructure
protected volatile boolean isImportedCorpusStructure
flag to determine, if corpus structure has already been imported
-
documentControllers
protected List<DocumentController> documentControllers
A list of allDocumentControllerImplobjects corresponding to eachSDocumentbelonging to this job.
-
isReadyToStart
protected boolean isReadyToStart
Determines ifcheckReadyToStart()was already called
-
inProgress
protected volatile ReentrantLock inProgress
Specifies if this job currently runs a conversion. If this is the case, some other operations, like addingSteps cannot be done simultaneously.
-
memPolicy
protected volatile MEMORY_POLICY memPolicy
-
-
Constructor Detail
-
PepperJobImpl
public PepperJobImpl(String jobId)
Initializes aPepperJobImpland sets its unique identifier.- Parameters:
jobId- unique identifier for this job. The id is not changeable
-
-
Method Detail
-
getSaltProject
public org.corpus_tools.salt.common.SaltProject getSaltProject()
Returns theSaltProjectwhich is converted by this job.- Specified by:
getSaltProjectin classPepperJob- Returns:
SaltProject
-
setSaltProject
public void setSaltProject(org.corpus_tools.salt.common.SaltProject saltProject)
Sets theSaltProjectwhich is converted by this job.- Parameters:
saltProject- newSaltProject
-
getConfiguration
public PepperConfiguration getConfiguration()
returns the properties to customize the behavior of conversion for this single job.- Returns:
- given customization properties
-
setConfiguration
public void setConfiguration(PepperConfiguration conf)
Sets the properties to customize the behavior of conversion for this single job- Parameters:
conf- for customization
-
getModuleResolver
public ModuleResolver getModuleResolver()
Returns a reference to the OSGi module resolver, to find modules matching to the step description.- Returns:
- reference to resolver to resolve
PepperModuleobjects
-
setModuleResolver
public void setModuleResolver(ModuleResolver moduleResolver)
Sets a reference to the OSGi module resolver, to find modules matching to the step description.- Parameters:
moduleResolver- reference to resolver to resolvePepperModuleobjects
-
getManipulationSteps
public List<Step> getManipulationSteps()
Returns the list of all steps belonging to the manipulation phase.- Returns:
- list of
Stepobjects.
-
getImportSteps
public List<Step> getImportSteps()
Returns the list of all steps belonging to the import phase.- Returns:
- list of
Stepobjects.
-
getExportSteps
public List<Step> getExportSteps()
Returns the list of all steps belonging to the export phase.- Returns:
- list of
Stepobjects.
-
getAllSteps
public List<Step> getAllSteps()
Returns a of all steps belonging no matter, to which phase they belong.
This computation could be expensive, when working more than once with the list, make a local copy and don't call this method twice.- Returns:
- list of
Stepobjects.
-
addStepDesc
public void addStepDesc(StepDesc stepDesc)
Overrides methodPepperJob.addStepDesc(StepDesc), but calls it via super and than callsaddStep(Step).
{@inheritDoc PepperJob#addStepDesc(StepDesc)}- Overrides:
addStepDescin classPepperJob- Parameters:
stepDesc- description object of a particular step
-
addStep
public Step addStep(StepDesc stepDesc)
Creates a newStepobject containing all values of the passedStepDescobject and adds it to the workflow covered by thisPepperJobImpl. Further tries to resolve the describedPepperModule.
-
addStep
public void addStep(Step step)
Adds the passedStepobject to the workflow covered by thisPepperJobImplobject and tries to resolve the describedPepperModule.Prerequisite
getModuleResolver()must be setgetSaltProject()must be set
- Parameters:
step-Stepobject to be added to internal list
-
getDocumentBuses
protected List<DocumentBus> getDocumentBuses()
-
wire
protected void wire()
Wires allStepobjects being contained by this object to be ready for#start(). Which means, that:- each step of
getImportSteps()is wired via a initial document bus with the framework (no wiring, but listening on#ID_INTITIAL) - each step of
getManipulationSteps()is wired with following step in list with aDocumentBus. - each step of
getExportSteps()is wired via a terminal document bus with the framework (no wiring, but listening on#ID_TERMINAL)
- each step of
-
importCorpusStructures
protected void importCorpusStructures()
Imports corpus structures of all registeredImportCorpusStructureTeststeps. After callingPepperImporter.importCorpusStructure(SCorpusGraph), all following modules will be asked, if they want to influence the order of importing documents. If this is the case, an order is created and put to allPepperImporterobjects.
This method produces as much asSCorpusGraphobjects asStepgiven in import step listgetImportSteps(). The position ofSCorpusGraphcorresponding toPepperImporter(importing that graph) inSaltProject.getCorpusGraphs()is equivalent to position ofStepin listgetImportSteps().
-
unifyProposedImportOrders
protected List<org.corpus_tools.salt.graph.Identifier> unifyProposedImportOrders(org.corpus_tools.salt.common.SCorpusGraph sCorpusGraph)
Returns a list ofIdentifiers corresponding to theSDocumentobjects contained in the passedSCorpusGraphobject. If all registered modules, do not make a proposal, the natural one (the one given by the order ofSDocuments inSCorpusGraph) is taken. Note: Currently, this method does not a real unification, if more than one proposals are given, the first one is taken.- Parameters:
sCorpusGraph- theSCorpusGraphfor which the list has to be unified- Returns:
- unified list
-
getDocumentControllers
public List<DocumentController> getDocumentControllers()
Returns a list of allDocumentControllerImplobjects corresponding to eachSDocumentbelonging to this job.- Returns:
- a list of all
DocumentControllerImpls
-
getStatusReport
public String getStatusReport()
{@inheritDoc PepperJob#getStatusReport()}- Specified by:
getStatusReportin classPepperJob- Returns:
- a report of the progress status
-
checkReadyToStart
protected Collection<org.apache.commons.lang3.tuple.Pair<Step,Collection<String>>> checkReadyToStart()
Checks for eachPepperModulein all steps, if it is ready to start, via callingPepperModule.isReadyToStart().- Returns:
- a list of steps whose modules are not ready to start
-
getProcessingTime
public Long getProcessingTime()
Returns the amount of time the job already took.- Returns:
- time in milli seconds
-
convert
public void convert()
Starts the conversion of this job.- If the single steps of the job has not already been wired, they will be wired.
- If
PepperImporter.importCorpusStructure(SCorpusGraph)has not already been called, it will be done.
-
convertFrom
public void convertFrom()
Imports aSaltProjectfrom any format. For conversion a process can be modeled, similar toPepperJob.convert()with the difference, that noPepperExportercould be defined. The imported Salt model can be accessed viaPepperJob.getSaltProject().- Specified by:
convertFromin classPepperJob
-
convertTo
public void convertTo()
Exports theSaltProjectinto any format. For conversion, a normal process could be created, except the use of an importer. Here the do-nothing importer is used, and it is expected, that thePepperJob.getSaltProject()is already 'filled'.
-
cancelConversion
public void cancelConversion()
Description copied from class:PepperJobCancels the current conversion. This might not stop immediately, but might finish the running document controller jobs first.- Specified by:
cancelConversionin classPepperJob
-
isCancellationRequested
public boolean isCancellationRequested()
Get if someone requested to cancel this job.- Returns:
- True if cancellation was requested.
-
getMemPolicy
public MEMORY_POLICY getMemPolicy()
Returns the set memory policy.- Returns:
-
setMemPolicy
protected void setMemPolicy(MEMORY_POLICY memPolicy)
Sets the memory policy. Don't change the memory policy, when job was started.- Parameters:
memPolicy-
-
setMaxNumerOfDocuments
protected void setMaxNumerOfDocuments(int maxNumOfDocuments)
-
getMaxNumberOfDocuments
public int getMaxNumberOfDocuments()
Returns the maximal number ofSDocumentobjects which could be processed at the same time- Returns:
- number of documents
-
getNumOfActiveDocuments
public int getNumOfActiveDocuments()
Returns the current number ofSDocumentobjects which could be processed at the same time- Returns:
- number of documents
-
getActiveDocuments
public Set<DocumentController> getActiveDocuments()
Returns a set of all currently active documents.
-
getPermissionForProcessDoument
public boolean getPermissionForProcessDoument(DocumentController controller)
Returns true, if aSDocumentor more precisely spoken aSDocumentGraphcould be woken up or imported. This is the case, as long as:
getNumOfActiveDocuments()<getMaxNumberOfDocuments().
Must be synchronized,- Returns:
- true, when #getCurrNumberOfDocuments()} < {@link #getMaxNumberOfDocuments(), false otherwise
-
releaseDocument
public void releaseDocument(DocumentController controller)
Releases a document and reduces the internal counter for the number of currently processed documents (getNumOfActiveDocuments()).
-
save
public org.eclipse.emf.common.util.URI save(org.eclipse.emf.common.util.URI uri)
{@inheritDoc PepperJob#save(URI)}- Specified by:
savein classPepperJob- Parameters:
uri- The location where to store this job.- Returns:
- Returns the URI where the Pepper job was stored, normally this is
the passed uri, but if the passed uri is a folder, than a file
having the job-if (
PepperJob.getId()).
-
load
public void load(org.eclipse.emf.common.util.URI uri)
{@inheritDoc PepperJob#load(URI)}
-
-