001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.openejb.cluster.stateful.deployment;
021:
022: import java.util.Map;
023: import java.util.Set;
024:
025: import javax.naming.Context;
026: import javax.security.auth.login.LoginException;
027:
028: import org.apache.geronimo.clustering.SessionManager;
029: import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
030: import org.apache.geronimo.gbean.GBeanInfo;
031: import org.apache.geronimo.gbean.GBeanInfoBuilder;
032: import org.apache.geronimo.gbean.GBeanLifecycle;
033: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
034: import org.apache.geronimo.kernel.Kernel;
035: import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
036: import org.apache.geronimo.openejb.EjbDeployment;
037: import org.apache.geronimo.openejb.EjbDeploymentGBean;
038: import org.apache.geronimo.openejb.OpenEjbSystem;
039: import org.apache.geronimo.openejb.cluster.infra.SessionManagerTracker;
040: import org.apache.geronimo.security.jacc.RunAsSource;
041: import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
042: import org.apache.openejb.Container;
043:
044: /**
045: *
046: * @version $Rev:$ $Date:$
047: */
048: public class ClusteredStatefulDeployment extends EjbDeployment
049: implements GBeanLifecycle {
050:
051: private final SessionManager sessionManager;
052:
053: public ClusteredStatefulDeployment() throws LoginException {
054: sessionManager = null;
055: }
056:
057: public ClusteredStatefulDeployment(String objectName,
058: String deploymentId, String ejbName,
059: String homeInterfaceName, String remoteInterfaceName,
060: String localHomeInterfaceName, String localInterfaceName,
061: String serviceEndpointInterfaceName, String beanClassName,
062: ClassLoader classLoader, boolean securityEnabled,
063: String defaultRole, String runAsRole,
064: RunAsSource runAsSource, Map componentContext,
065: Set unshareableResources,
066: Set applicationManagedSecurityResources,
067: TrackedConnectionAssociator trackedConnectionAssociator,
068: GeronimoTransactionManager transactionManager,
069: OpenEjbSystem openEjbSystem, SessionManager sessionManager,
070: Kernel kernel) throws Exception {
071: this (objectName, deploymentId, ejbName, homeInterfaceName,
072: remoteInterfaceName, localHomeInterfaceName,
073: localInterfaceName, serviceEndpointInterfaceName,
074: beanClassName, classLoader, securityEnabled,
075: defaultRole, runAsRole, runAsSource,
076: EnterpriseNamingContext.createEnterpriseNamingContext(
077: componentContext, transactionManager, kernel,
078: classLoader), unshareableResources,
079: applicationManagedSecurityResources,
080: trackedConnectionAssociator, openEjbSystem,
081: sessionManager);
082: }
083:
084: public ClusteredStatefulDeployment(String objectName,
085: String deploymentId, String ejbName,
086: String homeInterfaceName, String remoteInterfaceName,
087: String localHomeInterfaceName, String localInterfaceName,
088: String serviceEndpointInterfaceName, String beanClassName,
089: ClassLoader classLoader, boolean securityEnabled,
090: String defaultRole, String runAsRole,
091: RunAsSource runAsSource, Context componentContext,
092: Set unshareableResources,
093: Set applicationManagedSecurityResources,
094: TrackedConnectionAssociator trackedConnectionAssociator,
095: OpenEjbSystem openEjbSystem, SessionManager sessionManager)
096: throws LoginException {
097: super (objectName, deploymentId, ejbName, homeInterfaceName,
098: remoteInterfaceName, localHomeInterfaceName,
099: localInterfaceName, serviceEndpointInterfaceName,
100: beanClassName, classLoader, securityEnabled,
101: defaultRole, runAsRole, runAsSource, componentContext,
102: unshareableResources,
103: applicationManagedSecurityResources,
104: trackedConnectionAssociator, openEjbSystem);
105: if (null == sessionManager) {
106: throw new IllegalArgumentException(
107: "sessionManager is required");
108: }
109: this .sessionManager = sessionManager;
110: }
111:
112: public void doStart() throws Exception {
113: start();
114: }
115:
116: public void doStop() throws Exception {
117: stop();
118: }
119:
120: public void doFail() {
121: stop();
122: }
123:
124: protected void start() throws Exception {
125: super .start();
126:
127: Container container = deploymentInfo.getContainer();
128: if (null == container) {
129: throw new IllegalStateException(
130: "Container not assigned to deployment "
131: + deploymentId);
132: }
133: if (!(container instanceof SessionManagerTracker)) {
134: throw new IllegalStateException(
135: "Container for deployment [" + deploymentId
136: + "] is not a ["
137: + SessionManagerTracker.class.getName()
138: + "]. It is a ["
139: + container.getClass().getName() + "]");
140: }
141: SessionManagerTracker sessionManagerTracker = (SessionManagerTracker) container;
142: sessionManagerTracker.addSessionManager(deploymentId,
143: sessionManager);
144: }
145:
146: protected void stop() {
147: if (null != deploymentInfo) {
148: Container container = deploymentInfo.getContainer();
149: if (null != container) {
150: SessionManagerTracker sessionManagerTracker = (SessionManagerTracker) container;
151: sessionManagerTracker.removeSessionManager(
152: deploymentId, sessionManager);
153: }
154: }
155:
156: super .stop();
157: }
158:
159: public static final GBeanInfo GBEAN_INFO;
160:
161: public static final String GBEAN_REF_SESSION_MANAGER = "SessionManager";
162:
163: static {
164: GBeanInfoBuilder builder = GBeanInfoBuilder.createStatic(
165: ClusteredStatefulDeployment.class,
166: ClusteredStatefulDeployment.class,
167: EjbDeploymentGBean.GBEAN_INFO,
168: NameFactory.STATEFUL_SESSION_BEAN);
169:
170: builder.addReference(GBEAN_REF_SESSION_MANAGER,
171: SessionManager.class, NameFactory.GERONIMO_SERVICE);
172:
173: builder.setConstructor(new String[] { "objectName",
174: "deploymentId", "ejbName",
175:
176: "homeInterfaceName", "remoteInterfaceName",
177: "localHomeInterfaceName", "localInterfaceName",
178: "serviceEndpointInterfaceName", "beanClassName",
179: "classLoader",
180:
181: "securityEnabled", "defaultRole", "runAsRole",
182: "RunAsSource",
183:
184: "componentContextMap",
185:
186: "unshareableResources",
187: "applicationManagedSecurityResources",
188: "TrackedConnectionAssociator", "TransactionManager",
189:
190: "OpenEjbSystem", GBEAN_REF_SESSION_MANAGER,
191:
192: "kernel" });
193:
194: GBEAN_INFO = builder.getBeanInfo();
195: }
196:
197: public static GBeanInfo getGBeanInfo() {
198: return GBEAN_INFO;
199: }
200:
201: }
|