001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)WebSphereJBIFramework.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework.websphere;
030:
031: import com.sun.jndi.rmi.registry.RegistryContextFactory;
032: import java.rmi.registry.Registry;
033: import java.rmi.registry.LocateRegistry;
034: import java.rmi.server.UnicastRemoteObject;
035: import java.util.HashMap;
036: import java.util.Properties;
037: import java.util.logging.Logger;
038:
039: import javax.management.MBeanServer;
040: import javax.management.MBeanServerConnection;
041: import javax.management.ObjectName;
042: import javax.management.remote.JMXConnectorServer;
043: import javax.management.remote.JMXConnectorServerFactory;
044: import javax.management.remote.JMXServiceURL;
045: import javax.transaction.TransactionManager;
046: import javax.naming.InitialContext;
047:
048: /**
049: * JBI framework wrapper for WebSphere
050: * <br><br>
051: * A JSEJBIFramework instance cannot be loaded multiple times in the same
052: * VM. If multiple instances of the framework are required in a VM,
053: * instantiate multiple instances of JSEJBIFramework and load each one
054: * independently. There is no limit on the number of uniquely named
055: * JSEJBIFramework instances in the same VM. A specific JSEJBIFramework instance
056: * can be loaded and unloaded multiple times in a VM.
057: *
058: * @author Sun Microsystems, Inc.
059: */
060: public class WebSphereJBIFramework extends
061: com.sun.jbi.framework.JBIFramework implements
062: WebSphereJBIFrameworkMBean {
063: /** key for the install root property **/
064: public static final String INSTALL_ROOT = "install.root";
065:
066: /** key for the instance name property **/
067: public static final String INSTANCE_NAME = "instance.name";
068:
069: /** Configuration defaults. */
070: private static final String DEFAULT_INSTALL_ROOT = System
071: .getProperty("user.dir");
072: private static final String DEFAULT_INSTANCE_NAME = "server";
073:
074: private WebSpherePlatformContext mPlatformContext;
075: private boolean mLoaded;
076: private Properties mEnvironment;
077: private Logger mLog = Logger.getLogger(this .getClass().getPackage()
078: .getName());
079:
080: /**
081: * Creates a new instance of the JBI framework.
082: * @param environment the properties from servlet context
083: */
084: public WebSphereJBIFramework(Properties environment) {
085: super ();
086:
087: mEnvironment = environment;
088: mPlatformContext = new WebSpherePlatformContext(mEnvironment
089: .getProperty(INSTANCE_NAME, DEFAULT_INSTANCE_NAME),
090: mEnvironment.getProperty(INSTALL_ROOT,
091: DEFAULT_INSTALL_ROOT));
092: }
093:
094: /**
095: * Load the JBI framework with the specified environment. When this method
096: * retuns, all public interfaces and system services have completely
097: * initialized. If a connector port is specified in the environment
098: * properties, a remote JMX connector server is created.
099: * @throws Exception failed to load JBI framework
100: */
101: public synchronized void load() throws Exception {
102: try {
103:
104: if (mLoaded) {
105: throw new IllegalStateException(
106: "JBI framework already loaded!");
107: }
108:
109: // Register a management MBean for this framework instance
110: ObjectName fwMBeanName = new ObjectName("com.sun.jbi",
111: "instance", mPlatformContext.getInstanceName());
112: MBeanServer mbs = mPlatformContext.getMBeanServer();
113:
114: if (mbs.isRegistered(fwMBeanName)) {
115: if (mbs.getAttribute(fwMBeanName, "Loaded").equals(
116: Boolean.TRUE)) {
117: // Framework already loaded from a separate thread/process
118: throw new IllegalStateException(
119: "JBI framework instance "
120: + mPlatformContext
121: .getInstanceName()
122: + " has already been loaded");
123: } else {
124: // MBean should not be registered - try to clean up
125: mbs.unregisterMBean(fwMBeanName);
126: }
127: }
128: try {
129: mbs.registerMBean(this , fwMBeanName);
130: } catch (Exception ex) {
131: mLog.severe(ex.getMessage());
132: ex.printStackTrace();
133: }
134:
135: mEnvironment.setProperty("com.sun.jbi.home",
136: mPlatformContext.getInstallRoot());
137: init(mPlatformContext, mEnvironment);
138: startup(mPlatformContext.getNamingContext(), "");
139: prepare();
140: ready(true);
141:
142: // JBI framework has been loaded
143: mLoaded = true;
144: } catch (Exception ex) {
145: mLog.severe(ex.getMessage());
146: }
147: }
148:
149: /** Queries the state of the JBI Framework.
150: * @return true if the JBI framework is loaded, false otherwise.
151: */
152: public boolean isLoaded() {
153: return mLoaded;
154: }
155:
156: /**
157: * Unloads the JBI framework. When this method retuns, all
158: * public interfaces, system services, and JMX connector (if configured)
159: * have been destroyed.
160: * @throws java.lang.Exception failed to unload JBI framework
161: */
162: public synchronized void unload() throws Exception {
163: if (!mLoaded) {
164: return;
165: }
166:
167: shutdown();
168: terminate();
169:
170: mLoaded = false;
171: }
172:
173: /**
174: * This method returns the JMX Service URL for this server
175: * @throws java.lang.Exception if not able to get MBeanServerConnection
176: * @return MBeanServerConnection a connection to the MBeanServer
177: */
178: public MBeanServerConnection getMBeanServerConnection()
179: throws Exception {
180: return mPlatformContext.getMBeanServerConnection(null);
181: }
182:
183: }
|