001: /*
002: * $Id: KeyedPoolMessageDispatcherFactoryAdapter.java 10961 2008-02-22 19:01:02Z dfeist $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.transport;
012:
013: import org.mule.api.MuleException;
014: import org.mule.api.endpoint.OutboundEndpoint;
015: import org.mule.api.transport.MessageDispatcher;
016: import org.mule.api.transport.MessageDispatcherFactory;
017: import org.mule.config.i18n.CoreMessages;
018:
019: import org.apache.commons.pool.KeyedPoolableObjectFactory;
020:
021: /**
022: * <code>KeyedPoolMessageDispatcherFactoryAdapter</code> adapts a
023: * <code>MessageDispatcherFactory</code> with methods from commons-pool
024: * <code>KeyedPoolableObjectFactory</code>. It is only required for dispatcher
025: * factories that do not inherit from <code>AbstractMessageDispatcherFactory</code>.
026: *
027: * @see AbstractMessageDispatcherFactory
028: */
029: public class KeyedPoolMessageDispatcherFactoryAdapter implements
030: MessageDispatcherFactory, KeyedPoolableObjectFactory {
031: private final MessageDispatcherFactory factory;
032:
033: public KeyedPoolMessageDispatcherFactoryAdapter(
034: MessageDispatcherFactory factory) {
035: super ();
036:
037: if (factory == null) {
038: throw new IllegalArgumentException(CoreMessages
039: .objectIsNull("factory").toString());
040: }
041:
042: this .factory = factory;
043: }
044:
045: public void activateObject(Object key, Object obj) throws Exception {
046: factory.activate((OutboundEndpoint) key,
047: (MessageDispatcher) obj);
048: }
049:
050: public void destroyObject(Object key, Object obj) throws Exception {
051: factory
052: .destroy((OutboundEndpoint) key,
053: (MessageDispatcher) obj);
054: }
055:
056: public Object makeObject(Object key) throws Exception {
057: return factory.create((OutboundEndpoint) key);
058: }
059:
060: public void passivateObject(Object key, Object obj)
061: throws Exception {
062: factory.passivate((OutboundEndpoint) key,
063: (MessageDispatcher) obj);
064: }
065:
066: public boolean validateObject(Object key, Object obj) {
067: return factory.validate((OutboundEndpoint) key,
068: (MessageDispatcher) obj);
069: }
070:
071: public boolean isCreateDispatcherPerRequest() {
072: return factory.isCreateDispatcherPerRequest();
073: }
074:
075: public MessageDispatcher create(OutboundEndpoint endpoint)
076: throws MuleException {
077: return factory.create(endpoint);
078: }
079:
080: public void activate(OutboundEndpoint endpoint,
081: MessageDispatcher dispatcher) throws MuleException {
082: factory.activate(endpoint, dispatcher);
083: }
084:
085: public void destroy(OutboundEndpoint endpoint,
086: MessageDispatcher dispatcher) {
087: factory.destroy(endpoint, dispatcher);
088: }
089:
090: public void passivate(OutboundEndpoint endpoint,
091: MessageDispatcher dispatcher) {
092: factory.passivate(endpoint, dispatcher);
093: }
094:
095: public boolean validate(OutboundEndpoint endpoint,
096: MessageDispatcher dispatcher) {
097: return factory.validate(endpoint, dispatcher);
098: }
099:
100: }
|