org.gcube.indexmanagement.common.mergesort
Class MergeSortPipe

java.lang.Object
  extended by org.gcube.indexmanagement.common.mergesort.MergeSortPipe

public class MergeSortPipe
extends Object

This class is the container for results that are produced by workers and are consumed by a MergeSorter. The MergeSorter must pause until all the queues of the active workers have at least one element to consume OR there is no active worker left. A worker must pause until >= AND it has at least one element in its queue. The MergeSorter must wake up the workers when > OR one queue was emptied.

Author:
bill

Constructor Summary
MergeSortPipe(int numberOfworkers)
          constructor
 
Method Summary
 void add(int workerID, ArrayList<MergeSortElement> elements)
          Adds a new elements' array in the queue
 void add(int workerID, MergeSortElement element)
          Adds a new element in the queue
 boolean areAllQueuesNonEmpty()
          checks if all the queues, of the active workers, have at least one element
 boolean canMergeSorterPause()
          checks if a MergeSorter can pause and let the workers do the processing, until there is enough data to do merge sorting, or there are more results than the results requested by the client, or there is no worker left
 boolean canWorkerPause(int workerID)
          checks if a specific worker can sleep
 long getGetUntil()
          gets the sum of the results requested by the client, until now
 MergeSortElement getNext()
           
 long getResultsRetrieved()
          gets the sum of the results retrieved
 long getResultsSent()
           
 boolean isActive(int workerID)
          returns the state of the workerID
 boolean isAnyWorkerLeft()
          checks if there is any worker left
 boolean isStoped()
          returns the stop flag
 boolean sendMergerNotification()
          checks if a MergeSorter must receive a notification.
 boolean sendWorkersNotification()
          checks if workers must receive notifications.
 void setGetUntil(long getUntil)
          sets the number of results requested by the client
 void setInActive(int workerID)
          sets the workerID worker as inactive
 void setResultsRetrieved(long resultsRetrieved)
          sets the resultsRetrieved
 void setStop()
          raises the stop flag
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MergeSortPipe

public MergeSortPipe(int numberOfworkers)
constructor

Parameters:
numberOfworkers - - the number of workers
Method Detail

setInActive

public void setInActive(int workerID)
sets the workerID worker as inactive

Parameters:
workerID -

isActive

public boolean isActive(int workerID)
returns the state of the workerID

Parameters:
workerID -
Returns:
true if workerID is active / false otherwise

getResultsRetrieved

public long getResultsRetrieved()
gets the sum of the results retrieved

Returns:
resultsRetrieved

setResultsRetrieved

public void setResultsRetrieved(long resultsRetrieved)
sets the resultsRetrieved

Parameters:
resultsRetrieved -

getResultsSent

public long getResultsSent()

getGetUntil

public long getGetUntil()
gets the sum of the results requested by the client, until now

Returns:
getUntil

setGetUntil

public void setGetUntil(long getUntil)
sets the number of results requested by the client

Parameters:
getUntil -

add

public void add(int workerID,
                ArrayList<MergeSortElement> elements)
Adds a new elements' array in the queue

Parameters:
workerID - - the ID of the owrker that adds the element
elements - - the elements to be added in the queue

getNext

public MergeSortElement getNext()

add

public void add(int workerID,
                MergeSortElement element)
Adds a new element in the queue

Parameters:
workerID - - the ID of the owrker that adds the element
element - - the element to be added in the queue

areAllQueuesNonEmpty

public boolean areAllQueuesNonEmpty()
checks if all the queues, of the active workers, have at least one element

Returns:
true if yes / false otherwise

isAnyWorkerLeft

public boolean isAnyWorkerLeft()
checks if there is any worker left

Returns:
true if yes / false otherwise

canWorkerPause

public boolean canWorkerPause(int workerID)
checks if a specific worker can sleep

Parameters:
workerID - - the ID of the worker
Returns:
true if yes / false otherwise

canMergeSorterPause

public boolean canMergeSorterPause()
checks if a MergeSorter can pause and let the workers do the processing, until there is enough data to do merge sorting, or there are more results than the results requested by the client, or there is no worker left

Returns:
true if yes / false otherwise

sendMergerNotification

public boolean sendMergerNotification()
checks if a MergeSorter must receive a notification. If we are in a state that the MergeSorter should not be paused then a notification must be sent.

Returns:
true if yes / false otherwise

sendWorkersNotification

public boolean sendWorkersNotification()
checks if workers must receive notifications. If there is at least one active queue that is empty or the results retrieved are less than the results requested by the client.

Returns:
true if yes / false otherwise

setStop

public void setStop()
raises the stop flag


isStoped

public boolean isStoped()
returns the stop flag

Returns:
the stop flag


Copyright © 2013. All Rights Reserved.