Class Batcher<T>

java.lang.Object
org.oddjob.beanbus.destinations.Batcher<T>
Type Parameters:
T - The type of bean being batched.
All Implemented Interfaces:
Flushable, AutoCloseable, Runnable, Consumer<T>, BusFilter<T,Collection<T>>, Outbound<Collection<T>>

public class Batcher<T> extends Object implements Consumer<T>, BusFilter<T,Collection<T>>, Flushable, Runnable, AutoCloseable
Author:
Rob

Description

Provide batching of beans.

Example

Create Batches of 2 beans.

<oddjob>

    <job>

        <bus:bus id="bean-bus" xmlns:bus="oddjob:beanbus">

            <of>

                <bus:driver>

                    <values>

                        <list>

                            <values>

                                <value value="Apple"/>

                                <value value="Orange"/>

                                <value value="Pear"/>

                                <value value="Kiwi"/>

                                <value value="Banana"/>

                            </values>

                        </list>

                    </values>

                </bus:driver>

                <bean id="batcher" batchSize="2" class="org.oddjob.beanbus.destinations.Batcher"/>

                <bus:collect id="results"/>

            </of>

        </bus:bus>

    </job>

</oddjob>
  • Constructor Details

    • Batcher

      public Batcher()
  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • reset

      public void reset()
    • accept

      public void accept(T bean)
      Specified by:
      accept in interface Consumer<T>
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Throws:
      IOException
    • dispatch

      protected void dispatch()
      Dispatch the beans. Called when a batch is ready of a trip is ending.
    • getCount

      public int getCount()
    • getSize

      public int getSize()
    • getBatchSize

      public int getBatchSize()
    • setBatchSize

      public void setBatchSize(int batchSize)
    • getTo

      public Consumer<? super Collection<T>> getTo()
    • setTo

      public void setTo(Consumer<? super Collection<T>> next)
      Description copied from interface: Outbound
      Set the out bound destination.
      Specified by:
      setTo in interface Outbound<T>
      Parameters:
      next -
    • getName

      public String getName()
    • setName

      public void setName(String name)
    • toString

      public String toString()
      Overrides:
      toString in class Object