Coverage Report - org.mule.transport.AbstractReceiverResourceWorker
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractReceiverResourceWorker
0%
0/14
0%
0/4
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;
 8  
 
 9  
 import java.io.OutputStream;
 10  
 import java.util.ArrayList;
 11  
 
 12  
 /**
 13  
  * This is a Message receiver worker used by transports that do not have a way for the underlying transport
 14  
  * to call back to the receiver when a message is available such as Jms. This worker provides a
 15  
  * callback {@link #getNextMessage(Object)} where the receiver can read the next message from the underlying
 16  
  * transport.
 17  
  */
 18  
 public abstract class AbstractReceiverResourceWorker extends AbstractReceiverWorker
 19  
 {
 20  
     protected Object resource;
 21  
 
 22  
     public AbstractReceiverResourceWorker(Object resource, AbstractMessageReceiver receiver)
 23  
     {
 24  0
         this(resource, receiver, null);
 25  0
     }
 26  
 
 27  
     public AbstractReceiverResourceWorker(Object resource, AbstractMessageReceiver receiver, OutputStream out)
 28  
     {
 29  0
         super(new ArrayList<Object>(), receiver, out);
 30  0
         this.resource = resource;
 31  0
     }
 32  
 
 33  
     @Override
 34  
     public void doRun()
 35  
     {
 36  
         try
 37  
         {
 38  
             Object message;
 39  
             do 
 40  
             {
 41  0
                 message = getNextMessage(resource);
 42  0
                 messages.add(message);
 43  0
                 super.doRun();
 44  
             }
 45  0
             while (message != null && hasMoreMessages(message));
 46  
         }
 47  0
         catch (Exception e)
 48  
         {
 49  0
             receiver.getConnector().getMuleContext().getExceptionListener().handleException(e);
 50  0
         }
 51  0
     }
 52  
 
 53  
     protected boolean hasMoreMessages(Object message)
 54  
     {
 55  0
         return true;
 56  
     }
 57  
     
 58  
     /**
 59  
      * The method used to read the next message from the underlying transport.
 60  
      * @param resource the resource to read from, this may be a socket, a directory or some higher level
 61  
      * representation.
 62  
      * @return the message read from the resource.  This can be raw data such as a byte[].
 63  
      * @throws Exception
 64  
      */
 65  
     protected abstract Object getNextMessage(Object resource) throws Exception;
 66  
 }