Coverage Report - org.mule.construct.SimpleFlowConstruct
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleFlowConstruct
0%
0/32
0%
0/10
0
 
 1  
 /*
 2  
  * $Id: SimpleFlowConstruct.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.construct;
 12  
 
 13  
 import org.mule.DefaultMuleEvent;
 14  
 import org.mule.RequestContext;
 15  
 import org.mule.api.MuleContext;
 16  
 import org.mule.api.MuleEvent;
 17  
 import org.mule.api.MuleException;
 18  
 import org.mule.api.MuleSession;
 19  
 import org.mule.api.config.ThreadingProfile;
 20  
 import org.mule.api.context.WorkManager;
 21  
 import org.mule.api.endpoint.InboundEndpoint;
 22  
 import org.mule.api.processor.MessageProcessor;
 23  
 import org.mule.api.processor.MessageProcessorBuilder;
 24  
 import org.mule.api.processor.MessageProcessorChainBuilder;
 25  
 import org.mule.construct.processor.FlowConstructStatisticsMessageProcessor;
 26  
 import org.mule.interceptor.LoggingInterceptor;
 27  
 import org.mule.interceptor.ProcessingTimeInterceptor;
 28  
 import org.mule.lifecycle.processor.ProcessIfStartedMessageProcessor;
 29  
 import org.mule.processor.OptionalAsyncInterceptingMessageProcessor;
 30  
 import org.mule.processor.chain.DefaultMessageProcessorChainBuilder;
 31  
 import org.mule.session.DefaultMuleSession;
 32  
 import org.mule.util.concurrent.ThreadNameHelper;
 33  
 
 34  
 import java.util.Collections;
 35  
 import java.util.List;
 36  
 
 37  
 /**
 38  
  * Simple implementation of {@link AbstractFlowConstruct} that allows a list of
 39  
  * {@link MessageProcessor}s that will be used to process messages to be configured.
 40  
  * These MessageProcessors are chained together using the
 41  
  * {@link DefaultMessageProcessorChainBuilder}.
 42  
  * <p/>
 43  
  * If not message processors are configured then the source message is simply
 44  
  * returned.
 45  
  */
 46  
 public class SimpleFlowConstruct extends AbstractFlowConstruct implements MessageProcessor
 47  
 {
 48  0
     protected List<MessageProcessor> messageProcessors = Collections.emptyList();
 49  
 
 50  
     protected WorkManager workManager;
 51  
 
 52  
     public SimpleFlowConstruct(String name, MuleContext muleContext)
 53  
     {
 54  0
         super(name, muleContext);
 55  0
     }
 56  
 
 57  
     @Override
 58  
     protected void configureMessageProcessors(MessageProcessorChainBuilder builder)
 59  
     {
 60  0
         if (threadingProfile == null)
 61  
         {
 62  0
             threadingProfile = muleContext.getDefaultServiceThreadingProfile();
 63  
         }
 64  
 
 65  0
         final String threadPrefix = ThreadNameHelper.flow(muleContext, getName());
 66  
 
 67  0
         builder.chain(new ProcessIfStartedMessageProcessor(this, getLifecycleState()));
 68  0
         builder.chain(new ProcessingTimeInterceptor());
 69  0
         builder.chain(new LoggingInterceptor());
 70  0
         builder.chain(new FlowConstructStatisticsMessageProcessor());
 71  0
         if (messageSource != null)
 72  
         {
 73  0
             builder.chain(new OptionalAsyncInterceptingMessageProcessor(threadingProfile, threadPrefix,
 74  
                 muleContext.getConfiguration().getShutdownTimeout()));
 75  
         }
 76  0
         for (Object processor : messageProcessors)
 77  
         {
 78  0
             if (processor instanceof MessageProcessor)
 79  
             {
 80  0
                 builder.chain((MessageProcessor) processor);
 81  
             }
 82  0
             else if (processor instanceof MessageProcessorBuilder)
 83  
             {
 84  0
                 builder.chain((MessageProcessorBuilder) processor);
 85  
             }
 86  
             else
 87  
             {
 88  0
                 throw new IllegalArgumentException(
 89  
                     "MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured");
 90  
             }
 91  
         }
 92  0
     }
 93  
 
 94  
     public void setThreadingProfile(ThreadingProfile threadingProfile)
 95  
     {
 96  0
         this.threadingProfile = threadingProfile;
 97  0
     }
 98  
 
 99  
     public void setMessageProcessors(List<MessageProcessor> messageProcessors)
 100  
     {
 101  0
         this.messageProcessors = messageProcessors;
 102  0
     }
 103  
 
 104  
     public List<MessageProcessor> getMessageProcessors()
 105  
     {
 106  0
         return messageProcessors;
 107  
     }
 108  
 
 109  
     @Deprecated
 110  
     public void setEndpoint(InboundEndpoint endpoint)
 111  
     {
 112  0
         this.messageSource = endpoint;
 113  0
     }
 114  
 
 115  
     @Override
 116  
     public String getConstructType()
 117  
     {
 118  0
         return "Flow";
 119  
     }
 120  
     
 121  
     public MuleEvent process(MuleEvent event) throws MuleException
 122  
     {
 123  0
         MuleSession calledSession = new DefaultMuleSession(event.getSession(), this);
 124  0
         MuleEvent newEvent = new DefaultMuleEvent(event.getMessage(), event.getEndpoint(), event, calledSession);
 125  0
         RequestContext.setEvent(newEvent);
 126  
         try
 127  
         {
 128  0
             return messageProcessorChain.process(newEvent);
 129  
         }
 130  
         finally
 131  
         {
 132  0
             RequestContext.setEvent(event);
 133  
         }
 134  
     }
 135  
 
 136  
 }