Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * $Id: ProcessMessageReceiver.java 12639 2008-09-12 18:46:39Z tcarlson $
   * --------------------------------------------------------------------------------------
   * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
   *
   * The software in this package is published under the terms of the CPAL v1.0
   * license, a copy of which has been included with this distribution in the
   * LICENSE.txt file.
   */
 
 package org.mule.transport.bpm;
 
 
 import java.util.Map;
 
 import  javax.resource.spi.work.Work;

Generates an incoming Mule event from an executing workflow process.
 
 {
 
     private ProcessConnector connector = null;
 
     public ProcessMessageReceiver(Connector connectorService serviceInboundEndpoint endpoint)
             throws CreateException
     {
         super(connectorserviceendpoint);
         this. = (ProcessConnectorconnector;
     }
 
     public MuleMessage generateSynchronousEvent(String endpointObject payloadMap messagePropertiesthrows MuleException
     {
         .debug("Executing process is sending an event (synchronously) to Mule endpoint = " + endpoint);
         MuleMessage response = generateEvent(endpointpayloadmessagePropertiestrue);
         if (.isDebugEnabled())
         {
             .debug("Synchronous response is " + (response != null ? response.getPayload() : null));
         }
         return response;
     }
 
     public void generateAsynchronousEvent(String endpointObject payloadMap messagePropertiesthrows MuleException
     {
         .debug("Executing process is dispatching an event (asynchronously) to Mule endpoint = " + endpoint);
         try
         {
             WorkManager workManager = getWorkManager();
             if (workManager != null)
             {
                 workManager.scheduleWork(new Worker(endpointpayloadmessageProperties));
             }
             else
             {
                 throw new ConnectorException(MessageFactory.createStaticMessage("WorkManager not available"), getConnector());
             }
         }
         catch (Exception e)
         {
             handleException(e);
         }
     }
 
     protected MuleMessage generateEvent(String endpointObject payloadMap messagePropertiesboolean synchronousthrows MuleException
     {
         MuleMessage message;
         if (payload instanceof MuleMessage)
         {
             message = (MuleMessagepayload;
         }
         else
         {
             message = new DefaultMuleMessage(.getMessageAdapter(payload));
         }
         message.addProperties(messageProperties);
 
         if (.isAllowGlobalDispatcher())
         {
             // TODO MULE-1221 This should use the "dynamic://" endpoint and not depend on the MuleClient.
             if (synchronous)
             {
                 return .getMuleClient().send(endpointmessage);
             }
             else
             {
                 .getMuleClient().dispatch(endpointmessage);
                 return null;
             }
         }
        else
        {
            message.setStringProperty(.endpoint);
            return routeMessage(messagesynchronous);
        }
    }
    private class Worker implements Work
    {
        private String endpoint;
        private Object payload;
        private Map messageProperties;
        public Worker(String endpointObject payloadMap messageProperties)
        {
            this. = endpoint;
            this. = payload;
            this. = messageProperties;
        }
        public void run()
        {
            try
            {
                generateEvent(false);
            }
            catch (Exception e)
            {
                getConnector().handleException(e);
            }
        }
        public void release()
        { /*nop*/ }
    }
New to GrepCode? Check out our FAQ X