24 lines
2.6 KiB
HTML
24 lines
2.6 KiB
HTML
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Listeners</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch09s03.xhtml" title="Backoff Policies"/><link rel="next" href="ch09s05.xhtml" title="Declarative Retry"/></head><body><header/><section class="section" title="Listeners" epub:type="subchapter" id="retryListeners"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Listeners</h2></div></div></div><p>Often it is useful to be able to receive additional callbacks for
|
|
cross cutting concerns across a number of different retries. For this
|
|
purpose Spring Batch provides the <code class="classname">RetryListener</code>
|
|
interface. The <code class="classname">RetryTemplate</code> allows users to
|
|
register <code class="classname">RetryListener</code>s, and they will be given
|
|
callbacks with the <code class="classname">RetryContext</code> and
|
|
<code class="classname">Throwable</code> where available during the
|
|
iteration.</p><p>The interface looks like this:</p><pre class="programlisting">public interface RetryListener {
|
|
|
|
void open(RetryContext context, RetryCallback<T> callback);
|
|
|
|
void onError(RetryContext context, RetryCallback<T> callback, Throwable e);
|
|
|
|
void close(RetryContext context, RetryCallback<T> callback, Throwable e);
|
|
}</pre><p>The <code class="methodname">open</code> and
|
|
<code class="methodname">close</code> callbacks come before and after the entire
|
|
retry in the simplest case and <code class="methodname">onError</code> applies to
|
|
the individual <code class="classname">RetryCallback</code> calls. The
|
|
<code class="methodname">close</code> method might also receive a
|
|
<code class="classname">Throwable</code>; if there has been an error it is the
|
|
last one thrown by the <code class="classname">RetryCallback</code>.</p><p>Note that when there is more than one listener, they are in a list,
|
|
so there is an order. In this case <code class="methodname">open</code> will be
|
|
called in the same order while <code class="methodname">onError</code> and
|
|
<code class="methodname">close</code> will be called in reverse order.</p></section><footer/></body></html> |