Coverage Report - org.mule.transport.vm.VMMessageDispatcher
 
Classes in this File Line Coverage Branch Coverage Complexity
VMMessageDispatcher
0%
0/28
0%
0/12
0
VMMessageDispatcher$1
0%
0/2
N/A
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.transport.vm;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 import org.mule.api.MuleMessage;
 11  
 import org.mule.api.endpoint.EndpointURI;
 12  
 import org.mule.api.endpoint.OutboundEndpoint;
 13  
 import org.mule.api.transaction.TransactionCallback;
 14  
 import org.mule.api.transport.DispatchException;
 15  
 import org.mule.api.transport.NoReceiverForEndpointException;
 16  
 import org.mule.config.i18n.CoreMessages;
 17  
 import org.mule.transaction.TransactionTemplate;
 18  
 import org.mule.transport.AbstractMessageDispatcher;
 19  
 import org.mule.transport.vm.i18n.VMMessages;
 20  
 import org.mule.util.queue.Queue;
 21  
 import org.mule.util.queue.QueueSession;
 22  
 
 23  
 /**
 24  
  * <code>VMMessageDispatcher</code> is used for providing in memory interaction
 25  
  * between components.
 26  
  */
 27  
 public class VMMessageDispatcher extends AbstractMessageDispatcher
 28  
 {
 29  
     private final VMConnector connector;
 30  
 
 31  
     public VMMessageDispatcher(OutboundEndpoint endpoint)
 32  
     {
 33  0
         super(endpoint);
 34  0
         this.connector = (VMConnector) endpoint.getConnector();
 35  0
     }
 36  
 
 37  
     @Override
 38  
     protected void doDispatch(final MuleEvent event) throws Exception
 39  
     {
 40  0
         EndpointURI endpointUri = endpoint.getEndpointURI();
 41  
 
 42  0
         if (endpointUri == null)
 43  
         {
 44  0
             throw new DispatchException(CoreMessages.objectIsNull("Endpoint"), event,
 45  
                 (OutboundEndpoint) endpoint);
 46  
         }
 47  0
         QueueSession session = connector.getQueueSession();
 48  0
         Queue queue = session.getQueue(endpointUri.getAddress());
 49  0
         if (!queue.offer(event, connector.getQueueTimeout()))
 50  
         {
 51  
             // queue is full
 52  0
             throw new DispatchException(VMMessages.queueIsFull(queue.getName(), queue.size()),
 53  
                     event, (OutboundEndpoint) endpoint);
 54  
         }
 55  0
         if (logger.isDebugEnabled())
 56  
         {
 57  0
             logger.debug("dispatched MuleEvent on endpointUri: " + endpointUri);
 58  
         }
 59  0
     }
 60  
 
 61  
     @Override
 62  
     protected MuleMessage doSend(final MuleEvent event) throws Exception
 63  
     {
 64  
         MuleMessage retMessage;
 65  0
         EndpointURI endpointUri = event.getEndpoint().getEndpointURI();
 66  0
         final VMMessageReceiver receiver = connector.getReceiver(endpointUri);
 67  
         // Apply any outbound transformers on this event before we dispatch
 68  
 
 69  0
         if (receiver == null)
 70  
         {
 71  0
             throw new NoReceiverForEndpointException(VMMessages.noReceiverForEndpoint(connector.getName(),
 72  
                                                                                       event.getEndpoint().getEndpointURI()));
 73  
         }
 74  
 
 75  0
         TransactionTemplate<MuleMessage> tt = new TransactionTemplate<MuleMessage>(
 76  
                                                             receiver.getEndpoint().getTransactionConfig(),
 77  
                                                             event.getMuleContext());
 78  
 
 79  0
         TransactionCallback<MuleMessage> cb = new TransactionCallback<MuleMessage>()
 80  0
         {
 81  
             public MuleMessage doInTransaction() throws Exception
 82  
             {
 83  0
                 return receiver.onCall(event.getMessage());
 84  
             }
 85  
         };
 86  0
         retMessage = tt.execute(cb);
 87  
         
 88  0
         if (logger.isDebugEnabled())
 89  
         {
 90  0
             logger.debug("sent event on endpointUri: " + event.getEndpoint().getEndpointURI());
 91  
         }
 92  0
         return retMessage;
 93  
     }
 94  
 
 95  
     @Override
 96  
     protected void doDispose()
 97  
     {
 98  
         // template method
 99  0
     }
 100  
 
 101  
     @Override
 102  
     protected void doConnect() throws Exception
 103  
     {
 104  0
         if (!endpoint.getExchangePattern().hasResponse())
 105  
         {
 106  
             // use the default queue profile to configure this queue.
 107  0
             connector.getQueueProfile().configureQueue(
 108  
                     endpoint.getEndpointURI().getAddress(), connector.getQueueManager());
 109  
         }
 110  0
     }
 111  
 
 112  
     @Override
 113  
     protected void doDisconnect() throws Exception
 114  
     {
 115  
         // template method
 116  0
     }
 117  
 
 118  
 }