Coverage Report - org.mule.transport.KeyedPoolMessageRequesterFactoryAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
KeyedPoolMessageRequesterFactoryAdapter
0%
0/35
0%
0/14
1.462
 
 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 org.mule.api.MuleException;
 10  
 import org.mule.api.endpoint.InboundEndpoint;
 11  
 import org.mule.api.lifecycle.Disposable;
 12  
 import org.mule.api.lifecycle.Startable;
 13  
 import org.mule.api.lifecycle.Stoppable;
 14  
 import org.mule.api.transport.MessageRequester;
 15  
 import org.mule.api.transport.MessageRequesterFactory;
 16  
 import org.mule.config.i18n.CoreMessages;
 17  
 
 18  
 import org.apache.commons.pool.KeyedPoolableObjectFactory;
 19  
 
 20  
 /**
 21  
  * <code>KeyedPoolMessageRequesterFactoryAdapter</code> adapts a
 22  
  * <code>MessageRequesterFactory</code> with methods from commons-pool
 23  
  * <code>KeyedPoolableObjectFactory</code>. It is only required for requester
 24  
  * factories that do not inherit from <code>AbstractMessageRequesterFactory</code>.
 25  
  *
 26  
  * @see org.mule.transport.AbstractMessageRequesterFactory
 27  
  */
 28  
 public class KeyedPoolMessageRequesterFactoryAdapter
 29  
     implements MessageRequesterFactory, KeyedPoolableObjectFactory
 30  
 {
 31  
     private final MessageRequesterFactory factory;
 32  
 
 33  
     public KeyedPoolMessageRequesterFactoryAdapter(MessageRequesterFactory factory)
 34  
     {
 35  0
         super();
 36  
 
 37  0
         if (factory == null)
 38  
         {
 39  0
             throw new IllegalArgumentException(CoreMessages.objectIsNull("factory").toString());
 40  
         }
 41  
 
 42  0
         this.factory = factory;
 43  0
     }
 44  
 
 45  
     public void activateObject(Object key, Object obj) throws Exception
 46  
     {
 47  
         //Ensure requester has the same lifecycle as the connector
 48  0
         applyLifecycle((MessageRequester)obj, false);
 49  
 
 50  0
         factory.activate((InboundEndpoint) key, (MessageRequester) obj);
 51  0
     }
 52  
 
 53  
     public void destroyObject(Object key, Object obj) throws Exception
 54  
     {
 55  0
         factory.destroy((InboundEndpoint) key, (MessageRequester) obj);
 56  0
     }
 57  
 
 58  
     public Object makeObject(Object key) throws Exception
 59  
     {
 60  0
         Object obj = factory.create((InboundEndpoint) key);
 61  0
         applyLifecycle((MessageRequester)obj, true);
 62  0
         return obj;
 63  
     }
 64  
 
 65  
     public void passivateObject(Object key, Object obj) throws Exception
 66  
     {
 67  0
         factory.passivate((InboundEndpoint) key, (MessageRequester) obj);
 68  0
     }
 69  
 
 70  
     public boolean validateObject(Object key, Object obj)
 71  
     {
 72  0
         return factory.validate((InboundEndpoint) key, (MessageRequester) obj);
 73  
     }
 74  
 
 75  
     public boolean isCreateRequesterPerRequest()
 76  
     {
 77  0
         return factory.isCreateRequesterPerRequest();
 78  
     }
 79  
 
 80  
     public MessageRequester create(InboundEndpoint endpoint) throws MuleException
 81  
     {
 82  0
         return factory.create(endpoint);
 83  
     }
 84  
 
 85  
     public void activate(InboundEndpoint endpoint, MessageRequester requester) throws MuleException
 86  
     {
 87  0
         factory.activate(endpoint, requester);
 88  0
     }
 89  
 
 90  
     public void destroy(InboundEndpoint endpoint, MessageRequester requester)
 91  
     {
 92  0
         factory.destroy(endpoint, requester);
 93  0
     }
 94  
 
 95  
     public void passivate(InboundEndpoint endpoint, MessageRequester requester)
 96  
     {
 97  0
         factory.passivate(endpoint, requester);
 98  0
     }
 99  
 
 100  
     public boolean validate(InboundEndpoint endpoint, MessageRequester requester)
 101  
     {
 102  0
         return factory.validate(endpoint, requester);
 103  
     }
 104  
 
 105  
     protected void applyLifecycle(MessageRequester requester, boolean created) throws MuleException
 106  
     {
 107  0
         String phase = ((AbstractConnector)requester.getConnector()).getLifecycleManager().getCurrentPhase();
 108  0
         if(phase.equals(Startable.PHASE_NAME) && !requester.getLifecycleState().isStarted())
 109  
         {
 110  0
             if(!requester.getLifecycleState().isInitialised())
 111  
             {
 112  0
                 requester.initialise();
 113  
             }
 114  0
             requester.start();
 115  
         }
 116  0
         else if(phase.equals(Stoppable.PHASE_NAME) && requester.getLifecycleState().isStarted())
 117  
         {
 118  0
             requester.stop();
 119  
         }
 120  0
         else if(Disposable.PHASE_NAME.equals(phase))
 121  
         {
 122  0
             requester.dispose();
 123  
         }
 124  0
     }
 125  
 }