KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > server > ServerFederation


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: ServerFederation.java 1921 2005-06-19 22:40:34Z jlaskowski $
44  */

45 package org.openejb.server;
46
47 import org.openejb.ProxyInfo;
48 import org.openejb.util.FastThreadLocal;
49
50 import org.openejb.core.ivm.IntraVmServer;
51 import org.openejb.spi.ApplicationServer;
52
53 import javax.ejb.Handle JavaDoc;
54 import javax.ejb.EJBMetaData JavaDoc;
55 import javax.ejb.HomeHandle JavaDoc;
56 import javax.ejb.EJBObject JavaDoc;
57 import javax.ejb.EJBHome JavaDoc;
58
59 /**
60  * This class is passed in as the ApplicationServer implementation
61  * when OpenEJB is initialized. This class allows several application
62  * server implementations to be used on the same contianer system
63  *
64  * Each one calls setApplicationServer before making a call to OpenEJB.
65  * Then, when OpenEJB eventually makes a call to the ApplicationServer
66  * implementation, which is this object, we can actually delegate the
67  * call to the real application server.
68  *
69  * This allows us to have several ApplicationServer implamentations
70  * all using the same OpenEJB instance at the same time, whereas we
71  * would normally be limited to one.
72  *
73  * @author <a HREF="mailto:david.blevins@visi.com">David Blevins</a>
74  */

75 public class ServerFederation implements ApplicationServer {
76
77     private static FastThreadLocal threadStorage = new FastThreadLocal();
78
79
80
81     /**
82      * Delegates this call to the application server implementation
83      * associated with this thread.
84      *
85      * @param proxyInfo A proxy info instance describing the deployment
86      *
87      * @return Handle
88      */

89     public Handle JavaDoc getHandle(ProxyInfo proxyInfo) {
90         return getApplicationServer().getHandle(proxyInfo);
91     }
92
93     /**
94      * Delegates this call to the application server implementation
95      * associated with this thread.
96      *
97      * @param proxyInfo A proxy info instance describing the deployment
98      *
99      * @return EJBMetaData
100      */

101     public EJBMetaData JavaDoc getEJBMetaData(ProxyInfo proxyInfo) {
102         return getApplicationServer().getEJBMetaData(proxyInfo);
103     }
104
105     /**
106      * Delegates this call to the application server implementation
107      * associated with this thread.
108      *
109      * @param proxyInfo A proxy info instance describing the deployment
110      *
111      * @return HomeHandle
112      */

113     public HomeHandle JavaDoc getHomeHandle(ProxyInfo proxyInfo) {
114         return getApplicationServer().getHomeHandle(proxyInfo);
115     }
116
117     /**
118      * Delegates this call to the application server implementation
119      * associated with this thread.
120      *
121      * @param proxyInfo A proxy info instance describing the deployment
122      *
123      * @return EJBObject
124      */

125     public EJBObject JavaDoc getEJBObject(ProxyInfo proxyInfo) {
126         return getApplicationServer().getEJBObject(proxyInfo);
127     }
128
129     /**
130      * Delegates this call to the application server implementation
131      * associated with this thread.
132      *
133      * @param proxyInfo A proxy info instance describing the deployment
134      *
135      * @return EJBHome
136      */

137     public EJBHome JavaDoc getEJBHome(ProxyInfo proxyInfo) {
138         return getApplicationServer().getEJBHome(proxyInfo);
139     }
140
141
142     //-------------------------------------------//
143

144     /**
145      * Makes the ApplicationServer implementation specified the
146      * one that will be used for all actions on this thread.
147      *
148      * @param server
149      */

150     public static void setApplicationServer(ApplicationServer server) {
151         if ( server != null ) {
152             threadStorage.set(server);
153         }
154     }
155     
156     /**
157      * Gets the ApplicationServer implementation associates
158      * with this thread.
159      *
160      * @return ApplicationServer
161      */

162     public static ApplicationServer getApplicationServer( ) {
163         ApplicationServer server = (ApplicationServer)threadStorage.get();
164         //System.out.println("[] Get App Server "+obj);
165
return (server == null)? localServer: server;
166     }
167     
168     private static final IntraVmServer localServer = new IntraVmServer();
169 }
170
171
172
Popular Tags