View Javadoc

1   /*
2    * $Id: KeyedPoolMessageRequesterFactoryAdapter.java 10961 2008-02-22 19:01:02Z dfeist $
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;
12  
13  import org.mule.api.MuleException;
14  import org.mule.api.endpoint.InboundEndpoint;
15  import org.mule.api.transport.MessageRequester;
16  import org.mule.api.transport.MessageRequesterFactory;
17  import org.mule.config.i18n.CoreMessages;
18  
19  import org.apache.commons.pool.KeyedPoolableObjectFactory;
20  
21  /**
22   * <code>KeyedPoolMessageRequesterFactoryAdapter</code> adapts a
23   * <code>MessageRequesterFactory</code> with methods from commons-pool
24   * <code>KeyedPoolableObjectFactory</code>. It is only required for requester
25   * factories that do not inherit from <code>AbstractMessageRequesterFactory</code>.
26   *
27   * @see org.mule.transport.AbstractMessageRequesterFactory
28   */
29  public class KeyedPoolMessageRequesterFactoryAdapter
30      implements MessageRequesterFactory, KeyedPoolableObjectFactory
31  {
32      private final MessageRequesterFactory factory;
33  
34      public KeyedPoolMessageRequesterFactoryAdapter(MessageRequesterFactory factory)
35      {
36          super();
37  
38          if (factory == null)
39          {
40              throw new IllegalArgumentException(CoreMessages.objectIsNull("factory").toString());
41          }
42  
43          this.factory = factory;
44      }
45  
46      public void activateObject(Object key, Object obj) throws Exception
47      {
48          factory.activate((InboundEndpoint) key, (MessageRequester) obj);
49      }
50  
51      public void destroyObject(Object key, Object obj) throws Exception
52      {
53          factory.destroy((InboundEndpoint) key, (MessageRequester) obj);
54      }
55  
56      public Object makeObject(Object key) throws Exception
57      {
58          return factory.create((InboundEndpoint) key);
59      }
60  
61      public void passivateObject(Object key, Object obj) throws Exception
62      {
63          factory.passivate((InboundEndpoint) key, (MessageRequester) obj);
64      }
65  
66      public boolean validateObject(Object key, Object obj)
67      {
68          return factory.validate((InboundEndpoint) key, (MessageRequester) obj);
69      }
70  
71      public boolean isCreateRequesterPerRequest()
72      {
73          return factory.isCreateRequesterPerRequest();
74      }
75  
76      public MessageRequester create(InboundEndpoint endpoint) throws MuleException
77      {
78          return factory.create(endpoint);
79      }
80  
81      public void activate(InboundEndpoint endpoint, MessageRequester requester) throws MuleException
82      {
83          factory.activate(endpoint, requester);
84      }
85  
86      public void destroy(InboundEndpoint endpoint, MessageRequester requester)
87      {
88          factory.destroy(endpoint, requester);
89      }
90  
91      public void passivate(InboundEndpoint endpoint, MessageRequester requester)
92      {
93          factory.passivate(endpoint, requester);
94      }
95  
96      public boolean validate(InboundEndpoint endpoint, MessageRequester requester)
97      {
98          return factory.validate(endpoint, requester);
99      }
100 
101 }