Coverage Report - org.mule.providers.vm.VMMessageReceiver
 
Classes in this File Line Coverage Branch Coverage Complexity
VMMessageReceiver
0%
0/36
0%
0/4
1.75
 
 1  
 /*
 2  
  * $Id: VMMessageReceiver.java 7976 2007-08-21 14:26:13Z 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.providers.vm;
 12  
 
 13  
 import org.mule.MuleException;
 14  
 import org.mule.config.i18n.CoreMessages;
 15  
 import org.mule.impl.MuleMessage;
 16  
 import org.mule.providers.TransactedPollingMessageReceiver;
 17  
 import org.mule.umo.UMOComponent;
 18  
 import org.mule.umo.UMOEvent;
 19  
 import org.mule.umo.UMOException;
 20  
 import org.mule.umo.UMOMessage;
 21  
 import org.mule.umo.endpoint.UMOEndpoint;
 22  
 import org.mule.umo.lifecycle.InitialisationException;
 23  
 import org.mule.umo.provider.UMOConnector;
 24  
 import org.mule.util.queue.Queue;
 25  
 import org.mule.util.queue.QueueSession;
 26  
 
 27  
 import java.util.List;
 28  
 
 29  
 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
 30  
 
 31  
 /**
 32  
  * <code>VMMessageReceiver</code> is a listener for events from a Mule component
 33  
  * which then simply passes the events on to the target component.
 34  
  */
 35  
 public class VMMessageReceiver extends TransactedPollingMessageReceiver
 36  
 {
 37  
     public static final long DEFAULT_VM_POLL_FREQUENCY = 10;
 38  0
     public static final TimeUnit DEFAULT_VM_POLL_TIMEUNIT = TimeUnit.MILLISECONDS;
 39  
 
 40  
     private VMConnector connector;
 41  0
     private final Object lock = new Object();
 42  
 
 43  
     public VMMessageReceiver(UMOConnector connector, UMOComponent component, UMOEndpoint endpoint)
 44  
         throws InitialisationException
 45  
     {
 46  0
         super(connector, component, endpoint);
 47  0
         this.setReceiveMessagesInTransaction(endpoint.getTransactionConfig().isTransacted());
 48  0
         this.setFrequency(DEFAULT_VM_POLL_FREQUENCY);
 49  0
         this.setTimeUnit(DEFAULT_VM_POLL_TIMEUNIT);
 50  0
         this.connector = (VMConnector) connector;
 51  0
     }
 52  
 
 53  
     protected void doDispose()
 54  
     {
 55  
         // template method
 56  0
     }
 57  
 
 58  
     protected void doConnect() throws Exception
 59  
     {
 60  0
         if (connector.isQueueEvents())
 61  
         {
 62  
             // Ensure we can create a vm queue
 63  0
             QueueSession queueSession = connector.getQueueSession();
 64  0
             Queue q = queueSession.getQueue(endpoint.getEndpointURI().getAddress());
 65  0
             if (logger.isDebugEnabled())
 66  
             {
 67  0
                 logger.debug("Current queue depth for queue: " + endpoint.getEndpointURI().getAddress()
 68  
                                 + " is: " + q.size());
 69  
             }
 70  
         }
 71  0
     }
 72  
 
 73  
     protected void doDisconnect() throws Exception
 74  
     {
 75  
         // template method
 76  0
     }
 77  
 
 78  
     /*
 79  
      * (non-Javadoc)
 80  
      * 
 81  
      * @see org.mule.umo.UMOEventListener#onEvent(org.mule.umo.UMOEvent)
 82  
      */
 83  
     public void onEvent(UMOEvent event) throws UMOException
 84  
     {
 85  0
         if (connector.isQueueEvents())
 86  
         {
 87  0
             QueueSession queueSession = connector.getQueueSession();
 88  0
             Queue queue = queueSession.getQueue(endpoint.getEndpointURI().getAddress());
 89  
             try
 90  
             {
 91  0
                 queue.put(event);
 92  
             }
 93  0
             catch (InterruptedException e)
 94  
             {
 95  0
                 throw new MuleException(CoreMessages.interruptedQueuingEventFor(this.endpoint
 96  
                     .getEndpointURI()), e);
 97  0
             }
 98  
         }
 99  
         else
 100  
         {
 101  0
             UMOMessage msg = new MuleMessage(event.getTransformedMessage(), event.getMessage());
 102  0
             synchronized (lock)
 103  
             {
 104  0
                 routeMessage(msg);
 105  0
             }
 106  
         }
 107  0
     }
 108  
 
 109  
     public Object onCall(UMOEvent event) throws UMOException
 110  
     {
 111  0
         return routeMessage(new MuleMessage(event.getTransformedMessage(), event.getMessage()), event
 112  
             .isSynchronous());
 113  
     }
 114  
 
 115  
     protected List getMessages() throws Exception
 116  
     {
 117  0
         QueueSession qs = connector.getQueueSession();
 118  0
         Queue queue = qs.getQueue(endpoint.getEndpointURI().getAddress());
 119  0
         UMOEvent event = (UMOEvent) queue.poll(connector.getQueueTimeout());
 120  0
         if (event != null)
 121  
         {
 122  0
             routeMessage(new MuleMessage(event.getTransformedMessage(), event.getMessage()));
 123  
         }
 124  0
         return null;
 125  
     }
 126  
 
 127  
     /*
 128  
      * (non-Javadoc)
 129  
      * 
 130  
      * @see org.mule.providers.TransactionEnabledPollingMessageReceiver#processMessage(java.lang.Object)
 131  
      */
 132  
     protected void processMessage(Object msg) throws Exception
 133  
     {
 134  
         // This method is never called as the message is processed when received
 135  0
     }
 136  
 
 137  
 }