[jboss-cvs] JBossAS SVN: r84799 - in projects/jboss-osgi/trunk/runtime/deployer/src/main: java/org/jboss/osgi/deployer/helpers and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Feb 26 06:53:49 EST 2009
Author: alesj
Date: 2009-02-26 06:53:49 -0500 (Thu, 26 Feb 2009)
New Revision: 84799
Added:
projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleDeployer.java
projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/
projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/BundleClassLoader.java
projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java
Modified:
projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java
projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
Log:
[JBOSGI-36]; create CL off a Bundle.
Start/stop bundle in diff deployer.
Copied: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleDeployer.java (from rev 84793, projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java)
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleDeployer.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleDeployer.java 2009-02-26 11:53:49 UTC (rev 84799)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployer;
+
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.deployer.helpers.BundleClassLoader;
+import org.jboss.osgi.deployer.helpers.ResolvedBundleDependencyItem;
+import org.osgi.framework.Bundle;
+
+/**
+ * This is the Bundle Deployer
+ *
+ * @author Ales.Justin at jboss.org
+ */
+public class BundleDeployer extends AbstractSimpleRealDeployer<Bundle>
+{
+ public BundleDeployer()
+ {
+ super(Bundle.class);
+ addOutput(ClassLoaderFactory.class);
+ setStage(DeploymentStages.POST_PARSE);
+ }
+
+ public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
+ {
+ // create bundle delegate classloader
+ ClassLoaderFactory factory = createClassLoaderFactory(bundle);
+ unit.addAttachment(ClassLoaderFactory.class, factory);
+
+ // create dependency items
+ DependencyItem resolvedBundleDI = createResolvedBudleDependencyItem(bundle);
+ unit.addIDependOn(resolvedBundleDI);
+ }
+
+ /**
+ * Create classloader factory.
+ *
+ * @param bundle the bundle
+ * @return new classloader factory
+ */
+ protected ClassLoaderFactory createClassLoaderFactory(final Bundle bundle)
+ {
+ return new ClassLoaderFactory()
+ {
+ public ClassLoader createClassLoader(DeploymentUnit unit) throws Exception
+ {
+ return BundleClassLoader.createBundleClassLoaderFor(bundle);
+ }
+
+ public void removeClassLoader(DeploymentUnit unit) throws Exception
+ {
+ }
+ };
+ }
+
+ /**
+ * Create resolved bundle dependency item.
+ *
+ * @param bundle the bundle
+ * @return new dependency item
+ */
+ protected DependencyItem createResolvedBudleDependencyItem(Bundle bundle)
+ {
+ return new ResolvedBundleDependencyItem(bundle);
+ }
+}
\ No newline at end of file
Added: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleStartStopDeployer.java 2009-02-26 11:53:49 UTC (rev 84799)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployer;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * This is the Bundle start/stop Deployer
+ *
+ * @author Ales.Justin at jboss.org
+ */
+public class BundleStartStopDeployer extends AbstractSimpleRealDeployer<Bundle>
+{
+ public BundleStartStopDeployer()
+ {
+ super(Bundle.class);
+ setStage(DeploymentStages.POST_CLASSLOADER);
+ }
+
+ public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
+ {
+ try
+ {
+ bundle.start();
+ }
+ catch (BundleException e)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Exception starting bundle", e);
+ }
+ }
+
+ @Override
+ public void undeploy(DeploymentUnit unit, Bundle bundle)
+ {
+ try
+ {
+ bundle.stop();
+ }
+ catch (BundleException e)
+ {
+ log.warn("Exception stopping bundle: " + e);
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java 2009-02-26 11:44:16 UTC (rev 84798)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/OSGiDeployer.java 2009-02-26 11:53:49 UTC (rev 84799)
@@ -27,6 +27,7 @@
import java.util.List;
import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.osgi.framework.Bundle;
@@ -48,6 +49,8 @@
public OSGiDeployer()
{
super(OSGiMetaData.class);
+ addOutput(Bundle.class);
+ setStage(DeploymentStages.POST_PARSE);
}
public void setBundleContext(BundleContext bundleContext)
@@ -79,14 +82,12 @@
if (skipBundles != null && skipBundles.contains(bundleUri) == false)
{
Bundle bundle = bundleContext.installBundle(bundleUri.toString());
- bundle.start();
-
unit.addAttachment(Bundle.class, bundle);
}
}
catch (BundleException ex)
{
- throw new DeploymentException("Cannot install bundle: " + metadata, ex);
+ throw DeploymentException.rethrowAsDeploymentException("Cannot install bundle: " + metadata, ex);
}
}
@@ -103,7 +104,7 @@
}
catch (BundleException ex)
{
- log.error(ex);
+ log.warn(ex);
}
}
}
Added: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/BundleClassLoader.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/BundleClassLoader.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/BundleClassLoader.java 2009-02-26 11:53:49 UTC (rev 84799)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployer.helpers;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+/**
+ * Bundle backed classloader.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class BundleClassLoader extends ClassLoader
+{
+ private Bundle bundle;
+
+ public static BundleClassLoader createBundleClassLoaderFor(final Bundle bundle)
+ {
+ if (bundle == null)
+ throw new IllegalArgumentException("Null bundle");
+
+ return AccessController.doPrivileged(new PrivilegedAction<BundleClassLoader>()
+ {
+ public BundleClassLoader run()
+ {
+ return new BundleClassLoader(bundle);
+ }
+ });
+ }
+
+ private BundleClassLoader(Bundle bundle)
+ {
+ this.bundle = bundle;
+ }
+
+ protected Class findClass(String name) throws ClassNotFoundException
+ {
+ return bundle.loadClass(name);
+ }
+
+ protected URL findResource(String name)
+ {
+ return bundle.getResource(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Enumeration<URL> findResources(String name) throws IOException
+ {
+ return bundle.getResources(name);
+ }
+
+ public URL getResource(String name)
+ {
+ return findResource(name);
+ }
+
+ public Class loadClass(String name) throws ClassNotFoundException
+ {
+ return findClass(name);
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ return true;
+
+ if (o instanceof BundleClassLoader == false)
+ return false;
+
+ final BundleClassLoader bundleDelegatingClassLoader = (BundleClassLoader)o;
+ return bundle.equals(bundleDelegatingClassLoader.bundle);
+ }
+
+ public int hashCode()
+ {
+ return bundle.hashCode();
+ }
+
+ public String toString()
+ {
+ Dictionary dictionary = bundle.getHeaders();
+ String bname = dictionary.get(Constants.BUNDLE_NAME) + "(" + dictionary.get(Constants.BUNDLE_SYMBOLICNAME) + ")";
+ return "BundleClassLoader for [" + bname + "]";
+ }
+}
Added: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/helpers/ResolvedBundleDependencyItem.java 2009-02-26 11:53:49 UTC (rev 84799)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployer.helpers;
+
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.osgi.framework.Bundle;
+
+/**
+ * Resolved bundle dependency item.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ResolvedBundleDependencyItem extends AbstractDependencyItem
+{
+ private static final ControllerState CL = new ControllerState(DeploymentStages.CLASSLOADER.getName());
+ private final Bundle bundle;
+
+ public ResolvedBundleDependencyItem(Bundle bundle)
+ {
+ super(null, null, CL, null);
+ if (bundle == null)
+ throw new IllegalArgumentException("Null bundle");
+
+ this.bundle = bundle;
+ }
+
+ @Override
+ public boolean resolve(Controller controller)
+ {
+ setResolved(bundle.getState() == Bundle.RESOLVED);
+ return isResolved();
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml 2009-02-26 11:44:16 UTC (rev 84798)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml 2009-02-26 11:53:49 UTC (rev 84799)
@@ -71,4 +71,10 @@
<property name="skipBundles"><inject bean="jboss.osgi:service=Framework" property="autoInstall" /></property>
</bean>
+ <!-- The Bundle Deployer -->
+ <bean name="jboss.osgi:service=BundleDeployer" class="org.jboss.osgi.deployer.BundleDeployer"/>
+
+ <!-- The Bundle start/stop Deployer -->
+ <bean name="jboss.osgi:service=Deployer" class="org.jboss.osgi.deployer.BundleStartStopDeployer"/>
+
</deployment>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list