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