1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36
37 package javax.resource.spi;
38
39 import javax.resource.ResourceException;
40 import javax.resource.NotSupportedException;
41 import javax.resource.spi.ActivationSpec;
42 import javax.resource.spi.endpoint.MessageEndpointFactory;
43
44 import javax.transaction.xa.XAResource;
45
46 /**
47 * This represents a resource adapter instance and contains operations for
48 * lifecycle management and message endpoint setup. A concrete implementation
49 * of this interface is required to be a JavaBean.
50 *
51 * @version 1.0
52 * @author Ram Jeyaraman
53 */
54 public interface ResourceAdapter {
55
56 // lifecycle operations
57
58 /**
59 * This is called when a resource adapter instance is bootstrapped. This
60 * may be during resource adapter deployment or application server startup.
61 * This is a startup notification from the application server, and this
62 * method is called by an application server thread. The application server
63 * thread executes in an unspecified context.
64 *
65 * <p>During this method call a ResourceAdapter JavaBean is
66 * responsible for initializing the resource adapter
67 * instance. Any exception thrown during this method
68 * call causes the application server to abort the bootstrap procedure
69 * for this specific resource adapter instance.
70 *
71 * @param ctx a bootstrap context containing references to
72 * useful facilities that could be used by a resource adapter instance.
73 *
74 * @throws ResourceAdapterInternalException indicates bootstrap failure.
75 * The resource adapter instance is unusable and must be discarded.
76 */
77 void start(BootstrapContext ctx) throws ResourceAdapterInternalException;
78
79 /**
80 * This is called when a resource adapter instance is undeployed or
81 * during application server shutdown. This is a shutdown notification
82 * from the application server, and this method is called by an
83 * application server thread. The application server
84 * thread executes in an unspecified context.
85 *
86 * <p>During this method call, a ResourceAdapter
87 * JavaBean is responsible for performing an orderly shutdown of the
88 * resource adapter instance. Any exception thrown by this
89 * method call does not alter the
90 * processing of the application server shutdown or resource
91 * adapter undeployment that caused this method call. The application
92 * server may log the exception information for error reporting purposes.
93 */
94 void stop();
95
96 // message endpoint setup operations
97
98 /**
99 * This is called during the activation of a message endpoint. This causes
100 * the resource adapter instance to do the necessary setup (ie., setup
101 * message delivery for the message endpoint with a message provider).
102 * Note that message delivery to the message endpoint might start even
103 * before this method returns.
104 *
105 * <p>Endpoint activation is deemed successful only when this method
106 * completes successfully without throwing any exceptions.
107 *
108 * @param endpointFactory a message endpoint factory instance.
109 *
110 * @param spec an activation spec JavaBean instance.
111 *
112 * @throws NotSupportedException indicates message endpoint
113 * activation rejection due to incorrect activation
114 * setup information.
115 */
116 void endpointActivation(MessageEndpointFactory endpointFactory,
117 ActivationSpec spec) throws ResourceException;
118
119 /**
120 * This is called when a message endpoint is deactivated. The instances
121 * passed as arguments to this method call should be identical to those
122 * passed in for the corresponding </code>endpointActivation</code> call.
123 * This causes the resource adapter to stop delivering messages to the
124 * message endpoint.
125 *
126 * <p>Any exception thrown by this method is ignored. After
127 * this method call, the endpoint is deemed inactive.
128 *
129 * @param endpointFactory a message endpoint factory instance.
130 *
131 * @param spec an activation spec JavaBean instance.
132 */
133 void endpointDeactivation(MessageEndpointFactory endpointFactory,
134 ActivationSpec spec);
135
136 /**
137 * This method is called by the application server during crash recovery.
138 * This method takes in an array of <code>ActivationSpec</code> JavaBeans
139 * and returns an array of <code>XAResource</code> objects each of which
140 * represents a unique resource manager.
141 *
142 * The resource adapter may return null if it does not implement the
143 * <code>XAResource</code> interface. Otherwise, it must return an array
144 * of <code>XAResource</code> objects, each of which represents a unique
145 * resource manager that was used by the endpoint applications.
146 *
147 * The application server uses the <code>XAResource</code> objects to
148 * query each resource manager for a list of in-doubt transactions.
149 * It then completes each pending transaction by sending the commit
150 * decision to the participating resource managers.
151 *
152 * @param specs an array of <code>ActivationSpec</code> JavaBeans each of
153 * which corresponds to an deployed endpoint application that was
154 * active prior to the system crash.
155 *
156 * @throws ResourceException generic exception if operation fails due to an
157 * error condition.
158 *
159 * @return an array of <code>XAResource</code> objects each of which
160 * represents a unique resource manager.
161 */
162 XAResource[] getXAResources(ActivationSpec[] specs)
163 throws ResourceException;
164 }