Coverage Report - org.mule.construct.SimpleFlowConstruct
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleFlowConstruct
0%
0/41
0%
0/12
0
 
 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.construct;
 8  
 
 9  
 import org.mule.DefaultMuleEvent;
 10  
 import org.mule.RequestContext;
 11  
 import org.mule.api.MuleContext;
 12  
 import org.mule.api.MuleEvent;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.MuleSession;
 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.api.processor.MessageProcessorChainBuilder;
 21  
 import org.mule.construct.processor.FlowConstructStatisticsMessageProcessor;
 22  
 import org.mule.interceptor.LoggingInterceptor;
 23  
 import org.mule.interceptor.ProcessingTimeInterceptor;
 24  
 import org.mule.processor.OptionalAsyncInterceptingMessageProcessor;
 25  
 import org.mule.processor.chain.DefaultMessageProcessorChainBuilder;
 26  
 import org.mule.routing.requestreply.ReplyToAsyncProcessor;
 27  
 import org.mule.session.DefaultMuleSession;
 28  
 import org.mule.util.concurrent.ThreadNameHelper;
 29  
 
 30  
 import java.util.Collections;
 31  
 import java.util.List;
 32  
 
 33  
 /**
 34  
  * Simple implementation of {@link AbstractFlowConstruct} that allows a list of
 35  
  * {@link MessageProcessor}s that will be used to process messages to be configured.
 36  
  * These MessageProcessors are chained together using the
 37  
  * {@link DefaultMessageProcessorChainBuilder}.
 38  
  * <p/>
 39  
  * If not message processors are configured then the source message is simply
 40  
  * returned.
 41  
  */
 42  
 public class SimpleFlowConstruct extends AbstractFlowConstruct implements MessageProcessor
 43  
 {
 44  0
     protected List<MessageProcessor> messageProcessors = Collections.emptyList();
 45  
 
 46  
     protected WorkManager workManager;
 47  
 
 48  
     public SimpleFlowConstruct(String name, MuleContext muleContext)
 49  
     {
 50  0
         super(name, muleContext);
 51  0
     }
 52  
 
 53  
     @Override
 54  
     protected void configureMessageProcessors(MessageProcessorChainBuilder builder)
 55  
     {
 56  0
         if (threadingProfile == null)
 57  
         {
 58  0
             threadingProfile = muleContext.getDefaultServiceThreadingProfile();
 59  
         }
 60  
 
 61  0
         final String threadPrefix = ThreadNameHelper.flow(muleContext, getName());
 62  
 
 63  0
         builder.chain(new ProcessIfPipelineStartedMessageProcessor());
 64  0
         builder.chain(new ProcessingTimeInterceptor());
 65  0
         builder.chain(new LoggingInterceptor());
 66  0
         builder.chain(new FlowConstructStatisticsMessageProcessor());
 67  0
         if (messageSource != null)
 68  
         {
 69  0
             builder.chain(new OptionalAsyncInterceptingMessageProcessor(threadingProfile, threadPrefix,
 70  
                 muleContext.getConfiguration().getShutdownTimeout()));
 71  
         }
 72  0
         for (Object processor : messageProcessors)
 73  
         {
 74  0
             if (processor instanceof MessageProcessor)
 75  
             {
 76  0
                 builder.chain((MessageProcessor) processor);
 77  
             }
 78  0
             else if (processor instanceof MessageProcessorBuilder)
 79  
             {
 80  0
                 builder.chain((MessageProcessorBuilder) processor);
 81  
             }
 82  
             else
 83  
             {
 84  0
                 throw new IllegalArgumentException(
 85  
                     "MessageProcessorBuilder should only have MessageProcessor's or MessageProcessorBuilder's configured");
 86  
             }
 87  
         }
 88  0
         builder.chain(new ReplyToAsyncProcessor());
 89  0
     }
 90  
 
 91  
     public void setThreadingProfile(ThreadingProfile threadingProfile)
 92  
     {
 93  0
         this.threadingProfile = threadingProfile;
 94  0
     }
 95  
 
 96  
     public void setMessageProcessors(List<MessageProcessor> messageProcessors)
 97  
     {
 98  0
         this.messageProcessors = messageProcessors;
 99  0
     }
 100  
 
 101  
     public List<MessageProcessor> getMessageProcessors()
 102  
     {
 103  0
         return messageProcessors;
 104  
     }
 105  
 
 106  
     /**
 107  
      * @deprecated use setMessageSource(MessageSource) instead
 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,
 125  
             calledSession);
 126  0
         RequestContext.setEvent(newEvent);
 127  
         try
 128  
         {
 129  0
             MuleEvent result = messageProcessorChain.process(newEvent);
 130  0
             if (result != null)
 131  
             {
 132  0
                 result.getMessage().release();
 133  
             }
 134  0
             return result;
 135  
         }
 136  0
         catch (Exception e)
 137  
         {
 138  0
             MuleEvent resultEvent = getExceptionListener().handleException(e, newEvent);
 139  0
             event.getSession().merge(resultEvent.getSession());
 140  0
             return resultEvent;
 141  
         }
 142  
         finally
 143  
         {
 144  0
             RequestContext.setEvent(event);
 145  0
             event.getMessage().release();
 146  
         }
 147  
     }
 148  
 
 149  
 }