net.shibboleth.metadata.pipeline
Class SplitMergeStage<ItemType extends Item<?>>

java.lang.Object
  extended by net.shibboleth.utilities.java.support.component.AbstractDestructableInitializableComponent
      extended by net.shibboleth.utilities.java.support.component.AbstractDestructableIdentifiableInitializableComponent
          extended by net.shibboleth.metadata.pipeline.BaseStage<ItemType>
              extended by net.shibboleth.metadata.pipeline.SplitMergeStage<ItemType>
Type Parameters:
ItemType - type of items upon which this stage operates
All Implemented Interfaces:
Stage<ItemType>, net.shibboleth.utilities.java.support.component.Component, net.shibboleth.utilities.java.support.component.DestructableComponent, net.shibboleth.utilities.java.support.component.IdentifiableComponent, net.shibboleth.utilities.java.support.component.InitializableComponent

@ThreadSafe
public class SplitMergeStage<ItemType extends Item<?>>
extends BaseStage<ItemType>

A stage which splits a given collection and passes selected items to one pipeline and non-selected items to another. The selected and non-selected item pipelines are executed via the set ExecutorService and operate on collections that contains clones of the (non-)selected items.

This stage requires the following properties be set prior to initialization:

If no executorService is provided, one will be created using Executors.newFixedThreadPool(int) with 6 threads. If no collectionFactory is given, then SimpleItemCollectionFactory is used. If one or the other pipeline is null then no objects will be passed to it (obviously).


Field Summary
private  com.google.common.base.Supplier<Collection<ItemType>> collectionFactory
          Factory used to create the Item collection that is then given to the pipelines.
private  ExecutorService executorService
          Service used to execute the selected and/or non-selected item pipelines.
private  Logger log
          Class logger.
private  CollectionMergeStrategy mergeStrategy
          Strategy used to merge all the joined pipeline results in to the final Item collection.
private  Pipeline<ItemType> nonselectedItemPipeline
          Pipeline that receives the non-selected items.
private  Pipeline<ItemType> selectedItemPipeline
          Pipeline that receives the selected items.
private  com.google.common.base.Predicate<ItemType> selectionStrategy
          Strategy used to split the given item collection.
 
Constructor Summary
SplitMergeStage()
           
 
Method Summary
protected  void doDestroy()
          
protected  void doExecute(Collection<ItemType> itemCollection)
          Performs the stage processing on the given Item collection.
protected  void doInitialize()
          
protected  Future<Collection<? extends Item>> executePipeline(Pipeline<ItemType> pipeline, Collection<ItemType> items)
          Executes a pipeline.
 com.google.common.base.Supplier<Collection<ItemType>> getCollectionFactory()
          Gets the factory used to create the Item collection that is then given to the pipelines.
 CollectionMergeStrategy getCollectionMergeStrategy()
          Gets the strategy used to merge all the joined pipeline results in to the final Item collection.
 ExecutorService getExecutorService()
          Gets the executor service used to run the selected and non-selected item pipelines.
 Pipeline<ItemType> getNonselectedItemPipeline()
          Gets the pipeline that receives the non-selected items.
 Pipeline<ItemType> getSelectedItemPipeline()
          Gets the pipeline that receives the selected items.
 com.google.common.base.Predicate<ItemType> getSelectionStrategy()
          Gets the strategy used to split the given item collection.
 void setCollectionFactory(com.google.common.base.Supplier<Collection<ItemType>> factory)
          Sets the factory used to create the Item collection that is then given to the pipelines.
 void setCollectionMergeStrategy(CollectionMergeStrategy strategy)
          Sets the strategy used to merge all the joined pipeline results in to the final Item collection.
 void setExecutorService(ExecutorService service)
          Sets the executor service used to run the selected and non-selected item pipelines.
 void setNonselectedItemPipeline(Pipeline<ItemType> pipeline)
          Sets the pipeline that receives the non-selected items.
 void setSelectedItemPipeline(Pipeline<ItemType> pipeline)
          Sets the pipeline that receives the selected items.
 void setSelectionStrategy(com.google.common.base.Predicate<ItemType> strategy)
          Sets the strategy used to split the given item collection.
 
Methods inherited from class net.shibboleth.metadata.pipeline.BaseStage
execute, setId
 
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractDestructableIdentifiableInitializableComponent
getId
 
Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractDestructableInitializableComponent
destroy, initialize, isDestroyed, isInitialized
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.shibboleth.utilities.java.support.component.DestructableComponent
destroy, isDestroyed
 
Methods inherited from interface net.shibboleth.utilities.java.support.component.IdentifiableComponent
getId
 
Methods inherited from interface net.shibboleth.utilities.java.support.component.InitializableComponent
initialize, isInitialized
 

Field Detail

log

private final Logger log
Class logger.


executorService

private ExecutorService executorService
Service used to execute the selected and/or non-selected item pipelines.


collectionFactory

private com.google.common.base.Supplier<Collection<ItemType extends Item<?>>> collectionFactory
Factory used to create the Item collection that is then given to the pipelines.


selectionStrategy

private com.google.common.base.Predicate<ItemType extends Item<?>> selectionStrategy
Strategy used to split the given item collection.


selectedItemPipeline

private Pipeline<ItemType extends Item<?>> selectedItemPipeline
Pipeline that receives the selected items.


nonselectedItemPipeline

private Pipeline<ItemType extends Item<?>> nonselectedItemPipeline
Pipeline that receives the non-selected items.


mergeStrategy

private CollectionMergeStrategy mergeStrategy
Strategy used to merge all the joined pipeline results in to the final Item collection.

Constructor Detail

SplitMergeStage

public SplitMergeStage()
Method Detail

getExecutorService

@Nonnull
public ExecutorService getExecutorService()
Gets the executor service used to run the selected and non-selected item pipelines.

Returns:
executor service used to run the selected and non-selected item pipelines

setExecutorService

public void setExecutorService(@Nonnull
                               ExecutorService service)
Sets the executor service used to run the selected and non-selected item pipelines.

Parameters:
service - executor service used to run the selected and non-selected item pipelines

getCollectionFactory

@Nonnull
public com.google.common.base.Supplier<Collection<ItemType>> getCollectionFactory()
Gets the factory used to create the Item collection that is then given to the pipelines.

Returns:
factory used to create the Item collection that is then given to the pipelines

setCollectionFactory

public void setCollectionFactory(@Nonnull
                                 com.google.common.base.Supplier<Collection<ItemType>> factory)
Sets the factory used to create the Item collection that is then given to the pipelines.

Parameters:
factory - factory used to create the Item collection that is then given to the pipelines

getSelectionStrategy

@Nonnull
public com.google.common.base.Predicate<ItemType> getSelectionStrategy()
Gets the strategy used to split the given item collection.

Returns:
strategy used to split the given item collection

setSelectionStrategy

public void setSelectionStrategy(@Nonnull
                                 com.google.common.base.Predicate<ItemType> strategy)
Sets the strategy used to split the given item collection.

Parameters:
strategy - strategy used to split the given item collection, never null

getSelectedItemPipeline

@Nullable
public Pipeline<ItemType> getSelectedItemPipeline()
Gets the pipeline that receives the selected items.

Returns:
pipeline that receives the selected items

setSelectedItemPipeline

public void setSelectedItemPipeline(@Nullable
                                    Pipeline<ItemType> pipeline)
Sets the pipeline that receives the selected items.

Parameters:
pipeline - pipeline that receives the selected items

getNonselectedItemPipeline

@Nullable
public Pipeline<ItemType> getNonselectedItemPipeline()
Gets the pipeline that receives the non-selected items.

Returns:
pipeline that receives the non-selected items

setNonselectedItemPipeline

public void setNonselectedItemPipeline(@Nullable
                                       Pipeline<ItemType> pipeline)
Sets the pipeline that receives the non-selected items.

Parameters:
pipeline - pipeline that receives the non-selected items

getCollectionMergeStrategy

@Nonnull
public CollectionMergeStrategy getCollectionMergeStrategy()
Gets the strategy used to merge all the joined pipeline results in to the final Item collection.

Returns:
strategy used to merge all the joined pipeline results in to the final Item collection, never null

setCollectionMergeStrategy

public void setCollectionMergeStrategy(@Nonnull
                                       CollectionMergeStrategy strategy)
Sets the strategy used to merge all the joined pipeline results in to the final Item collection.

Parameters:
strategy - strategy used to merge all the joined pipeline results in to the final Item collection, never null

doExecute

protected void doExecute(@Nonnull@NonnullElements
                         Collection<ItemType> itemCollection)
                  throws StageProcessingException
Performs the stage processing on the given Item collection.

The stage is guaranteed to be have been initialized and not destroyed when this is invoked.

Specified by:
doExecute in class BaseStage<ItemType extends Item<?>>
Parameters:
itemCollection - collection to be processed
Throws:
StageProcessingException - thrown if there is an unrecoverable problem when processing the stage

executePipeline

@Nonnull
protected Future<Collection<? extends Item>> executePipeline(Pipeline<ItemType> pipeline,
                                                                     Collection<ItemType> items)
Executes a pipeline.

Parameters:
pipeline - the pipeline, may be null
items - the collections of items
Returns:
the token representing the background execution of the pipeline

doDestroy

protected void doDestroy()

Overrides:
doDestroy in class net.shibboleth.utilities.java.support.component.AbstractDestructableInitializableComponent

doInitialize

protected void doInitialize()
                     throws net.shibboleth.utilities.java.support.component.ComponentInitializationException

Overrides:
doInitialize in class net.shibboleth.utilities.java.support.component.AbstractDestructableIdentifiableInitializableComponent
Throws:
net.shibboleth.utilities.java.support.component.ComponentInitializationException


Copyright © 1999-2012. All Rights Reserved.