org.apache.camel.builder
Class NotifyBuilder

java.lang.Object
  extended by org.apache.camel.builder.NotifyBuilder

public class NotifyBuilder
extends Object

A builder to build an expression based on EventNotifier notifications about Exchange being routed.

This builder can be used for testing purposes where you want to know when a test is supposed to be done. The idea is that you can build an expression that explains when the test is done. For example when Camel have finished routing 5 messages. You can then in your test await for this condition to occur.

Version:

Constructor Summary
NotifyBuilder(CamelContext context)
          Creates a new builder.
 
Method Summary
 NotifyBuilder and()
          Prepares to append an additional expression using the and operator.
 NotifyBuilder create()
          Creates the expression this builder should use for matching.
 ExpressionClauseSupport<NotifyBuilder> filter()
          Optionally a filter to only allow matching Exchange to be used for matching.
 NotifyBuilder filter(Predicate predicate)
          Optionally a filter to only allow matching Exchange to be used for matching.
 NotifyBuilder from(String endpointUri)
          Optionally a from endpoint which means that this expression should only be based on Exchange which is originated from the particular endpoint(s).
 NotifyBuilder fromRoute(String routeId)
          Optionally a from route which means that this expression should only be based on Exchange which is originated from the particular route(s).
 boolean matches()
          Does all the expression match?

This operation will return immediately which means it can be used for testing at this very moment.

 boolean matches(long timeout, TimeUnit timeUnit)
          Does all the expression match?

This operation will wait until the match is true or otherwise a timeout occur which means false will be returned.

 boolean matchesMockWaitTime()
          Does all the expression match?

This operation will wait until the match is true or otherwise a timeout occur which means false will be returned.

 NotifyBuilder not()
          Prepares to append an additional expression using the not operator.
 NotifyBuilder or()
          Prepares to append an additional expression using the or operator.
 void reset()
          Resets the notifier.
 String toString()
           
 NotifyBuilder wereSentTo(String endpointUri)
          Optionally a sent to endpoint which means that this expression should only be based on Exchange which has been sent to the given endpoint uri.
 NotifyBuilder whenAllDoneMatches(Predicate predicate)
          Sets a condition that all done Exchange should match the Predicate
 NotifyBuilder whenAllReceivedMatches(Predicate predicate)
          Sets a condition that all received Exchange should match the Predicate
 NotifyBuilder whenAnyDoneMatches(Predicate predicate)
          Sets a condition that any done Exchange should match the Predicate
 NotifyBuilder whenAnyReceivedMatches(Predicate predicate)
          Sets a condition that any received Exchange should match the Predicate
 NotifyBuilder whenBodiesDone(Object... bodies)
          Sets a condition that the bodies is expected to be done in the order as well.
 NotifyBuilder whenBodiesReceived(Object... bodies)
          Sets a condition that the bodies is expected to be received in the order as well.
 NotifyBuilder whenCompleted(int number)
          Sets a condition when number of Exchange has been completed.
 NotifyBuilder whenDone(int number)
          Sets a condition when number of Exchange is done being processed.
 NotifyBuilder whenDoneByIndex(int index)
          Sets a condition when tne n'th (by index) Exchange is done being processed.
 NotifyBuilder whenDoneNotSatisfied(MockEndpoint mock)
          Sets a condition when the provided mock is not satisfied based on Exchange being sent to it when they are done.
 NotifyBuilder whenDoneSatisfied(MockEndpoint mock)
          Sets a condition when the provided mock is satisfied based on Exchange being sent to it when they are done.
 NotifyBuilder whenExactBodiesDone(Object... bodies)
          Sets a condition that the bodies is expected to be done in the order as well.
 NotifyBuilder whenExactBodiesReceived(Object... bodies)
          Sets a condition that the bodies is expected to be received in the order as well.
 NotifyBuilder whenExactlyCompleted(int number)
          Sets a condition when number of Exchange has been completed.
 NotifyBuilder whenExactlyDone(int number)
          Sets a condition when number of Exchange is done being processed.
 NotifyBuilder whenExactlyFailed(int number)
          Sets a condition when number of Exchange has failed.
 NotifyBuilder whenFailed(int number)
          Sets a condition when number of Exchange has failed.
 NotifyBuilder whenReceived(int number)
          Sets a condition when number of Exchange has been received.
 NotifyBuilder whenReceivedNotSatisfied(MockEndpoint mock)
          Sets a condition when the provided mock is not satisfied based on Exchange being sent to it when they are received.
 NotifyBuilder whenReceivedSatisfied(MockEndpoint mock)
          Sets a condition when the provided mock is satisfied based on Exchange being sent to it when they are received.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NotifyBuilder

public NotifyBuilder(CamelContext context)
Creates a new builder.

Parameters:
context - the Camel context
Method Detail

from

public NotifyBuilder from(String endpointUri)
Optionally a from endpoint which means that this expression should only be based on Exchange which is originated from the particular endpoint(s).

Parameters:
endpointUri - uri of endpoint or pattern (see the EndpointHelper javadoc)
Returns:
the builder
See Also:
EndpointHelper.matchEndpoint(org.apache.camel.CamelContext, String, String)

fromRoute

public NotifyBuilder fromRoute(String routeId)
Optionally a from route which means that this expression should only be based on Exchange which is originated from the particular route(s).

Parameters:
routeId - id of route or pattern (see the EndpointHelper javadoc)
Returns:
the builder
See Also:
EndpointHelper.matchEndpoint(org.apache.camel.CamelContext, String, String)

filter

public NotifyBuilder filter(Predicate predicate)
Optionally a filter to only allow matching Exchange to be used for matching.

Parameters:
predicate - the predicate to use for the filter
Returns:
the builder

filter

public ExpressionClauseSupport<NotifyBuilder> filter()
Optionally a filter to only allow matching Exchange to be used for matching.

Returns:
the builder

wereSentTo

public NotifyBuilder wereSentTo(String endpointUri)
Optionally a sent to endpoint which means that this expression should only be based on Exchange which has been sent to the given endpoint uri.

Notice the Exchange may have been sent to other endpoints as well. This condition will match if the Exchange has been sent at least once to the given endpoint.

Parameters:
endpointUri - uri of endpoint or pattern (see the EndpointHelper javadoc)
Returns:
the builder
See Also:
EndpointHelper.matchEndpoint(org.apache.camel.CamelContext, String, String)

whenReceived

public NotifyBuilder whenReceived(int number)
Sets a condition when number of Exchange has been received.

The number matching is at least based which means that if more messages received it will match also.

Parameters:
number - at least number of messages
Returns:
the builder

whenDone

public NotifyBuilder whenDone(int number)
Sets a condition when number of Exchange is done being processed.

The number matching is at least based which means that if more messages received it will match also.

The difference between done and completed is that done can also include failed messages, where as completed is only successful processed messages.

Parameters:
number - at least number of messages
Returns:
the builder

whenDoneByIndex

public NotifyBuilder whenDoneByIndex(int index)
Sets a condition when tne n'th (by index) Exchange is done being processed.

The difference between done and completed is that done can also include failed messages, where as completed is only successful processed messages.

Parameters:
index - the message by index to be done
Returns:
the builder

whenCompleted

public NotifyBuilder whenCompleted(int number)
Sets a condition when number of Exchange has been completed.

The number matching is at least based which means that if more messages received it will match also.

The difference between done and completed is that done can also include failed messages, where as completed is only successful processed messages.

Parameters:
number - at least number of messages
Returns:
the builder

whenFailed

public NotifyBuilder whenFailed(int number)
Sets a condition when number of Exchange has failed.

The number matching is at least based which means that if more messages received it will match also.

Parameters:
number - at least number of messages
Returns:
the builder

whenExactlyDone

public NotifyBuilder whenExactlyDone(int number)
Sets a condition when number of Exchange is done being processed.

messages, where as completed is only successful processed messages.

Parameters:
number - exactly number of messages
Returns:
the builder

whenExactlyCompleted

public NotifyBuilder whenExactlyCompleted(int number)
Sets a condition when number of Exchange has been completed.

The difference between done and completed is that done can also include failed messages, where as completed is only successful processed messages.

Parameters:
number - exactly number of messages
Returns:
the builder

whenExactlyFailed

public NotifyBuilder whenExactlyFailed(int number)
Sets a condition when number of Exchange has failed.

Parameters:
number - exactly number of messages
Returns:
the builder

whenAnyReceivedMatches

public NotifyBuilder whenAnyReceivedMatches(Predicate predicate)
Sets a condition that any received Exchange should match the Predicate

Parameters:
predicate - the predicate
Returns:
the builder

whenAnyDoneMatches

public NotifyBuilder whenAnyDoneMatches(Predicate predicate)
Sets a condition that any done Exchange should match the Predicate

Parameters:
predicate - the predicate
Returns:
the builder

whenAllReceivedMatches

public NotifyBuilder whenAllReceivedMatches(Predicate predicate)
Sets a condition that all received Exchange should match the Predicate

Parameters:
predicate - the predicate
Returns:
the builder

whenAllDoneMatches

public NotifyBuilder whenAllDoneMatches(Predicate predicate)
Sets a condition that all done Exchange should match the Predicate

Parameters:
predicate - the predicate
Returns:
the builder

whenDoneSatisfied

public NotifyBuilder whenDoneSatisfied(MockEndpoint mock)
Sets a condition when the provided mock is satisfied based on Exchange being sent to it when they are done.

The idea is that you can use Mock for setting fine grained expectations and then use that together with this builder. The mock provided does NOT have to already exist in the route. You can just create a new pseudo mock and this builder will send the done Exchange to it. So its like adding the mock to the end of your route(s).

Parameters:
mock - the mock
Returns:
the builder

whenReceivedSatisfied

public NotifyBuilder whenReceivedSatisfied(MockEndpoint mock)
Sets a condition when the provided mock is satisfied based on Exchange being sent to it when they are received.

The idea is that you can use Mock for setting fine grained expectations and then use that together with this builder. The mock provided does NOT have to already exist in the route. You can just create a new pseudo mock and this builder will send the done Exchange to it. So its like adding the mock to the end of your route(s).

Parameters:
mock - the mock
Returns:
the builder

whenReceivedNotSatisfied

public NotifyBuilder whenReceivedNotSatisfied(MockEndpoint mock)
Sets a condition when the provided mock is not satisfied based on Exchange being sent to it when they are received.

The idea is that you can use Mock for setting fine grained expectations and then use that together with this builder. The mock provided does NOT have to already exist in the route. You can just create a new pseudo mock and this builder will send the done Exchange to it. So its like adding the mock to the end of your route(s).

Parameters:
mock - the mock
Returns:
the builder

whenDoneNotSatisfied

public NotifyBuilder whenDoneNotSatisfied(MockEndpoint mock)
Sets a condition when the provided mock is not satisfied based on Exchange being sent to it when they are done.

The idea is that you can use Mock for setting fine grained expectations and then use that together with this builder. The mock provided does NOT have to already exist in the route. You can just create a new pseudo mock and this builder will send the done Exchange to it. So its like adding the mock to the end of your route(s).

Parameters:
mock - the mock
Returns:
the builder

whenBodiesReceived

public NotifyBuilder whenBodiesReceived(Object... bodies)
Sets a condition that the bodies is expected to be received in the order as well.

This condition will discard any additional messages. If you need a more strict condition then use whenExactBodiesReceived(Object...)

Parameters:
bodies - the expected bodies
Returns:
the builder
See Also:
whenExactBodiesReceived(Object...)

whenBodiesDone

public NotifyBuilder whenBodiesDone(Object... bodies)
Sets a condition that the bodies is expected to be done in the order as well.

This condition will discard any additional messages. If you need a more strict condition then use whenExactBodiesDone(Object...)

Parameters:
bodies - the expected bodies
Returns:
the builder
See Also:
whenExactBodiesDone(Object...)

whenExactBodiesReceived

public NotifyBuilder whenExactBodiesReceived(Object... bodies)
Sets a condition that the bodies is expected to be received in the order as well.

This condition is strict which means that it only expect that exact number of bodies

Parameters:
bodies - the expected bodies
Returns:
the builder
See Also:
whenBodiesReceived(Object...)

whenExactBodiesDone

public NotifyBuilder whenExactBodiesDone(Object... bodies)
Sets a condition that the bodies is expected to be done in the order as well.

This condition is strict which means that it only expect that exact number of bodies

Parameters:
bodies - the expected bodies
Returns:
the builder
See Also:
whenExactBodiesDone(Object...)

and

public NotifyBuilder and()
Prepares to append an additional expression using the and operator.

Returns:
the builder

or

public NotifyBuilder or()
Prepares to append an additional expression using the or operator.

Returns:
the builder

not

public NotifyBuilder not()
Prepares to append an additional expression using the not operator.

Returns:
the builder

create

public NotifyBuilder create()
Creates the expression this builder should use for matching.

You must call this method when you are finished building the expressions.

Returns:
the created builder ready for matching

matches

public boolean matches()
Does all the expression match?

This operation will return immediately which means it can be used for testing at this very moment.

Returns:
true if matching, false otherwise

matches

public boolean matches(long timeout,
                       TimeUnit timeUnit)
Does all the expression match?

This operation will wait until the match is true or otherwise a timeout occur which means false will be returned.

Parameters:
timeout - the timeout value
timeUnit - the time unit
Returns:
true if matching, false otherwise due to timeout

matchesMockWaitTime

public boolean matchesMockWaitTime()
Does all the expression match?

This operation will wait until the match is true or otherwise a timeout occur which means false will be returned.

The timeout value is by default 10 seconds. But it will use the highest maximum result wait time from the configured mocks, if such a value has been configured.

This method is convenient to use in unit tests to have it adhere and wait as long as the mock endpoints.

Returns:
true if matching, false otherwise due to timeout

reset

public void reset()
Resets the notifier.


toString

public String toString()
Overrides:
toString in class Object


Apache CAMEL