Package org.corpus_tools.pepper.core
Class DocumentBus
- java.lang.Object
-
- org.corpus_tools.pepper.core.DocumentBus
-
- Direct Known Subclasses:
InitialDocumentBus,TerminalDocumentBus
public class DocumentBus extends Object
This object is an implementation of a threadsafe queue to storeDocumentControllerobjects. Such an object is used to connect multipleModuleControllerobjects. AnDocumentControllercan only be removed from queue, when all outputModuleControllerobjects requested theDocumentControllerobject.
This object has a list of Ids belonging toModuleControllerobjects, which are on the output side of this queue. All these objects have to request a document, before this queue can get the status finished. The same goes forModuleControllerobjects on the input side. All these controllers have to notify this queue to be finished, before the queue can notify the controllers on the output side, that this queue is finished.- Author:
- Florian Zipser
-
-
Field Summary
Fields Modifier and Type Field Description protected Hashtable<String,ConcurrentLinkedQueue<DocumentController>>documentBusThis table is the central management object of theDocumentBus.protected StringidId of this object.protected List<String>inputModuleControllerIdsA list of Ids belonging toModuleControllerobjects on the input side.protected ReentrantLocklockThis lock is used for creating the conditionwaitUntilAllDocumentsArePutto let thepop(String)method wait until all documents have been put.protected MEMORY_POLICYmemPolicyprotected List<String>outputModuleControllerIdsA list of Ids belonging toModuleControllerobjects, which are on the output side of this queue.protected ConditionwaitUntilAllDocumentsArePutUsed to let thepop(String)method wait until all documents have been put.
-
Constructor Summary
Constructors Constructor Description DocumentBus(String inputModuleControllerId, String outputModuleControllerId)Creates an object of this type and sets the passes the given input controller and output controller.DocumentBus(String inputModuleControllerId, List<String> outputModuleControllerIds)Creates an object of this type and sets the passes the given input controller and output controller.DocumentBus(List<String> inputModuleControllerIds, String outputModuleControllerId)Creates an object of this type and sets the passes the given input controller and output controller.DocumentBus(List<String> inputModuleControllerIds, List<String> outputModuleControllerIds)Creates an object of this type and sets all passed in- and outputModuleControllerobjects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfinish(String inputControllerId)Sets the entry corresponding to given id to status finished, which means, that when all listedModuleControllerobjects on input side, are set to status finish, this queue is finished and no further documents are passed toModuleControllerobjects on output side.Hashtable<String,ConcurrentLinkedQueue<DocumentController>>getDocumentBus()Returns the table, which is the central management object of theDocumentBus.StringgetId()Creates an id for this object. the id consists of the in- and outputDocumentControllerobjects.List<String>getInputControllerIds()Returns a list of Ids belonging toModuleControllerobjects on the input side.MEMORY_POLICYgetMemPolicy()Returns the set memory policy.List<String>getOutputControllerIds()Returns a list of Ids belonging toModuleControllerobjects, which are on the output side of this queue.PepperJobImplgetPepperJob()Returns thePepperJobobject containing this objectprotected voidinit(List<String> inputModuleControllerIds, List<String> outputModuleControllerIds)Creates an object of this type and passes all outputModuleControllerobjects.protected voidinitDocumentBus(List<String> outputModuleControllerIds)Initializes the table, which is the central management object of theDocumentBus.booleanisFinished()Returns true, whether all inputModuleControllerobjects called thefinish(String)method and set this object to status finish.DocumentControllerpop(String outputControllerId)Returns aDocumentControllerobject, which is on first place of the internal queue (regarding the FIFO principle).DocumentControllerpop(String outputControllerId, boolean ignorePermissionForDocument)Returns aDocumentControllerobject, which is on first place of the internal queue (regarding the FIFO principle).voidput(DocumentController documentController)Adds the givenDocumentControllerobject to the queue.voidsetMemPolicy(MEMORY_POLICY memPolicy)Sets the memory policy.voidsetPepperJob(PepperJobImpl pepperJob)Sets thePepperJobobject containing this objectStringtoString()returns a String representation of this object.
-
-
-
Field Detail
-
outputModuleControllerIds
protected List<String> outputModuleControllerIds
A list of Ids belonging toModuleControllerobjects, which are on the output side of this queue. All these objects have to request a document, before this queue can get the status finished.
-
inputModuleControllerIds
protected List<String> inputModuleControllerIds
A list of Ids belonging toModuleControllerobjects on the input side. All these controllers have to notify this queue to be finished, before the queue can notify the controllers on the output side, that this queue is finished.
-
id
protected String id
Id of this object.
-
documentBus
protected volatile Hashtable<String,ConcurrentLinkedQueue<DocumentController>> documentBus
This table is the central management object of theDocumentBus. This table relates a queue containing document controllers to a identifier of aModuleControllerobject. Key= identifier, value= queue
-
memPolicy
protected volatile MEMORY_POLICY memPolicy
-
lock
protected ReentrantLock lock
This lock is used for creating the conditionwaitUntilAllDocumentsArePutto let thepop(String)method wait until all documents have been put.
-
waitUntilAllDocumentsArePut
protected Condition waitUntilAllDocumentsArePut
Used to let thepop(String)method wait until all documents have been put.
-
-
Constructor Detail
-
DocumentBus
public DocumentBus(String inputModuleControllerId, String outputModuleControllerId)
Creates an object of this type and sets the passes the given input controller and output controller.- Parameters:
inputModuleControllerId- identifier of controller, which produces documents for this busoutputModuleControllerId- identifier of controller, which consumes documents for this bus
-
DocumentBus
public DocumentBus(String inputModuleControllerId, List<String> outputModuleControllerIds)
Creates an object of this type and sets the passes the given input controller and output controller.- Parameters:
inputModuleControllerId- identifier of controller, which produces documents for this busoutputModuleControllerIds- list of identifier of controller, which consumes documents for this bus
-
DocumentBus
public DocumentBus(List<String> inputModuleControllerIds, String outputModuleControllerId)
Creates an object of this type and sets the passes the given input controller and output controller.- Parameters:
inputModuleControllerIds- list of identifier of controller, which produces documents for this busoutputModuleControllerId- identifier of controller, which consumes documents for this bus
-
DocumentBus
public DocumentBus(List<String> inputModuleControllerIds, List<String> outputModuleControllerIds)
Creates an object of this type and sets all passed in- and outputModuleControllerobjects. This is important, because anDocumentControllercan only be removed from queue, when all outputModuleControllerobjects requested theDocumentControllerobject.- Parameters:
inputModuleControllerIds- list of identifier of controller, which produces documents for this busoutputModuleControllerIds- list of identifier of controller, which consumes documents for this bus
-
-
Method Detail
-
init
protected void init(List<String> inputModuleControllerIds, List<String> outputModuleControllerIds)
Creates an object of this type and passes all outputModuleControllerobjects. This is important, because anDocumentControllercan only be removed from queue, when all outputModuleControllerobjects requested theDocumentControllerobject.- Parameters:
outputs-
-
getOutputControllerIds
public List<String> getOutputControllerIds()
Returns a list of Ids belonging toModuleControllerobjects, which are on the output side of this queue. All these objects have to request a document, before this queue can get the status finished.- Returns:
- list of all ids
-
getInputControllerIds
public List<String> getInputControllerIds()
Returns a list of Ids belonging toModuleControllerobjects on the input side. All these controllers have to notify this queue to be finished, before the queue can notify the controllers on the output side, that this queue is finished.- Returns:
- list of all ids
-
getId
public String getId()
Creates an id for this object. the id consists of the in- and outputDocumentControllerobjects.- Returns:
-
getPepperJob
public PepperJobImpl getPepperJob()
Returns thePepperJobobject containing this object- Returns:
PepperJobobject containing this
-
setPepperJob
public void setPepperJob(PepperJobImpl pepperJob)
Sets thePepperJobobject containing this object- Parameters:
pepperJob-PepperJobobject containing this
-
getDocumentBus
public Hashtable<String,ConcurrentLinkedQueue<DocumentController>> getDocumentBus()
Returns the table, which is the central management object of theDocumentBus. This table relates a queue containing document controllers to a identifier of aModuleControllerobject. Key= identifier, value= queue- Returns:
-
initDocumentBus
protected void initDocumentBus(List<String> outputModuleControllerIds)
Initializes the table, which is the central management object of theDocumentBus. This table relates a queue containing document controllers to a identifier of aModuleControllerobject. Key= identifier, value= queue.
Please take care not to call this method, when this object is already started, since this will confuse the started process.- Parameters:
outputModuleControllerIds- a list of ids of theModuleControllerobjects on the output side.
-
getMemPolicy
public MEMORY_POLICY getMemPolicy()
Returns the set memory policy.- Returns:
-
setMemPolicy
public void setMemPolicy(MEMORY_POLICY memPolicy)
Sets the memory policy. Don't change the memory policy, when job was started.- Parameters:
memPolicy-
-
finish
public void finish(String inputControllerId)
Sets the entry corresponding to given id to status finished, which means, that when all listedModuleControllerobjects on input side, are set to status finish, this queue is finished and no further documents are passed toModuleControllerobjects on output side.- Parameters:
inputControllerId- id of controller to be set to finish.
-
isFinished
public boolean isFinished()
Returns true, whether all inputModuleControllerobjects called thefinish(String)method and set this object to status finish.- Returns:
- if all input controllers called finished
-
put
public void put(DocumentController documentController)
Adds the givenDocumentControllerobject to the queue.- Parameters:
documentController- theDocumentControllerobject to be added to the queue.
-
pop
public DocumentController pop(String outputControllerId)
Returns aDocumentControllerobject, which is on first place of the internal queue (regarding the FIFO principle). When all registeredModuleControllerobjects popped theDocumentControllerobject, it will be removed from internal queue.
If the document, which is the one to be taken in queue is in sleep mode, it will be woken up, if thePepperJobImplgives the permission. Otherwise, this method waits for the permission.
Caution, call this method can take some time, since it waits for two conditions:- a document is waiting in the queue, and the preceding
PepperModulehas not finished all documents - the Pepper framework (more precisely the
PepperJobImpl) gives the permission to wake up the document, if it was in sleep mode
- Parameters:
moduleController- object requesting theDocumentControllerobject- Returns:
- head of the queue.
- a document is waiting in the queue, and the preceding
-
pop
public DocumentController pop(String outputControllerId, boolean ignorePermissionForDocument)
Returns aDocumentControllerobject, which is on first place of the internal queue (regarding the FIFO principle). When all registeredModuleControllerobjects popped theDocumentControllerobject, it will be removed from internal queue.
If the document, which is the one to be taken in queue is in sleep mode, it will be woken up, if thePepperJobImplgives the permission. Otherwise, this method waits for the permission.
Caution, call this method can take some time, since it waits for two conditions:- a document is waiting in the queue, and the preceding
PepperModulehas not finished all documents - the Pepper framework (more precisely the
PepperJobImpl) gives the permission to wake up the document, if it was in sleep mode
pop(String), ifignorePermissionForDocumentis set to true this method returns aDocumentControllerobject even if thePepperJobpermission does not allow to process a further document. This mechanism can be used, if aPepperModulehas an own control mechanism of sendingSDocuments to sleep.- Parameters:
outputControllerId- object requesting theDocumentControllerobjectignorePermissionForDocument- if set, a document will be returned even if the Pepper job gives no permission- Returns:
- head of the queue.
- a document is waiting in the queue, and the preceding
-
-