001: /**
002: * EasyBeans
003: * Copyright (C) 2006-2007 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id:MDBMessageEndPoint.java 1477 2007-06-16 16:50:19Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.container.mdb;
025:
026: import java.lang.reflect.Method;
027:
028: import javax.ejb.Timer;
029: import javax.resource.ResourceException;
030: import javax.resource.spi.ApplicationServerInternalException;
031: import javax.resource.spi.UnavailableException;
032: import javax.resource.spi.endpoint.MessageEndpoint;
033: import javax.transaction.xa.XAResource;
034:
035: import org.ow2.easybeans.api.Factory;
036: import org.ow2.easybeans.api.bean.EasyBeansMDB;
037:
038: /**
039: * Implementation of the MessageEndPoint interface.<br/> These methods will be
040: * called by the Resource Adapter.
041: * @author Florent Benoit
042: */
043: public class MDBMessageEndPoint implements MessageEndpoint {
044:
045: /**
046: * MDB object Wrapped by this message end point.
047: */
048: private EasyBeansMDB easyBeansMDB = null;
049:
050: /**
051: * Reference to the message end point factory.
052: */
053: private MDBMessageEndPointFactory mdbMessageEndPointFactory = null;
054:
055: /**
056: * XAResource of this message end point. This resource will be
057: * enlisted/delisted.
058: */
059: private XAResource xaResource = null;
060:
061: /**
062: * Constructor : Build an endpoint with a reference to the message end point
063: * factory.
064: * @param mdbMessageEndPointFactory the message end point factory.
065: * @param easyBeansMDB the message driven bean object that is wrapped.
066: */
067: public MDBMessageEndPoint(
068: final MDBMessageEndPointFactory mdbMessageEndPointFactory,
069: final EasyBeansMDB easyBeansMDB) {
070: this .mdbMessageEndPointFactory = mdbMessageEndPointFactory;
071: this .easyBeansMDB = easyBeansMDB;
072: }
073:
074: /**
075: * This is called by a resource adapter before a message is delivered.
076: * @param method description of a target method. This information about the
077: * intended target method allows an application server to decide
078: * whether to start a transaction during this method call, depending
079: * on the transaction preferences of the target method. The
080: * processing (by the application server) of the actual message
081: * delivery method call on the endpoint must be independent of the
082: * class loader associated with this descriptive method object.
083: * @throws NoSuchMethodException - indicates that the specified method does
084: * not exist on the target endpoint.
085: * @throws ResourceException - generic exception.
086: * @throws ApplicationServerInternalException - indicates an error condition
087: * in the application server.
088: * @throws IllegalStateException - indicates that the endpoint is in an
089: * illegal state for the method invocation. For example, this occurs
090: * when beforeDelivery and afterDelivery method calls are not
091: * paired.
092: * @throws UnavailableException - indicates that the endpoint is not
093: * available.
094: */
095: public void beforeDelivery(final Method method)
096: throws ApplicationServerInternalException,
097: UnavailableException, NoSuchMethodException,
098: IllegalStateException, ResourceException {
099: // TODO : implement this !
100: throw new UnsupportedOperationException("Not implemented");
101: }
102:
103: /**
104: * This is called by a resource adapter after a message is delivered.
105: * @throws ResourceException - generic exception.
106: * @throws ApplicationServerInternalException - indicates an error condition
107: * in the application server.
108: * @throws IllegalStateException - indicates that the endpoint is in an
109: * illegal state for the method invocation. For example, this occurs
110: * when beforeDelivery and afterDelivery method calls are not
111: * paired.
112: * @throws UnavailableException - indicates that the endpoint is not
113: * available.
114: */
115: public void afterDelivery()
116: throws ApplicationServerInternalException,
117: IllegalStateException, UnavailableException,
118: ResourceException {
119: // TODO : implement this !
120: throw new UnsupportedOperationException("Not implemented");
121: }
122:
123: /**
124: * This method may be called by the resource adapter to indicate that it no
125: * longer needs a proxy endpoint instance. This hint may be used by the
126: * application server for endpoint pooling decisions.
127: */
128: public void release() {
129: mdbMessageEndPointFactory.releaseEndPoint(this );
130: }
131:
132: /**
133: * Gets the factory of the bean.
134: * @return factory of the bean.
135: */
136: public Factory getEasyBeansFactory() {
137: return mdbMessageEndPointFactory;
138: }
139:
140: /**
141: * Gets the wrapped Message Driven Bean object.
142: * @return wrapped Message Driven Bean object.
143: */
144: public EasyBeansMDB getEasyBeansMDB() {
145: return easyBeansMDB;
146: }
147:
148: /**
149: * Gets the XAResource of this message end point.
150: * @return the XAResource of this message end point
151: */
152: protected XAResource getXaResource() {
153: return xaResource;
154: }
155:
156: /**
157: * Sets the XAResource of this message end point.
158: * @param xaResource the XAResource of this message end point
159: */
160: protected void setXaResource(final XAResource xaResource) {
161: this .xaResource = xaResource;
162: }
163:
164: /**
165: * Invokes the timeout method on the bean.
166: * @param timer the given EJB timer
167: */
168: protected void notifyTimeout(final Timer timer) {
169: // set classloader to EJB classloader
170: ClassLoader oldCL = Thread.currentThread()
171: .getContextClassLoader();
172: Thread.currentThread().setContextClassLoader(
173: getEasyBeansFactory().getContainer().getClassLoader());
174: // Call the timeout method
175: try {
176: getEasyBeansMDB().timeoutCallByEasyBeans(timer);
177: } finally {
178: Thread.currentThread().setContextClassLoader(oldCL);
179: }
180: }
181: }
|