Coverage Report - org.mule.config.spring.factories.AsyncMessageProcessorsFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
AsyncMessageProcessorsFactoryBean
0%
0/26
0%
0/8
0
 
 1  
 /*
 2  
  * $Id: AsyncMessageProcessorsFactoryBean.java 20531 2010-12-08 21:34:21Z dzapata $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.config.spring.factories;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.NamedObject;
 15  
 import org.mule.api.config.MuleConfiguration;
 16  
 import org.mule.api.config.ThreadingProfile;
 17  
 import org.mule.api.context.MuleContextAware;
 18  
 import org.mule.api.processor.MessageProcessor;
 19  
 import org.mule.api.processor.MessageProcessorBuilder;
 20  
 import org.mule.processor.AsyncInterceptingMessageProcessor;
 21  
 import org.mule.processor.chain.DefaultMessageProcessorChainBuilder;
 22  
 import org.mule.util.concurrent.ThreadNameHelper;
 23  
 
 24  
 import java.util.List;
 25  
 
 26  
 import org.springframework.beans.factory.FactoryBean;
 27  
 
 28  0
 public class AsyncMessageProcessorsFactoryBean implements FactoryBean, MuleContextAware, NamedObject
 29  
 {
 30  
 
 31  
     protected MuleContext muleContext;
 32  
 
 33  
     protected List messageProcessors;
 34  
     protected ThreadingProfile threadingProfile;
 35  
     protected String name;
 36  
 
 37  
     public Class getObjectType()
 38  
     {
 39  0
         return MessageProcessor.class;
 40  
     }
 41  
 
 42  
     public void setThreadingProfile(ThreadingProfile threadingProfile)
 43  
     {
 44  0
         this.threadingProfile = threadingProfile;
 45  0
     }
 46  
 
 47  
     public void setMessageProcessors(List messageProcessors)
 48  
     {
 49  0
         this.messageProcessors = messageProcessors;
 50  0
     }
 51  
 
 52  
     public Object getObject() throws Exception
 53  
     {
 54  0
         if (threadingProfile == null)
 55  
         {
 56  0
             threadingProfile = muleContext.getDefaultThreadingProfile();
 57  
         }
 58  
 
 59  0
         DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder();
 60  0
         final MuleConfiguration config = muleContext.getConfiguration();
 61  0
         final String threadPrefix = ThreadNameHelper.asyncProcessor(muleContext, name);
 62  
 
 63  0
         AsyncInterceptingMessageProcessor asyncProcessor = new AsyncInterceptingMessageProcessor(threadingProfile,
 64  
                                                                                                  threadPrefix,
 65  
                                                                                                  config.getShutdownTimeout());
 66  0
         builder.chain(asyncProcessor);
 67  0
         for (Object processor : messageProcessors)
 68  
         {
 69  0
             if (processor instanceof MessageProcessor)
 70  
             {
 71  0
                 builder.chain((MessageProcessor) processor);
 72  
             }
 73  0
             else if (processor instanceof MessageProcessorBuilder)
 74  
             {
 75  0
                 builder.chain((MessageProcessorBuilder) processor);
 76  
             }
 77  
             else
 78  
             {
 79  0
                 throw new IllegalArgumentException(
 80  
                     "MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured");
 81  
             }
 82  
         }
 83  0
         return builder.build();
 84  
     }
 85  
 
 86  
     public boolean isSingleton()
 87  
     {
 88  0
         return false;
 89  
     }
 90  
 
 91  
     public void setMuleContext(MuleContext context)
 92  
     {
 93  0
         this.muleContext = context;
 94  0
     }
 95  
 
 96  
     public String getName()
 97  
     {
 98  0
         return name;
 99  
     }
 100  
 
 101  
     public void setName(String name)
 102  
     {
 103  0
         this.name = name;
 104  0
     }
 105  
 
 106  
 }