Class BusLimit<F>

java.lang.Object
org.oddjob.beanbus.destinations.BusLimit<F>
Type Parameters:
F -
All Implemented Interfaces:
Consumer<F>, BusFilter<F,F>, Outbound<F>, Service, Stoppable

public class BusLimit<F> extends Object implements Service, BusFilter<F,F>
Author:
rob

Description

Only allow a certain number of beans passed. When the limit is reached the Bus will be Stopped. Any beans arriving while the bus is stopping will be ignored.

Example

Limit the Bus to 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="Banana"/>

                            </values>

                        </list>

                    </values>

                </bus:driver>

                <bus:collect id="before" name="Beans Before"/>

                <bus:limit id="only-filter" limit="2"/>

                <bus:collect id="results" name="Beans After"/>

            </of>

        </bus:bus>

    </job>

</oddjob>
  • Constructor Details

    • BusLimit

      public BusLimit()
  • Method Details

    • stop

      public void stop() throws FailedToStopException
      Description copied from interface: Stoppable
      Stop executing. This method should not return until the Stoppable has actually stopped.
      Specified by:
      stop in interface Stoppable
      Throws:
      FailedToStopException
    • start

      public void start() throws Exception
      Description copied from interface: Service
      Start the service.
      Specified by:
      start in interface Service
      Throws:
      Exception - If the service can't be started.
    • accept

      public void accept(F from)
      Specified by:
      accept in interface Consumer<F>
    • getLimit

      public int getLimit()
    • setLimit

      public void setLimit(int limit)
    • getCount

      public int getCount()
    • setBusConductor

      @Inject public void setBusConductor(BusConductor busConductor)
    • setTo

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

      public String getName()
    • setName

      public void setName(String name)
    • toString

      public String toString()
      Overrides:
      toString in class Object