Coverage Report - org.mule.work.AbstractMuleEventWork
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractMuleEventWork
0%
0/8
N/A
1
 
 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.work;
 8  
 
 9  
 import org.mule.OptimizedRequestContext;
 10  
 import org.mule.api.MuleEvent;
 11  
 import org.mule.api.ThreadSafeAccess;
 12  
 
 13  
 import javax.resource.spi.work.Work;
 14  
 
 15  
 /**
 16  
  * Abstract implementation of Work to be used whenever Work needs to be scheduled
 17  
  * that operates on a MuleEvent. The abstract implementation ensures that a copy of
 18  
  * MuleEvent is used and that this copy is available in the RequestContext for this
 19  
  * new thread. Implementations of AbstractMuleEventWork should be run/scheduled only
 20  
  * once. NOTE: This approach does not attempt to resolve MULE-4409 so this work may
 21  
  * need to be reverted to correctly fix MULE-4409 in future releases.
 22  
  */
 23  
 public abstract class AbstractMuleEventWork implements Work
 24  
 {
 25  
 
 26  
     protected MuleEvent event;
 27  
 
 28  
     public AbstractMuleEventWork(MuleEvent event)
 29  0
     {
 30  
         // Event must be copied here rather than once work is executed, so main flow can't mutate the message
 31  
         // before work execution
 32  0
         this.event = (MuleEvent) ((ThreadSafeAccess) event).newThreadCopy();
 33  0
     }
 34  
 
 35  
     public final void run()
 36  
     {
 37  
         // Set event in RequestContext now we are in new thread (fresh copy already made in constructor)
 38  0
         OptimizedRequestContext.unsafeSetEvent(event);
 39  0
         doRun();
 40  0
     }
 41  
 
 42  
     protected abstract void doRun();
 43  
 
 44  
     public void release()
 45  
     {
 46  
         // no-op
 47  0
     }
 48  
 
 49  
     public MuleEvent getEvent()
 50  
     {
 51  0
         return event;
 52  
     }
 53  
 }