Package org.corpus_tools.pepper.core
Class DocumentControllerImpl
- java.lang.Object
-
- org.corpus_tools.pepper.core.DocumentControllerImpl
-
- All Implemented Interfaces:
DocumentController
public class DocumentControllerImpl extends Object implements DocumentController
Stores the global status of aSDocument. And a list of tuples for all Modules and their current status. Can sendSDocumentGraphs contained in givenSDocumentto sleep and wake them.- Author:
- Florian Zipser
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classDocumentControllerImpl.DetailedStatusA small helper class, to store the status and the processing a specificPepperModuleneeded for theSDocumentobject contained by the containerDocumentControllerImplobject.
-
Field Summary
Fields Modifier and Type Field Description protected ModuleControllercurrentModuleControllerstores the currently active document controllerprotected booleanisStartedDetermines, if this object is already 'started', which means if#updateStatus(String, DOCUMENT_STATUS)has been called.protected List<ModuleControllerImpl>moduleControllersA list of allModuleControllerImplobjects, the here containedSDocumentobject has to pass.protected intnumberOfProcessingModulesStores the number ofPepperModule, currently processing thisDocumentControllerImpl.
-
Constructor Summary
Constructors Constructor Description DocumentControllerImpl()Initializes an object of this class.DocumentControllerImpl(org.corpus_tools.salt.common.SDocument document)Initializes an object of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddModuleControllers(ModuleControllerImpl moduleController)Adds a furtherModuleControllerImplto internal list of allModuleControllerImplobjects, the here containedSDocumentobject has to pass.voidawake()Wakes up the containedSDocument, which means, it theSDocumentGraphof theSDocumentwill be load to main memory again by callingSDocument#loadSDocumentGraph().ModuleControllergetCurrentModuleController()Returns the module controller, which is currently processing this document.org.corpus_tools.salt.common.SDocumentgetDocument()Returns theSDocumentobject, to which this object belongs to.org.corpus_tools.salt.graph.IdentifiergetDocumentId()Returns theIdentifierof theSDocumentobject, to which this object belongs to.StringgetGlobalId()Returns a global unique (inside one Salt project) id for the containedSDocumentobject.DOCUMENT_STATUSgetGlobalStatus()Returns the global status of this object.org.eclipse.emf.common.util.URIgetLocation()Returns location, where to storeSDocumentGraphwhen#sleep()was called or load whenDocumentController.awake()was calledList<ModuleControllerImpl>getModuleControllers()Returns a list of allModuleControllerImplobjects, the here containedSDocumentobject has to pass.intgetNumOfProcessingModules()Returns the number ofPepperModulecurrently processing theSDocumentor more precisly theSDocumentGraphcontained by thisDocumentControllerImplobject.LonggetProcessingTime()Returns the processing time of the containedSDocumentobject, needed by all registeredPepperModule, which have already started the process.doublegetProgress()Returns the progress of the containedSDocumentfor all registeredModuleControllerImplobjects.intgetSize_nodes()Stores the number ofSNodes a document contains, when it ws send to sleep.intgetSize_relations()Stores the number ofSRelations a document contains, when it ws send to sleep.StringgetStatusReport()Returns a formated string containing a report of the progress status of the contained document.booleanisAsleep()Returns if theSDocumentGraphof containedSDocumentis send to sleep or awake.voidsendToSleep()Notifies theDocumentControllerImplobject, that the containedSDocumentor more precisely theSDocumentGraphobject could be send to sleep.voidsendToSleep_FORCE()Sends theDocumentControllerImplobject, that the containedSDocumentor more precisely theSDocumentGraphobject could be send to sleep as methodDocumentController.sendToSleep().voidsetCallGC(boolean callGC)Sets whether the garbage collector should be called after sending aSDocumentobject to sleep.voidsetDocument(org.corpus_tools.salt.common.SDocument sDocument)Sets theSDocumentobject, to which this object belongs to.voidsetLocation(org.eclipse.emf.common.util.URI location)Sets location, where to storeSDocumentGraphwhen#sleep()was called or load whenDocumentController.awake()was called.protected voidsleep()Sends the containedSDocumentto sleep, which means, it will be stored to local disk and removed from main memory, by callingSDocument#saveSDocumentGraph(org.eclipse.emf.common.util.URI).StringtoString()Returns a textual representation of this object.voidupdateStatus(ModuleController moduleController, DOCUMENT_STATUS status)Updates the status of a specified of containedSDocumentobject corresponding to theModuleControllerImplmatching to the passed id.
-
-
-
Field Detail
-
moduleControllers
protected volatile List<ModuleControllerImpl> moduleControllers
A list of allModuleControllerImplobjects, the here containedSDocumentobject has to pass.
-
isStarted
protected volatile boolean isStarted
Determines, if this object is already 'started', which means if#updateStatus(String, DOCUMENT_STATUS)has been called.
-
numberOfProcessingModules
protected volatile int numberOfProcessingModules
Stores the number ofPepperModule, currently processing thisDocumentControllerImpl. Number is determined by method#updateStatus(String, DOCUMENT_STATUS)
-
currentModuleController
protected volatile ModuleController currentModuleController
stores the currently active document controller
-
-
Constructor Detail
-
DocumentControllerImpl
public DocumentControllerImpl()
Initializes an object of this class. The default value ofDOCUMENT_STATUSwill be set toDOCUMENT_STATUS.NOT_STARTED.
-
DocumentControllerImpl
public DocumentControllerImpl(org.corpus_tools.salt.common.SDocument document)
Initializes an object of this class. The default value ofDOCUMENT_STATUSwill be set toDOCUMENT_STATUS.NOT_STARTED.- Parameters:
document-SDocumentobject which is controlled by this object
-
-
Method Detail
-
getDocument
public org.corpus_tools.salt.common.SDocument getDocument()
Returns theSDocumentobject, to which this object belongs to.- Specified by:
getDocumentin interfaceDocumentController- Returns:
- document id
-
setDocument
public void setDocument(org.corpus_tools.salt.common.SDocument sDocument)
Sets theSDocumentobject, to which this object belongs to. Computes the globalId ( see:DocumentController.getGlobalId()). Adds the global id as processing instruction to theSDocumentobject.- Specified by:
setDocumentin interfaceDocumentController- Parameters:
sDocument-SDocumentobject to which this object belongs to
-
getDocumentId
public org.corpus_tools.salt.graph.Identifier getDocumentId()
Returns theIdentifierof theSDocumentobject, to which this object belongs to.- Specified by:
getDocumentIdin interfaceDocumentController- Returns:
- document id
-
getGlobalId
public String getGlobalId()
Returns a global unique (inside one Salt project) id for the containedSDocumentobject. This identifier is computed by mthe number of theSCorpusGraphin list, thisSDocumentobject is contained in and theIdentifierof theSDocument. Imagine the number of theSCorpusGraphis 1 and theIdentifier.getId()is /corpus1/document1, than the returned global id is /1/corpus1/document1.- Specified by:
getGlobalIdin interfaceDocumentController- Returns:
- a global unique (inside one Salt project) id for the contained
SDocumentobject
-
setCallGC
public void setCallGC(boolean callGC)
Sets whether the garbage collector should be called after sending aSDocumentobject to sleep.- Parameters:
callGC-
-
getLocation
public org.eclipse.emf.common.util.URI getLocation()
Returns location, where to storeSDocumentGraphwhen#sleep()was called or load whenDocumentController.awake()was called- Specified by:
getLocationin interfaceDocumentController- Returns:
- location
-
setLocation
public void setLocation(org.eclipse.emf.common.util.URI location)
Sets location, where to storeSDocumentGraphwhen#sleep()was called or load whenDocumentController.awake()was called.- Specified by:
setLocationin interfaceDocumentController- Parameters:
location- location asURI
-
isAsleep
public boolean isAsleep()
Returns if theSDocumentGraphof containedSDocumentis send to sleep or awake.- Specified by:
isAsleepin interfaceDocumentController- Returns:
- true, if
SDocumentGraphis asleep, false otherwise.
-
sleep
protected void sleep()
Sends the containedSDocumentto sleep, which means, it will be stored to local disk and removed from main memory, by callingSDocument#saveSDocumentGraph(org.eclipse.emf.common.util.URI). The counterpart to this method isawake(). Both methods are synchronized.
-
sendToSleep
public void sendToSleep()
Notifies theDocumentControllerImplobject, that the containedSDocumentor more precisely theSDocumentGraphobject could be send to sleep. If noPepperModuleis currently processing it, theSDocumentGraphis send to sleep. This means, theSDocumentGraphwill be stored to local disk and removed from main memory, by callingSDocument#saveSDocumentGraph(org.eclipse.emf.common.util.URI). The counterpart to this method isDocumentController.awake(). Both methods are synchronized.- Specified by:
sendToSleepin interfaceDocumentController
-
sendToSleep_FORCE
public void sendToSleep_FORCE()
Sends theDocumentControllerImplobject, that the containedSDocumentor more precisely theSDocumentGraphobject could be send to sleep as methodDocumentController.sendToSleep().
But note, this method does not check if theSDocumentGraphis still in use by any other module. Therfore handle with care.- Specified by:
sendToSleep_FORCEin interfaceDocumentController
-
awake
public void awake()
Wakes up the containedSDocument, which means, it theSDocumentGraphof theSDocumentwill be load to main memory again by callingSDocument#loadSDocumentGraph(). The counterpart to this method is#sleep(). Both methods are synchronized.- Specified by:
awakein interfaceDocumentController
-
toString
public String toString()
Returns a textual representation of this object. Note: This representation could not be used for serialization/deserialization purposes.
-
getModuleControllers
public List<ModuleControllerImpl> getModuleControllers()
Returns a list of allModuleControllerImplobjects, the here containedSDocumentobject has to pass.- Specified by:
getModuleControllersin interfaceDocumentController- Returns:
- a list of all
ModuleControllerImplobjects
-
addModuleControllers
public void addModuleControllers(ModuleControllerImpl moduleController)
Adds a furtherModuleControllerImplto internal list of allModuleControllerImplobjects, the here containedSDocumentobject has to pass.
Note: You cannot call this method anymore, if the process has already been started. Which means that the methods#updateStatus(String, DOCUMENT_STATUS)has been called.- Specified by:
addModuleControllersin interfaceDocumentController- Parameters:
moduleController-ModuleControllerImpltheSDocumentalso has to pass
-
getNumOfProcessingModules
public int getNumOfProcessingModules()
Returns the number ofPepperModulecurrently processing theSDocumentor more precisly theSDocumentGraphcontained by thisDocumentControllerImplobject.- Specified by:
getNumOfProcessingModulesin interfaceDocumentController- Returns:
- number of processing
PepperModuleobjects
-
getCurrentModuleController
public ModuleController getCurrentModuleController()
Returns the module controller, which is currently processing this document.- Specified by:
getCurrentModuleControllerin interfaceDocumentController- Returns:
- the currently active
ModuleController
-
updateStatus
public void updateStatus(ModuleController moduleController, DOCUMENT_STATUS status)
Updates the status of a specified of containedSDocumentobject corresponding to theModuleControllerImplmatching to the passed id.- Specified by:
updateStatusin interfaceDocumentControllerstatus- the status to which theStepStatusshall be set to.
-
getGlobalStatus
public DOCUMENT_STATUS getGlobalStatus()
Returns the global status of this object. The global status is determined by eachStepStatusobject being contained in this object.- If one of the contained
StepStatusobjects status value is set toDOCUMENT_STATUS.IN_PROGRESS, the global status will beDOCUMENT_STATUS.IN_PROGRESS. - If one of the contained
StepStatusobjects status value is set toDOCUMENT_STATUS.DELETED, the global status will beDOCUMENT_STATUS.DELETED. - If one of the contained
StepStatusobjects status value is set toDOCUMENT_STATUS.FAILED, the global status will beDOCUMENT_STATUS.FAILED. - Only if each contained
StepStatusobjects status value is set toDOCUMENT_STATUS.COMPLETED, the global status will beDOCUMENT_STATUS.COMPLETED.
- Specified by:
getGlobalStatusin interfaceDocumentController- Returns:
- If one of the contained
-
getProgress
public double getProgress()
Returns the progress of the containedSDocumentfor all registeredModuleControllerImplobjects.- Specified by:
getProgressin interfaceDocumentController- Returns:
- percentage value between 0 and 1.
-
getProcessingTime
public Long getProcessingTime()
Returns the processing time of the containedSDocumentobject, needed by all registeredPepperModule, which have already started the process.- Specified by:
getProcessingTimein interfaceDocumentController
-
getStatusReport
public String getStatusReport()
Returns a formated string containing a report of the progress status of the contained document.- Returns:
- a report of the progress status
-
getSize_nodes
public int getSize_nodes()
Stores the number ofSNodes a document contains, when it ws send to sleep.- Specified by:
getSize_nodesin interfaceDocumentController- Returns:
- number of
SNodeof the contained document
-
getSize_relations
public int getSize_relations()
Stores the number ofSRelations a document contains, when it ws send to sleep.- Specified by:
getSize_relationsin interfaceDocumentController- Returns:
- number of
SRelationof the contained document
-
-