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