View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.tck.functional;
8   
9   import org.mule.api.MuleEventContext;
10  
11  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
12  
13  /**
14   * A test callback that counts the number of messages received.
15   */
16  public class CounterCallback implements EventCallback
17  {
18      private AtomicInteger callbackCount;
19  
20      public CounterCallback()
21      {
22          callbackCount = new AtomicInteger(0);
23      }
24  
25      public CounterCallback(AtomicInteger callbackCount)
26      {
27          this.callbackCount = callbackCount;
28      }
29  
30      public void eventReceived(MuleEventContext context, Object Component) throws Exception
31      {
32          incCallbackCount();
33      }
34  
35      /**
36       * Increment callback count.
37       * @return current count after increment
38       */
39      protected int incCallbackCount()
40      {
41          return callbackCount.incrementAndGet();
42      }
43  
44      public int getCallbackCount()
45      {
46          return callbackCount.intValue();
47      }
48  }