KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > ondemand > ResourcesServiceGroup


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
24 package com.sun.enterprise.server.ondemand;
25
26 import java.util.Set JavaDoc;
27 import java.util.logging.Logger JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import com.sun.enterprise.server.ondemand.entry.EntryContext;
30 import com.sun.enterprise.server.ondemand.entry.EntryPoint;
31 import com.sun.enterprise.server.ServerContext;
32 import com.sun.enterprise.server.ResourcesUtil;
33 import com.sun.enterprise.config.*;
34 import com.sun.enterprise.config.serverbeans.*;
35 import com.sun.enterprise.connectors.ConnectorRuntime;
36 import com.sun.enterprise.connectors.DeferredResourceConfig;
37 import com.sun.enterprise.deployment.*;
38
39
40 /**
41  * Represents the group services needed by resources. The main components
42  * of this servicegroup JMS provider or MQ. Almost all the resources
43  * in Sun application server are lazily loaded anyway. So this service
44  * group just concentrates on SJSMQ.
45  *
46  * @author Binod PG
47  * @see ServiceGroup
48  * @see ServiceGroupBuilder
49  */

50 public class ResourcesServiceGroup extends ServiceGroup {
51
52     /**
53      * Triggers the start of the servicegroup. The entry context
54      * that caused this startup is used by the servicegroup to obtain
55      * any startup information it require.
56      *
57      * @param context EntryContext object.
58      * @see EntryContext.
59      */

60     public void start(EntryContext context)
61     throws ServiceGroupException {
62         try {
63             //loadSystemApps();
64

65             startLifecycleServices(context.getServerContext());
66             //(ConnectorRuntime.DEFAULT_JMS_ADAPTER);
67
} catch (Exception JavaDoc e) {
68             throw new ServiceGroupException(e);
69         }
70     }
71
72     /**
73      * Analyse the entrycontext and specifies whether this servicegroup
74      * can be started or not.
75      *
76      * @return boolean If true is returned, this servicegroup can be started
77      * If false is returned, the entrycontext is not recognized by the
78      * servicegroup.
79      */

80     public boolean analyseEntryContext( EntryContext context ) {
81         
82         if (_logger.isLoggable(Level.FINER)) {
83             _logger.log(Level.FINER,
84             "Analysing the context in Resources ServiceGroup :" + context);
85         }
86
87         if (context.get() == null) {
88             return false;
89         }
90
91         boolean result = false;
92         try {
93             ConfigContext ctxt = context.getServerContext().getConfigContext();
94             Config conf = ServerBeansFactory.getConfigBean( ctxt );
95             JmsService jmsService_ = conf.getJmsService();
96             String JavaDoc defaultJmsHost = jmsService_.getDefaultJmsHost();
97             JmsHost jmsHost_ = null;
98             boolean embedded = true;
99
100             if (defaultJmsHost==null || defaultJmsHost.equals("")) {
101                jmsHost_ = ServerBeansFactory.getJmsHostBean(ctxt);
102             } else {
103                jmsHost_ = jmsService_.getJmsHostByName(defaultJmsHost);
104             }
105
106             if (jmsHost_ == null || jmsService_.getType() == null ||
107                 ! jmsService_.getType().equalsIgnoreCase("embedded")) {
108                 embedded = false;
109             }
110
111             if ( context.getEntryPointType() == EntryPoint.JNDI ) {
112                // TODO. Move connectors lazy loading from naming to here.
113
}
114
115             if ( context.getEntryPointType() == EntryPoint.STARTUP ) {
116                 boolean onDemandStartup = ((Boolean JavaDoc) context.get()).booleanValue();
117                 if (onDemandStartup == true && embedded == false) {
118                     result = true;
119                 }
120             } else if (embedded == false) {
121                 return false;
122             }
123
124             if (context.getEntryPointType() == EntryPoint.APPLOADER ) {
125                 String JavaDoc mqRA = ConnectorRuntime.DEFAULT_JMS_ADAPTER;
126                 Descriptor desc = (Descriptor) context.get();
127                 if (desc instanceof Application) {
128                     Application application = (Application) desc;
129                     for (ConnectorDescriptor cd : (java.util.Set JavaDoc<ConnectorDescriptor>)
130                          application.getRarDescriptors()) {
131                          Application app = cd.getApplication();
132                          if (app !=null && mqRA.equals(app.getRegistrationName())) {
133                              result = true;
134                          }
135                     }
136                 } else if (desc instanceof ConnectorDescriptor ) {
137                     ConnectorDescriptor cd = (ConnectorDescriptor) desc;
138                     Application app = cd.getApplication();
139                     if (app != null && mqRA.equals(app.getRegistrationName())) {
140                         result = true;
141                     }
142                 }
143                 
144             }
145
146             if ( context.getEntryPointType() == EntryPoint.PORT ) {
147                 String JavaDoc portStr = jmsHost_.getPort();
148                 if (Integer.parseInt(portStr.trim()) ==
149                    ((Integer JavaDoc) context.get()).intValue()) {
150                    result = true;
151                 }
152             }
153         } catch (Exception JavaDoc e) {
154             e.printStackTrace();
155             result = false;
156         }
157
158         return result;
159     }
160
161     /**
162      * Loads all the system apps belongs to this servicegroup.
163      * @see OnDemandServices
164      * @see SystemAppLoader
165      */

166     private void loadSystemApps() {
167         SystemAppLoader loader = OnDemandServer.getSystemAppLoader();
168         loader.loadSystemApps(loader.getResourcesServiceGroupSystemApps());
169     }
170
171
172     /**
173      * Start lifecycles belonging to this service group.
174      * @see OnDemandServices
175      */

176     private void startLifecycleServices(ServerContext context) {
177         String JavaDoc[][] services = OnDemandServices.getResourcesServiceGroupServices();
178         super.startLifecycleServices(services, context);
179     }
180
181     /**
182      * Stop the servicegroup. It stops all the lifecycle modules belongs to this
183      * servicegroup.
184      */

185     public void stop(EntryContext context) throws ServiceGroupException {
186         super.stopLifecycleServices();
187     }
188
189     /**
190      * Abort the servicegroup. This is not called from anywhere as of now.
191      */

192     public void abort(EntryContext context) {
193         super.stopLifecycleServices();
194     }
195
196 }
197
Popular Tags