01: /*
02: * $Id: AbstractMessageDispatcherFactory.java 10961 2008-02-22 19:01:02Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.transport;
12:
13: import org.mule.api.MuleException;
14: import org.mule.api.endpoint.OutboundEndpoint;
15: import org.mule.api.transport.MessageDispatcher;
16: import org.mule.api.transport.MessageDispatcherFactory;
17: import org.mule.util.ClassUtils;
18:
19: /**
20: * <code>AbstractMessageDispatcherFactory</code> is a base implementation of the
21: * <code>MessageDispatcherFactory</code> interface for managing the lifecycle of
22: * message dispatchers.
23: *
24: * @see MessageDispatcherFactory
25: */
26: public abstract class AbstractMessageDispatcherFactory implements
27: MessageDispatcherFactory {
28:
29: public AbstractMessageDispatcherFactory() {
30: super ();
31: }
32:
33: /**
34: * This default implementation of
35: * {@link MessageDispatcherFactory#isCreateDispatcherPerRequest()} returns
36: * <code>false</code>, which means that dispatchers are pooled according to
37: * their lifecycle as described in {@link MessageDispatcher}.
38: *
39: * @return <code>false</code> by default, unless overwritten by a subclass.
40: */
41: public boolean isCreateDispatcherPerRequest() {
42: return false;
43: }
44:
45: public abstract MessageDispatcher create(OutboundEndpoint endpoint)
46: throws MuleException;
47:
48: public void activate(OutboundEndpoint endpoint,
49: MessageDispatcher dispatcher) throws MuleException {
50: dispatcher.activate();
51: }
52:
53: public void destroy(OutboundEndpoint endpoint,
54: MessageDispatcher dispatcher) {
55: dispatcher.dispose();
56: }
57:
58: public void passivate(OutboundEndpoint endpoint,
59: MessageDispatcher dispatcher) {
60: dispatcher.passivate();
61: }
62:
63: public boolean validate(OutboundEndpoint endpoint,
64: MessageDispatcher dispatcher) {
65: // Unless dispatchers are to be disposed of after every request, we check if
66: // the dispatcher is still valid or has e.g. disposed itself after an
67: // exception.
68: return (this .isCreateDispatcherPerRequest() ? false
69: : dispatcher.validate());
70: }
71:
72: // @Override
73: public String toString() {
74: final StringBuffer sb = new StringBuffer(60);
75: sb.append(ClassUtils.getSimpleName(this .getClass()));
76: sb.append("{this=").append(
77: Integer.toHexString(System.identityHashCode(this )));
78: sb.append(", createDispatcherPerRequest=").append(
79: this .isCreateDispatcherPerRequest());
80: sb.append('}');
81: return sb.toString();
82: }
83:
84: }
|