Coverage Report - org.mule.construct.SimpleFlowConstruct
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleFlowConstruct
0%
0/25
0%
0/10
0
 
 1  
 /*
 2  
  * $Id$
 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.construct;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.config.MuleConfiguration;
 15  
 import org.mule.api.config.ThreadingProfile;
 16  
 import org.mule.api.context.WorkManager;
 17  
 import org.mule.api.endpoint.InboundEndpoint;
 18  
 import org.mule.api.processor.MessageProcessor;
 19  
 import org.mule.api.processor.MessageProcessorBuilder;
 20  
 import org.mule.lifecycle.processor.ProcessIfStartedMessageProcessor;
 21  
 import org.mule.processor.OptionalAsyncInterceptingMessageProcessor;
 22  
 import org.mule.processor.builder.InterceptingChainMessageProcessorBuilder;
 23  
 
 24  
 import java.util.Collections;
 25  
 import java.util.List;
 26  
 
 27  
 /**
 28  
  * Simple implementation of {@link AbstractFlowConstruct} that allows a list of
 29  
  * {@link MessageProcessor}s that will be used to process messages to be configured.
 30  
  * These MessageProcessors are chained together using the
 31  
  * {@link InterceptingChainMessageProcessorBuilder}.
 32  
  * <p/>
 33  
  * If not message processors are configured then the source message is simply
 34  
  * returned.
 35  
  */
 36  
 public class SimpleFlowConstruct extends AbstractFlowConstruct
 37  
 {
 38  0
     protected List<MessageProcessor> messageProcessors = Collections.emptyList();
 39  
 
 40  
     protected ThreadingProfile threadingProfile;
 41  
 
 42  
     protected WorkManager workManager;
 43  
 
 44  
     public SimpleFlowConstruct(String name, MuleContext muleContext)
 45  
     {
 46  0
         super(name, muleContext);
 47  0
     }
 48  
 
 49  
     @Override
 50  
     protected void configureMessageProcessors(InterceptingChainMessageProcessorBuilder builder)
 51  
     {
 52  0
         if (threadingProfile == null)
 53  
         {
 54  0
             threadingProfile = muleContext.getDefaultServiceThreadingProfile();
 55  
         }
 56  
 
 57  0
         final MuleConfiguration config = muleContext.getConfiguration();
 58  0
         final boolean containerMode = config.isContainerMode();
 59  0
         final String threadPrefix = containerMode
 60  
                                                  ? String.format("[%s].flow.%s", config.getId(), getName())
 61  
                                                  : String.format("flow.%s", getName());
 62  
 
 63  0
         builder.chain(new ProcessIfStartedMessageProcessor(this, getLifecycleState()));
 64  0
         builder.chain(new OptionalAsyncInterceptingMessageProcessor(threadingProfile, threadPrefix,
 65  
             muleContext.getConfiguration().getShutdownTimeout()));
 66  
 
 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
     }
 84  
 
 85  
     public ThreadingProfile getThreadingProfile()
 86  
     {
 87  0
         return threadingProfile;
 88  
     }
 89  
 
 90  
     public void setThreadingProfile(ThreadingProfile threadingProfile)
 91  
     {
 92  0
         this.threadingProfile = threadingProfile;
 93  0
     }
 94  
 
 95  
     public void setMessageProcessors(List<MessageProcessor> messageProcessors)
 96  
     {
 97  0
         this.messageProcessors = messageProcessors;
 98  0
     }
 99  
 
 100  
     public List<MessageProcessor> getMessageProcessors()
 101  
     {
 102  0
         return messageProcessors;
 103  
     }
 104  
 
 105  
     @Deprecated
 106  
     public void setEndpoint(InboundEndpoint endpoint)
 107  
     {
 108  0
         this.messageSource = endpoint;
 109  0
     }
 110  
 
 111  
 }