title: Camel Spring DSL Call a method on bean once all all files in a directory have been processed
body: <p>I am trying to achieve the following in Camel Spring DSL (Version 2.12.1).</p>
  
  <ul>
  <li>Read all files from a directory</li>
  <li>Process each file with an <code>indexer</code> bean</li>
  <li>Call a <code>finalizeRepository</code> method on the indexer bean once all files have been processed</li>
  </ul>
  
  <p>(Based on the answer supplied by Claus I have updated the code sample below with a working solution.)</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;route&gt;
      &lt;from uri="file:./dataToIndex" /&gt;
      &lt;bean ref="indexer" method="addDocument(${body}, ${headers.CamelFileNameOnly})" /&gt;
      &lt;when&gt;
          &lt;simple&gt;${headers.CamelBatchComplete} == true&lt;/simple&gt;
      &lt;bean ref="indexer" method="finalizeRepository" /&gt;
      &lt;/when&gt;
  &lt;/route&gt;
  </code></pre>
  
  <p>If the header <code>CamelBatchComplete</code> holds the value <code>true</code> the method <code>finalizeRepository</code> on the <code>indexer</code> bean will be called. The header is set to <code>true</code> once all documents in the <code>dataToIndex</code> directory have been processed. </p>
  
  <p>The only thing I am not quite certain about is the definition of <code>batch</code>. 
  Is a <code>batch</code> determined based on what is found during a single polling event (e.g. if 1k files are found in a directory then this constitutes the batch), or a pattern of polling event (i.e. a series of successfull polls with items followed by a poll without any items is considered a <code>batch</code>).    </p>