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