Coverage Report - org.mule.transport.vm.VMMessageRequester
 
Classes in this File Line Coverage Branch Coverage Complexity
VMMessageRequester
0%
0/31
0%
0/14
3.6
 
 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.ThreadSafeAccess;
 12  
 import org.mule.api.endpoint.InboundEndpoint;
 13  
 import org.mule.transport.AbstractMessageRequester;
 14  
 import org.mule.util.queue.Queue;
 15  
 import org.mule.util.queue.QueueSession;
 16  
 
 17  
 /**
 18  
  * <code>VMMessageDispatcher</code> is used for providing in memory interaction
 19  
  * between components.
 20  
  */
 21  
 public class VMMessageRequester extends AbstractMessageRequester
 22  
 {
 23  
 
 24  
     private final VMConnector connector;
 25  
 
 26  
     public VMMessageRequester(InboundEndpoint endpoint)
 27  
     {
 28  0
         super(endpoint);
 29  0
         this.connector = (VMConnector) endpoint.getConnector();
 30  0
     }
 31  
 
 32  
     /**
 33  
      * Make a specific request to the underlying transport
 34  
      *
 35  
      * @param timeout the maximum time the operation should block before returning.
 36  
      *                The call should return immediately if there is data available. If
 37  
      *                no data becomes available before the timeout elapses, null will be
 38  
      *                returned
 39  
      * @return the result of the request wrapped in a MuleMessage object. Null will be
 40  
      *         returned if no data was available
 41  
      * @throws Exception if the call to the underlying protocol causes an exception
 42  
      */
 43  
     protected MuleMessage doRequest(long timeout) throws Exception
 44  
     {
 45  
         try
 46  
         {
 47  0
             QueueSession queueSession = connector.getQueueSession();
 48  0
             Queue queue = queueSession.getQueue(endpoint.getEndpointURI().getAddress());
 49  
 
 50  0
             if (queue == null)
 51  
             {
 52  0
                 if (logger.isDebugEnabled())
 53  
                 {
 54  0
                     logger.debug("No queue with name " + endpoint.getEndpointURI().getAddress());
 55  
                 }
 56  0
                 return null;
 57  
             }
 58  
             else
 59  
             {
 60  0
                 MuleEvent event = null;
 61  0
                 if (logger.isDebugEnabled())
 62  
                 {
 63  0
                     logger.debug("Waiting for a message on " + endpoint.getEndpointURI().getAddress());
 64  
                 }
 65  
                 try
 66  
                 {
 67  0
                     event = (MuleEvent) queue.poll(timeout);
 68  
                 }
 69  0
                 catch (InterruptedException e)
 70  
                 {
 71  0
                     logger.error("Failed to receive message from queue: " + endpoint.getEndpointURI());
 72  0
                 }
 73  0
                 if (event != null)
 74  
                 {
 75  
                     //The message will contain old thread information, we need to reset it
 76  0
                     if(event.getMessage() instanceof ThreadSafeAccess)
 77  
                     {
 78  0
                         ((ThreadSafeAccess) event.getMessage()).resetAccessControl();
 79  
                     }
 80  0
                     if (logger.isDebugEnabled())
 81  
                     {
 82  0
                         logger.debug("Message received: " + event);
 83  
                     }
 84  0
                     return event.getMessage();
 85  
                 }
 86  
                 else
 87  
                 {
 88  0
                     if (logger.isDebugEnabled())
 89  
                     {
 90  0
                         logger.debug("No event received after " + timeout + " ms");
 91  
                     }
 92  0
                     return null;
 93  
                 }
 94  
             }
 95  
         }
 96  0
         catch (Exception e)
 97  
         {
 98  0
             throw e;
 99  
         }
 100  
     }
 101  
 
 102  
     protected void doDispose()
 103  
     {
 104  
         // template method
 105  0
     }
 106  
 
 107  
     protected void doConnect() throws Exception
 108  
     {
 109  
         // use the default queue profile to configure this queue.
 110  0
         connector.getQueueProfile().configureQueue(endpoint.getEndpointURI().getAddress(),
 111  
             connector.getQueueManager());
 112  0
     }
 113  
 
 114  
     protected void doDisconnect() throws Exception
 115  
     {
 116  
         // template method
 117  0
     }
 118  
 
 119  
 }