|
Glassfish example source code file (EmbeddedOSGiGlassFishRuntimeBuilder.java)
The Glassfish EmbeddedOSGiGlassFishRuntimeBuilder.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html * or packager/legal/LICENSE.txt. See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each * file and include the License file at packager/legal/LICENSE.txt. * * GPL Classpath Exception: * Oracle designates this particular file as subject to the "Classpath" * exception as provided by Oracle in the GPL Version 2 section of the License * file that accompanied this code. * * Modifications: * If applicable, add the following below the License Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyright [year] [name of copyright owner]" * * Contributor(s): * If you wish your version of this file to be governed by only the CDDL or * only the GPL Version 2, indicate your decision by adding "[Contributor] * elects to include this software in this distribution under the [CDDL or GPL * Version 2] license." If you don't indicate a single choice of license, a * recipient has the option to distribute your version of this file under * either the CDDL, the GPL Version 2 or to extend the choice of license to * its licensees as provided above. However, if you add GPL Version 2 code * and therefore, elected the GPL Version 2 license, then the option applies * only if the new code is made subject to such option by the copyright * holder. */ package com.sun.enterprise.glassfish.bootstrap; import org.glassfish.embeddable.spi.RuntimeBuilder; import org.glassfish.embeddable.*; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.BundleReference; import org.osgi.util.tracker.ServiceTracker; import java.io.File; import java.io.FileFilter; import java.util.ArrayList; import java.util.List; /** * This {@link org.glassfish.embeddable.spi.RuntimeBuilder} is responsible for setting up a {@link GlassFishRuntime} * when user has a regular installation of GlassFish and they want to embed GlassFish in an existing OSGi runtime. * * It sets up the runtime like this: * 1. Installs all bundles located in glassfish modules directory. * 2. Starts the main bundle of GlassFish. Main bundle is identified by Bundle-SymbolicName * org.glassfish.core.kernel. This main bundle then is used to start any necessary bundle. This main bundle * registers a service of type GlassFishRuntime. * 3. It waits for GlassFishRuntime service to be available and returns when found. * * @see #build(org.glassfish.embeddable.BootstrapProperties) * @see #handles(org.glassfish.embeddable.BootstrapProperties) * * @author Sanjeeb.Sahoo@Sun.COM */ public class EmbeddedOSGiGlassFishRuntimeBuilder implements RuntimeBuilder { private BundleContext bundleContext; private String installRoot; private static final String mainBundleName = "org.glassfish.core.kernel"; /* package */ static final String BUILDER_NAME_PROPERTY = "GlassFish.BUILDER_NAME"; private static final String JAR_EXT = ".jar"; public boolean handles(BootstrapProperties bsProps) { return EmbeddedOSGiGlassFishRuntimeBuilder.class.getName(). equals(bsProps.getProperties().getProperty(BUILDER_NAME_PROPERTY)); } public GlassFishRuntime build(BootstrapProperties bsProps) throws GlassFishException { this.bundleContext = getBundleContext(); installRoot = bsProps.getInstallRoot(); // Install all gf bundles, start the primordial bundle and wait for GlassFishRuntime service to be available // We install the bundles in two installments, viz: // 1. First we install and start the endorsed bundles, // 2. Then we gor for the rest. // This way, endorsed bundles becomes candidates for providers instead of system bundle for a matching pkg. installAndStartEndorsedBundles(); installBundles(); configureBundles(); startBundles(); ServiceTracker st = new ServiceTracker(bundleContext, GlassFishRuntime.class.getName(), null); try { st.open(); return GlassFishRuntime.class.cast(st.waitForService(0)); }catch(Exception e) { throw new GlassFishException(e); } finally { st.close(); } } private void installAndStartEndorsedBundles() { List<Bundle> endorsedBundles = new ArrayList Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish EmbeddedOSGiGlassFishRuntimeBuilder.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.