Coverage Report - org.mule.providers.bpm.ProcessMessageReceiver
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessMessageReceiver
16%
5/31
0%
0/10
1.667
ProcessMessageReceiver$Worker
0%
0/11
N/A
1.667
 
 1  
 /*
 2  
  * $Id: ProcessMessageReceiver.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 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.providers.bpm;
 12  
 
 13  
 import org.mule.impl.MuleMessage;
 14  
 import org.mule.providers.AbstractMessageReceiver;
 15  
 import org.mule.umo.UMOComponent;
 16  
 import org.mule.umo.UMOException;
 17  
 import org.mule.umo.UMOMessage;
 18  
 import org.mule.umo.endpoint.UMOEndpoint;
 19  
 import org.mule.umo.lifecycle.InitialisationException;
 20  
 import org.mule.umo.provider.UMOConnector;
 21  
 
 22  
 import java.util.Map;
 23  
 
 24  
 import javax.resource.spi.work.Work;
 25  
 
 26  
 /**
 27  
  * Generates an incoming Mule event from an executing workflow process.
 28  
  */
 29  
 public class ProcessMessageReceiver extends AbstractMessageReceiver {
 30  
 
 31  2
     private ProcessConnector connector = null;
 32  
 
 33  
     public ProcessMessageReceiver(UMOConnector connector, UMOComponent component, UMOEndpoint endpoint)
 34  
             throws InitialisationException {
 35  2
         super(connector, component, endpoint);
 36  2
         this.connector = (ProcessConnector) connector;
 37  2
     }
 38  
 
 39  
     public UMOMessage generateSynchronousEvent(String endpoint, Object payload, Map messageProperties) throws UMOException {
 40  0
         logger.debug("Executing process is sending an event (synchronously) to Mule endpoint = " + endpoint);
 41  0
         UMOMessage response = generateEvent(endpoint, payload, messageProperties, true);
 42  0
         if (logger.isDebugEnabled())
 43  
         {
 44  0
             logger.debug("Synchronous response is " + (response != null ? response.getPayload() : null ));
 45  
         }
 46  0
         return response;
 47  
     }
 48  
 
 49  
     public void generateAsynchronousEvent(String endpoint, Object payload, Map messageProperties) throws UMOException {
 50  0
         logger.debug("Executing process is dispatching an event (asynchronously) to Mule endpoint = " + endpoint);
 51  
         try {
 52  0
             getWorkManager().scheduleWork(new Worker(endpoint, payload, messageProperties));
 53  0
         } catch (Exception e) {
 54  0
             handleException(e);
 55  0
         }
 56  0
     }
 57  
 
 58  
     protected UMOMessage generateEvent(String endpoint, Object payload, Map messageProperties, boolean synchronous) throws UMOException {
 59  
         UMOMessage message;
 60  0
         if (payload instanceof UMOMessage) {
 61  0
             message = (UMOMessage) payload;
 62  
         } else {
 63  0
             message = new MuleMessage(connector.getMessageAdapter(payload));
 64  
         }
 65  0
         message.addProperties(messageProperties);
 66  
 
 67  0
         if (connector.isAllowGlobalDispatcher()) {
 68  
             // TODO MULE-1221 This should use the "dynamic://" endpoint and not depend on the MuleClient.
 69  0
             if (synchronous) {
 70  0
                 return connector.getMuleClient().send(endpoint, message);
 71  
             } else {
 72  0
                 connector.getMuleClient().dispatch(endpoint, message);
 73  0
                 return null;
 74  
             }
 75  
         }
 76  
         else {
 77  0
             message.setStringProperty(ProcessConnector.PROPERTY_ENDPOINT, endpoint);
 78  0
             return routeMessage(message, synchronous);
 79  
         }
 80  
     }
 81  
 
 82  
     private class Worker implements Work {
 83  
         private String endpoint;
 84  
         private Object payload;
 85  
         private Map messageProperties;
 86  
 
 87  0
         public Worker(String endpoint, Object payload, Map messageProperties) {
 88  0
             this.endpoint = endpoint;
 89  0
             this.payload = payload;
 90  0
             this.messageProperties = messageProperties;
 91  0
         }
 92  
 
 93  
         public void run() {
 94  
             try {
 95  0
                 generateEvent(endpoint, payload, messageProperties, false);
 96  0
             } catch (Exception e) {
 97  0
                 getConnector().handleException(e);
 98  0
             }
 99  0
         }
 100  
 
 101  0
         public void release() { /*nop*/ }
 102  
     }
 103  
 
 104  
     protected void doConnect() throws Exception
 105  
     {
 106  
         // nothing to do
 107  0
     }
 108  
 
 109  
     protected void doDisconnect() throws Exception
 110  
     {
 111  
         // nothing to do
 112  0
     }
 113  
 
 114  
     protected void doStart() throws UMOException
 115  
     {
 116  
         // nothing to do
 117  0
     }
 118  
 
 119  
     protected void doStop() throws UMOException
 120  
     {
 121  
         // nothing to do
 122  0
     }
 123  
 
 124  
     protected void doDispose()
 125  
     {
 126  
         // nothing to do               
 127  2
     }
 128  
 
 129  
 }