View Javadoc

1   /*
2    * $Id: TestComponent.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.tck.testmodels.services;
12  
13  import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  
17  public class TestComponent implements ITestComponent
18  {
19      public static final String EXCEPTION_MESSAGE = "Test Component fired an Exception";
20  
21      protected static final Log logger = LogFactory.getLog(TestComponent.class);
22  
23      protected AtomicInteger count = new AtomicInteger(0);
24  
25      public String receive(String message) throws Exception
26      {
27          logger.info("Received: " + message + " number: " + inc() + " in thread: "
28                      + Thread.currentThread().getName());
29          return "Received: " + message;
30      }
31      
32      public String receiveBytes(byte[] message) throws Exception
33      {
34          return receive(new String(message)); 
35      }
36  
37      public String throwsException(String message) throws Exception
38      {
39          throw new TestComponentException(EXCEPTION_MESSAGE);
40      }
41  
42      protected int inc()
43      {
44          return count.incrementAndGet();
45      }
46  
47  }