Package jadex.commons.future
Class CounterResultListener<E>
- java.lang.Object
-
- jadex.commons.future.CounterResultListener<E>
-
- All Implemented Interfaces:
IFunctionalExceptionListener
,IFunctionalResultListener<E>
,IResultListener<E>
,IUndoneResultListener<E>
public class CounterResultListener<E> extends java.lang.Object implements IResultListener<E>, IUndoneResultListener<E>
Counter result listener for counting a specified number of resultAvailable calls.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
cnt
The number of received callbacks.protected IResultListener<java.lang.Void>
delegate
The delegate result listener.protected boolean
ignorefailures
The ignore failure flag.protected IFunctionalResultListener<E>
intermediateResultListener
Listener that is called on intermediate results.protected boolean
notified
Flag to indicate that the delegate already has been notified.protected int
num
The number of sub listeners to wait for.protected boolean
undone
The undone flag.
-
Constructor Summary
Constructors Constructor Description CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<java.lang.Void> countReachedListener)
Create a new counter listener.CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalExceptionListener exListener)
Create a new counter listener.CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalResultListener<E> intermediateResultListener, IFunctionalExceptionListener exListener)
Create a new counter listener.CounterResultListener(int num, boolean ignorefailures, IResultListener<java.lang.Void> delegate)
Create a new counter listener.CounterResultListener(int num, IFunctionalResultListener<java.lang.Void> countReachedListener)
Create a new counter listener.CounterResultListener(int num, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalExceptionListener exListener)
Create a new counter listener.CounterResultListener(int num, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalResultListener<E> intermediateResultListener, IFunctionalExceptionListener exListener)
Create a new counter listener.CounterResultListener(int num, IResultListener<java.lang.Void> delegate)
Create a new counter listener.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
exceptionOccurred(java.lang.Exception exception)
Called when an exception occurred.void
exceptionOccurredIfUndone(java.lang.Exception exception)
Called when an exception occurred.int
getCnt()
Get the current number of received results.int
getNumber()
Get the number of results this Listener is waiting for.boolean
intermediateExceptionOccurred(java.lang.Exception exception)
Method that can be overridden to do sth. on each exception that occurs.void
intermediateResultAvailable(E result)
Method that can be overridden to do sth. on each result available call.boolean
isUndone()
Get the undone.void
resultAvailable(E result)
Called when the result is available.void
resultAvailableIfUndone(E result)
Called when the result is available.void
setNumber(int num)
Set the number.
-
-
-
Field Detail
-
num
protected int num
The number of sub listeners to wait for.
-
cnt
protected int cnt
The number of received callbacks.
-
delegate
protected IResultListener<java.lang.Void> delegate
The delegate result listener.
-
notified
protected boolean notified
Flag to indicate that the delegate already has been notified.
-
ignorefailures
protected boolean ignorefailures
The ignore failure flag.
-
undone
protected boolean undone
The undone flag.
-
intermediateResultListener
protected IFunctionalResultListener<E> intermediateResultListener
Listener that is called on intermediate results.
-
-
Constructor Detail
-
CounterResultListener
public CounterResultListener(int num, IFunctionalResultListener<java.lang.Void> countReachedListener)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.countReachedListener
- Functional listener called when the count is reached.
-
CounterResultListener
public CounterResultListener(int num, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalExceptionListener exListener)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.countReachedListener
- Functional listener called when the count is reached.exListener
- The listener that is called on exceptions. Passingnull
enables default exception logging.
-
CounterResultListener
public CounterResultListener(int num, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalResultListener<E> intermediateResultListener, IFunctionalExceptionListener exListener)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.countReachedListener
- Functional listener called when the count is reached.intermediateResultListener
- Functional listener called on intermediate results.exListener
- The listener that is called on exceptions. Passingnull
enables default exception logging.
-
CounterResultListener
public CounterResultListener(int num, IResultListener<java.lang.Void> delegate)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.
-
CounterResultListener
public CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<java.lang.Void> countReachedListener)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.ignorefailures
- Flag whether to ignore failures.countReachedListener
- Functional listener called when the count is reached.
-
CounterResultListener
public CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalExceptionListener exListener)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.ignorefailures
- Flag whether to ignore failures.countReachedListener
- Functional listener called when the count is reached.exListener
- The listener that is called on exceptions. Passingnull
enables default exception logging.
-
CounterResultListener
public CounterResultListener(int num, boolean ignorefailures, IFunctionalResultListener<java.lang.Void> countReachedListener, IFunctionalResultListener<E> intermediateResultListener, IFunctionalExceptionListener exListener)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.ignorefailures
- Flag whether to ignore failures.countReachedListener
- Functional listener called when the count is reached.intermediateResultListener
- Functional listener called on intermediate results, can benull
.exListener
- The listener that is called on exceptions. Passingnull
enables default exception logging.
-
CounterResultListener
public CounterResultListener(int num, boolean ignorefailures, IResultListener<java.lang.Void> delegate)
Create a new counter listener.- Parameters:
num
- The number of sub callbacks.
-
-
Method Detail
-
resultAvailable
public void resultAvailable(E result)
Called when the result is available.- Specified by:
resultAvailable
in interfaceIFunctionalResultListener<E>
- Parameters:
result
- The result.
-
exceptionOccurred
public void exceptionOccurred(java.lang.Exception exception)
Called when an exception occurred.- Specified by:
exceptionOccurred
in interfaceIFunctionalExceptionListener
- Parameters:
exception
- The exception.
-
intermediateResultAvailable
public void intermediateResultAvailable(E result)
Method that can be overridden to do sth. on each result available call.
-
intermediateExceptionOccurred
public boolean intermediateExceptionOccurred(java.lang.Exception exception)
Method that can be overridden to do sth. on each exception that occurs.- Returns:
- True, for retry the task (cnt is not increased);
-
getNumber
public int getNumber()
Get the number of results this Listener is waiting for.- Returns:
- The expected number of results.
-
setNumber
public void setNumber(int num)
Set the number.- Parameters:
num
- The number.
-
getCnt
public int getCnt()
Get the current number of received results.- Returns:
- Number of results.
-
resultAvailableIfUndone
public void resultAvailableIfUndone(E result)
Called when the result is available.- Specified by:
resultAvailableIfUndone
in interfaceIUndoneResultListener<E>
- Parameters:
result
- The result.
-
exceptionOccurredIfUndone
public void exceptionOccurredIfUndone(java.lang.Exception exception)
Called when an exception occurred.- Specified by:
exceptionOccurredIfUndone
in interfaceIUndoneResultListener<E>
- Parameters:
exception
- The exception.
-
isUndone
public boolean isUndone()
Get the undone.- Returns:
- The undone.
-
-