Coverage Report - org.mule.transport.bpm.ProcessMessageReceiver
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessMessageReceiver
19%
6/32
0%
0/10
1.615
ProcessMessageReceiver$Worker
0%
0/11
N/A
1.615
 
 1  
 /*
 2  
  * $Id: ProcessMessageReceiver.java 10961 2008-02-22 19:01:02Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.transport.bpm;
 12  
 
 13  
 import org.mule.DefaultMuleMessage;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.MuleMessage;
 16  
 import org.mule.api.endpoint.InboundEndpoint;
 17  
 import org.mule.api.lifecycle.CreateException;
 18  
 import org.mule.api.lifecycle.InitialisationException;
 19  
 import org.mule.api.service.Service;
 20  
 import org.mule.api.transport.Connector;
 21  
 import org.mule.transport.AbstractMessageReceiver;
 22  
 
 23  
 import java.util.Map;
 24  
 
 25  
 import javax.resource.spi.work.Work;
 26  
 
 27  
 /** Generates an incoming Mule event from an executing workflow process. */
 28  
 public class ProcessMessageReceiver extends AbstractMessageReceiver
 29  
 {
 30  
 
 31  2
     private ProcessConnector connector = null;
 32  
 
 33  
     public ProcessMessageReceiver(Connector connector, Service service, InboundEndpoint endpoint)
 34  
             throws CreateException
 35  
     {
 36  2
         super(connector, service, endpoint);
 37  2
         this.connector = (ProcessConnector) connector;
 38  2
     }
 39  
 
 40  
     public MuleMessage generateSynchronousEvent(String endpoint, Object payload, Map messageProperties) throws MuleException
 41  
     {
 42  0
         logger.debug("Executing process is sending an event (synchronously) to Mule endpoint = " + endpoint);
 43  0
         MuleMessage response = generateEvent(endpoint, payload, messageProperties, true);
 44  0
         if (logger.isDebugEnabled())
 45  
         {
 46  0
             logger.debug("Synchronous response is " + (response != null ? response.getPayload() : null));
 47  
         }
 48  0
         return response;
 49  
     }
 50  
 
 51  
     public void generateAsynchronousEvent(String endpoint, Object payload, Map messageProperties) throws MuleException
 52  
     {
 53  0
         logger.debug("Executing process is dispatching an event (asynchronously) to Mule endpoint = " + endpoint);
 54  
         try
 55  
         {
 56  0
             getWorkManager().scheduleWork(new Worker(endpoint, payload, messageProperties));
 57  
         }
 58  0
         catch (Exception e)
 59  
         {
 60  0
             handleException(e);
 61  0
         }
 62  0
     }
 63  
 
 64  
     protected MuleMessage generateEvent(String endpoint, Object payload, Map messageProperties, boolean synchronous) throws MuleException
 65  
     {
 66  
         MuleMessage message;
 67  0
         if (payload instanceof MuleMessage)
 68  
         {
 69  0
             message = (MuleMessage) payload;
 70  
         }
 71  
         else
 72  
         {
 73  0
             message = new DefaultMuleMessage(connector.getMessageAdapter(payload));
 74  
         }
 75  0
         message.addProperties(messageProperties);
 76  
 
 77  0
         if (connector.isAllowGlobalDispatcher())
 78  
         {
 79  
             // TODO MULE-1221 This should use the "dynamic://" endpoint and not depend on the MuleClient.
 80  0
             if (synchronous)
 81  
             {
 82  0
                 return connector.getMuleClient().send(endpoint, message);
 83  
             }
 84  
             else
 85  
             {
 86  0
                 connector.getMuleClient().dispatch(endpoint, message);
 87  0
                 return null;
 88  
             }
 89  
         }
 90  
         else
 91  
         {
 92  0
             message.setStringProperty(ProcessConnector.PROPERTY_ENDPOINT, endpoint);
 93  0
             return routeMessage(message, synchronous);
 94  
         }
 95  
     }
 96  
 
 97  
     private class Worker implements Work
 98  
     {
 99  
         private String endpoint;
 100  
         private Object payload;
 101  
         private Map messageProperties;
 102  
 
 103  
         public Worker(String endpoint, Object payload, Map messageProperties)
 104  0
         {
 105  0
             this.endpoint = endpoint;
 106  0
             this.payload = payload;
 107  0
             this.messageProperties = messageProperties;
 108  0
         }
 109  
 
 110  
         public void run()
 111  
         {
 112  
             try
 113  
             {
 114  0
                 generateEvent(endpoint, payload, messageProperties, false);
 115  
             }
 116  0
             catch (Exception e)
 117  
             {
 118  0
                 getConnector().handleException(e);
 119  0
             }
 120  0
         }
 121  
 
 122  
         public void release()
 123  0
         { /*nop*/ }
 124  
     }
 125  
 
 126  
     protected void doInitialise() throws InitialisationException
 127  
     {
 128  
         //nothing to do
 129  2
     }
 130  
 
 131  
     protected void doConnect() throws Exception
 132  
     {
 133  
         // nothing to do
 134  0
     }
 135  
 
 136  
     protected void doDisconnect() throws Exception
 137  
     {
 138  
         // nothing to do
 139  0
     }
 140  
 
 141  
     protected void doStart() throws MuleException
 142  
     {
 143  
         // nothing to do
 144  0
     }
 145  
 
 146  
     protected void doStop() throws MuleException
 147  
     {
 148  
         // nothing to do
 149  0
     }
 150  
 
 151  
     protected void doDispose()
 152  
     {
 153  
         // nothing to do               
 154  4
     }
 155  
 
 156  
 }