KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > TimerBeanContainer


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.ejb.containers;
24
25
26 import java.util.logging.*;
27 import java.util.Vector JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import javax.naming.NamingException JavaDoc;
31 import javax.naming.Context JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33
34 import com.sun.ejb.Container;
35 import com.sun.ejb.InvocationInfo;
36 import com.sun.enterprise.deployment.*;
37
38 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
39 import com.sun.enterprise.server.ApplicationServer;
40 import com.sun.enterprise.server.ServerContext;
41 import com.sun.enterprise.config.serverbeans.EjbContainer;
42 import com.sun.enterprise.config.serverbeans.EjbTimerService;
43
44
45 public class TimerBeanContainer
46     extends EntityContainer
47 {
48     
49     private EJBTimerService ejbTimerService;
50         
51     /**
52      * This constructor is called when the timer service system application is
53      * loaded.
54      * @exception Exception on error
55      */

56     protected TimerBeanContainer(EjbDescriptor desc, ClassLoader JavaDoc loader)
57         throws Exception JavaDoc
58     {
59         super(desc, loader);
60
61         _logger.log(Level.FINE,"[TimerBeanContainer] Created "
62                 + " TimerBeanContainer: " + logParams[0]);
63
64     }
65
66     public void onShutdown() {
67         _logger.log(Level.FINE,"[TimerBeanContainer] onShutdown() called....");
68
69         super.onShutdown();
70
71         if (ejbTimerService != null) {
72             ejbTimerService.onShutdown();
73         }
74     }
75
76     /**
77      * Called after all the components in the container's application
78      * have deployed successfully.
79      */

80     public void doAfterApplicationDeploy() {
81
82         super.doAfterApplicationDeploy();
83
84         try {
85
86             TimerLocalHome timerLocalHome = (TimerLocalHome) ejbLocalHome;
87
88             // Do "health check" on access to persistent timer info.
89
EjbBundleDescriptor bundle =
90                 ejbDescriptor.getEjbBundleDescriptor();
91
92             // Get timer data source name set in timer service system app's
93
// sun-ejb-jar.xml
94
ResourceReferenceDescriptor cmpResource =
95                 bundle.getCMPResourceReference();
96
97             String JavaDoc cmpResourceJndiName = cmpResource.getJndiName();
98
99             // Get the timer data source name from the domain.xml
100
ServerContext sc = ApplicationServer.getServerContext();
101             EjbContainer ejbc = ServerBeansFactory.
102                 getConfigBean(sc.getConfigContext()).getEjbContainer();
103             EjbTimerService ejbt = ejbc.getEjbTimerService();
104             // EjbTimerService is an optional element
105
String JavaDoc ejbtDatasource = (ejbt != null) ?
106                 ejbt.getTimerDatasource() : null;
107
108             // Override the timer datasource with the one from domain.xml
109
// if necessary.
110
if( (ejbtDatasource != null) &&
111                 (!ejbtDatasource.equals(cmpResourceJndiName)) ) {
112
113                 cmpResourceJndiName = ejbtDatasource;
114                  
115                 // overwrite datasource jndi name in descriptor
116
cmpResource.setJndiName(cmpResourceJndiName);
117             }
118
119             // Make sure cmp resource is available in the namespace.
120
Context JavaDoc context = new InitialContext JavaDoc();
121             context.lookup(cmpResourceJndiName);
122             
123             // Make an invocation on timer bean to ensure that app is
124
// initialized properly. Second param determines whether
125
// exhaustive database checks are performed. These are time
126
// consuming so they will be disabled by default.
127
boolean checkStatus =
128                 timerLocalHome.checkStatus(cmpResourceJndiName, false);
129
130             if( checkStatus ) {
131
132                 //descriptor object representing this application or module
133
Application application = ejbDescriptor.getApplication();
134         
135                 //registration name of the applicaton
136
String JavaDoc appID = application.getRegistrationName();
137
138                 Vector JavaDoc ejbs = application.getEjbDescriptors();
139                 TimerMigrationLocalHome timerMigrationLocalHome = null;
140                 for(Iterator JavaDoc iter = ejbs.iterator(); iter.hasNext();) {
141                     EjbDescriptor next = (EjbDescriptor) iter.next();
142                     if( next.getLocalHomeClassName().equals
143                         (TimerMigrationLocalHome.class.getName()) ) {
144                         BaseContainer container = (BaseContainer)
145                             containerFactory.getContainer(next.getUniqueId());
146                         timerMigrationLocalHome = (TimerMigrationLocalHome)
147                             container.getEJBLocalHome();
148                         break;
149                     }
150                 }
151
152                 // Create EJB Timer service.
153
ejbTimerService =
154                     new EJBTimerService(appID, timerLocalHome,
155                                         timerMigrationLocalHome);
156
157                 containerFactory.setEJBTimerService(ejbTimerService);
158
159                 _logger.log(Level.INFO, "ejb.timer_service_started",
160                             new Object JavaDoc[] { cmpResourceJndiName } );
161
162             } else {
163                 // error logged by timer bean.
164
}
165
166         } catch (NamingException JavaDoc nnfe) {
167
168             // This is most likely caused by the timer datasource not being
169
// configured for this server instance.
170
_logger.log(Level.WARNING, "ejb.timer_service_init_error",
171                         logParams);
172
173         } catch (Exception JavaDoc ex) {
174             _logger.log(Level.WARNING, "ejb.timer_service_init_error",
175                         logParams);
176             _logger.log(Level.WARNING, "", ex);
177         }
178         
179     }
180     
181 } //TimerBeanContainer.java
182
Popular Tags