Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2010-05-11 08:15:08 -0400
committerGlyn Normington2010-05-11 08:15:08 -0400
commit5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7 (patch)
tree5522099ce269769cdd39fe31fbe2d20afd416a1c /org.eclipse.virgo.kernel.dmfragment/src
parentb99bf75af622c030c6c9b479c1639925bd1ea872 (diff)
downloadorg.eclipse.virgo.kernel-5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7.tar.gz
org.eclipse.virgo.kernel-5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7.tar.xz
org.eclipse.virgo.kernel-5dfdbe75bdf1ba2476fe2e60e62e3454a3565de7.zip
initial checkin from dm Server kernel commit dffbc217a919cefba04886160ba820f2c6cf5f57 omitting build-kernel/bin/service
Diffstat (limited to 'org.eclipse.virgo.kernel.dmfragment/src')
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/ModuleBeanFactoryPostProcessor.java26
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBean.java58
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBeanPostProcessor.java31
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ContextClassLoaderPostProcessor.java68
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelAnnotationMBeanExporter.java39
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelExtensionConfiguringOsgiPostProcessor.java49
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelLoadTimeWeaver.java97
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelMBeanExporter.java40
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelModelMBean.java50
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/LoadTimeWeaverPostProcessor.java38
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/MBeanExporterPostProcessor.java61
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ServiceProxyRetryDisablingBundleListener.java63
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/main/resources/META-INF/spring/extender/kernel-dmfragment-context.xml39
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/test/java/.gitignore0
-rw-r--r--org.eclipse.virgo.kernel.dmfragment/src/test/resources/.gitignore0
15 files changed, 659 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/ModuleBeanFactoryPostProcessor.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/ModuleBeanFactoryPostProcessor.java
new file mode 100644
index 00000000..8c252b11
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/ModuleBeanFactoryPostProcessor.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment;
+
+import org.osgi.framework.BundleContext;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+/**
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Implementations must be thread-safe.
+ *
+ */
+public interface ModuleBeanFactoryPostProcessor {
+
+ void postProcess(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory);
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBean.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBean.java
new file mode 100644
index 00000000..579c69ff
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBean.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.BeanFactoryUtils;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ApplicationContextEvent;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean;
+
+/**
+ * {@link ApplicationContextShutdownBean} manages the shutting down of application contexts in the dm Server. In
+ * particular it is responsible for ensuring that Spring DM service proxies do not hold up application context shutdown.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * This class is thread safe.
+ *
+ */
+// Note that this class must not implement ApplicationListener<ContextClosedEvent> since it needs to work with Spring
+// 2.5.x as well as Spring 3 and beyond.
+final class ApplicationContextShutdownBean implements ApplicationListener<ApplicationEvent> {
+
+ private static final Logger logger = LoggerFactory.getLogger(ApplicationContextShutdownBean.class);
+
+ /**
+ * {@inheritDoc}
+ */
+ public void onApplicationEvent(ApplicationEvent event) {
+ if (event instanceof ContextClosedEvent) {
+ logger.info("Processing ContextClosedEvent '{}'", event);
+ ApplicationContext applicationContext = ((ApplicationContextEvent) event).getApplicationContext();
+ disableServiceProxyRetry(applicationContext);
+ }
+ }
+
+ static void disableServiceProxyRetry(ApplicationContext applicationContext) {
+ for (OsgiServiceProxyFactoryBean proxyBean : BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext,
+ OsgiServiceProxyFactoryBean.class, true, false).values()) {
+ logger.info("Setting timeout to 0 for proxy '{}' of application context '{}'", proxyBean, applicationContext);
+ proxyBean.setTimeout(0);
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBeanPostProcessor.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBeanPostProcessor.java
new file mode 100644
index 00000000..cb9e6b77
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ApplicationContextShutdownBeanPostProcessor.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import org.eclipse.virgo.kernel.dmfragment.ModuleBeanFactoryPostProcessor;
+import org.osgi.framework.BundleContext;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+
+
+final class ApplicationContextShutdownBeanPostProcessor implements ModuleBeanFactoryPostProcessor{
+
+ private static final String APPLICATION_CONTEXT_SHUTDOWN_BEAN_NAME = "org.eclipse.virgo.server.applicationContextShutdownBean";
+
+ /**
+ * {@inheritDoc}
+ */
+ public void postProcess(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory) {
+ beanFactory.registerSingleton(APPLICATION_CONTEXT_SHUTDOWN_BEAN_NAME, new ApplicationContextShutdownBean());
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ContextClassLoaderPostProcessor.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ContextClassLoaderPostProcessor.java
new file mode 100644
index 00000000..cb08f03d
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ContextClassLoaderPostProcessor.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.virgo.kernel.dmfragment.ModuleBeanFactoryPostProcessor;
+import org.osgi.framework.BundleContext;
+import org.springframework.beans.MutablePropertyValues;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.osgi.extender.OsgiBeanFactoryPostProcessor;
+import org.springframework.osgi.service.importer.support.ImportContextClassLoader;
+import org.springframework.osgi.service.importer.support.OsgiServiceCollectionProxyFactoryBean;
+import org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean;
+
+
+/**
+ * {@link OsgiBeanFactoryPostProcessor} that ensures that all service references are in unmanaged mode for thread
+ * context class loader propagation.<p/>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Threadsafe.
+ *
+ */
+final class ContextClassLoaderPostProcessor implements ModuleBeanFactoryPostProcessor {
+
+ private static final String PROPERTY_CONTEXT_CLASS_LOADER = "contextClassLoader";
+
+ private static final Set<String> IMPORTER_CLASS_NAMES = createImportClassNames();
+
+ /**
+ * {@inheritDoc}
+ */
+ public void postProcess(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory) {
+ String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
+ for (String name : beanDefinitionNames) {
+ BeanDefinition beanDefinition = beanFactory.getBeanDefinition(name);
+ if (isServiceImportDefinition(beanDefinition)) {
+ MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
+ propertyValues.addPropertyValue(PROPERTY_CONTEXT_CLASS_LOADER, ImportContextClassLoader.UNMANAGED.getLabel());
+ }
+ }
+ }
+
+ private static Set<String> createImportClassNames() {
+ Set<String> names = new HashSet<String>();
+ names.add(OsgiServiceProxyFactoryBean.class.getName());
+ names.add(OsgiServiceCollectionProxyFactoryBean.class.getName());
+ return names;
+ }
+
+ private boolean isServiceImportDefinition(BeanDefinition beanDefinition) {
+ return IMPORTER_CLASS_NAMES.contains(beanDefinition.getBeanClassName());
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelAnnotationMBeanExporter.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelAnnotationMBeanExporter.java
new file mode 100644
index 00000000..111b288f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelAnnotationMBeanExporter.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import javax.management.MBeanException;
+import javax.management.modelmbean.ModelMBean;
+
+import org.eclipse.virgo.kernel.shim.serviceability.TracingService;
+import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
+
+
+/**
+ * An extension of {@link AnnotationMBeanExporter} that exports Kernel-specific MBeans.
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * As thread-safe as <code>MBeanExporter</code>.
+ */
+final class KernelAnnotationMBeanExporter extends AnnotationMBeanExporter {
+
+ private final TracingService tracingService;
+
+ KernelAnnotationMBeanExporter(TracingService tracingService) {
+ this.tracingService = tracingService;
+ }
+
+ @Override
+ protected ModelMBean createModelMBean() throws MBeanException {
+ return new KernelModelMBean(this.tracingService, this.tracingService.getCurrentApplicationName());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelExtensionConfiguringOsgiPostProcessor.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelExtensionConfiguringOsgiPostProcessor.java
new file mode 100644
index 00000000..f20252ac
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelExtensionConfiguringOsgiPostProcessor.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.eclipse.virgo.kernel.dmfragment.ModuleBeanFactoryPostProcessor;
+import org.osgi.framework.BundleContext;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.osgi.extender.OsgiBeanFactoryPostProcessor;
+
+
+/**
+ * {@link OsgiBeanFactoryPostProcessor} implementation that plugs in Server extensions implementation when needed.<p/>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Threadsafe.
+ *
+ */
+final class KernelExtensionConfiguringOsgiPostProcessor implements OsgiBeanFactoryPostProcessor {
+
+ private final List<ModuleBeanFactoryPostProcessor> postProcessors = new CopyOnWriteArrayList<ModuleBeanFactoryPostProcessor>();
+
+ KernelExtensionConfiguringOsgiPostProcessor(List<ModuleBeanFactoryPostProcessor> defaultPostProcessors) {
+ this.postProcessors.addAll(defaultPostProcessors);
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void postProcessBeanFactory(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory) {
+ for (ModuleBeanFactoryPostProcessor postProcessor : this.postProcessors) {
+ postProcessor.postProcess(bundleContext, beanFactory);
+ }
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelLoadTimeWeaver.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelLoadTimeWeaver.java
new file mode 100644
index 00000000..1bb92fcd
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelLoadTimeWeaver.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import java.lang.instrument.ClassFileTransformer;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.springframework.beans.factory.BeanClassLoaderAware;
+import org.springframework.instrument.classloading.LoadTimeWeaver;
+import org.springframework.osgi.util.BundleDelegatingClassLoader;
+
+import org.eclipse.virgo.kernel.osgi.framework.InstrumentableClassLoader;
+import org.eclipse.virgo.kernel.osgi.framework.OsgiFramework;
+
+/**
+ * {@link LoadTimeWeaver} implementation that plugs into the {@link InstrumentableClassLoader
+ * InstrumentableClassLoaders} created for all installed bundles.<p/>
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Threadsafe.
+ *
+ */
+final class KernelLoadTimeWeaver implements LoadTimeWeaver, BeanClassLoaderAware {
+
+ private volatile InstrumentableClassLoader instrumentableClassLoader;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addTransformer(ClassFileTransformer transformer) {
+ this.instrumentableClassLoader.addClassFileTransformer(transformer);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ClassLoader getInstrumentableClassLoader() {
+ return (ClassLoader) this.instrumentableClassLoader;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ClassLoader getThrowawayClassLoader() {
+ return this.instrumentableClassLoader.createThrowAway();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setBeanClassLoader(ClassLoader classLoader) {
+ InstrumentableClassLoader instrumentableClassLoader = null;
+ if (classLoader instanceof InstrumentableClassLoader) {
+ instrumentableClassLoader = (InstrumentableClassLoader) classLoader;
+ } else if (classLoader instanceof BundleDelegatingClassLoader) {
+ Bundle bundle = ((BundleDelegatingClassLoader) classLoader).getBundle();
+ ClassLoader bundleClassLoader = getBundleClassLoader(bundle);
+ if (bundleClassLoader instanceof InstrumentableClassLoader) {
+ instrumentableClassLoader = (InstrumentableClassLoader) bundleClassLoader;
+ }
+ }
+ if (instrumentableClassLoader == null) {
+ throw new IllegalStateException("ClassLoader '" + classLoader + "' is not instrumentable.");
+ }
+ this.instrumentableClassLoader = instrumentableClassLoader;
+ }
+
+ /**
+ * Gets the {@link ClassLoader} for the supplied {@link Bundle}.
+ *
+ * @param bundle the <code>Bundle</code>.
+ * @return the <code>Bundles</code> <code>ClassLoader</code>.
+ */
+ private ClassLoader getBundleClassLoader(Bundle bundle) {
+ BundleContext bundleContext = bundle.getBundleContext();
+ ServiceReference serviceReference = bundleContext.getServiceReference(OsgiFramework.class.getName());
+ try {
+ OsgiFramework framework = (OsgiFramework) bundleContext.getService(serviceReference);
+ return framework.getBundleClassLoader(bundle);
+ } finally {
+ bundleContext.ungetService(serviceReference);
+ }
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelMBeanExporter.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelMBeanExporter.java
new file mode 100644
index 00000000..d6cb410b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelMBeanExporter.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import javax.management.MBeanException;
+import javax.management.modelmbean.ModelMBean;
+
+import org.eclipse.virgo.kernel.shim.serviceability.TracingService;
+import org.springframework.jmx.export.MBeanExporter;
+
+
+/**
+ * An extension of {@link MBeanExporter} that exports Server-specific MBeans.
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * As thread-safe as <code>MBeanExporter</code>.
+ *
+ */
+final class KernelMBeanExporter extends MBeanExporter {
+
+ private final TracingService tracingService;
+
+ KernelMBeanExporter(TracingService tracingService) {
+ this.tracingService = tracingService;
+ }
+
+ @Override
+ protected ModelMBean createModelMBean() throws MBeanException {
+ return new KernelModelMBean(this.tracingService, this.tracingService.getCurrentApplicationName());
+ }
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelModelMBean.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelModelMBean.java
new file mode 100644
index 00000000..3f357741
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/KernelModelMBean.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import javax.management.MBeanException;
+import javax.management.ReflectionException;
+import javax.management.RuntimeOperationsException;
+
+import org.eclipse.virgo.kernel.shim.serviceability.TracingService;
+import org.springframework.jmx.export.SpringModelMBean;
+
+
+/**
+ * An extension of {@link SpringModelMBean} that acts as a Server-specific MBeans.
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * As thread-safe as <code>SpringModelMBean</code>.
+ */
+final class KernelModelMBean extends SpringModelMBean {
+
+ private final TracingService tracingService;
+
+ private final String applicationName;
+
+ public KernelModelMBean(TracingService tracingService, String applicationName) throws RuntimeOperationsException, MBeanException {
+ this.tracingService = tracingService;
+ this.applicationName = applicationName;
+ }
+
+ @Override
+ public Object invoke(String opName, Object[] opArgs, String[] sig) throws MBeanException, ReflectionException {
+ String originalApplicationName = this.tracingService.getCurrentApplicationName();
+
+ try {
+ this.tracingService.setCurrentApplicationName(this.applicationName);
+ return super.invoke(opName, opArgs, sig);
+ } finally {
+ this.tracingService.setCurrentApplicationName(originalApplicationName);
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/LoadTimeWeaverPostProcessor.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/LoadTimeWeaverPostProcessor.java
new file mode 100644
index 00000000..fc3efdd6
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/LoadTimeWeaverPostProcessor.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import static org.springframework.context.ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME;
+
+import org.eclipse.virgo.kernel.dmfragment.ModuleBeanFactoryPostProcessor;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+
+
+final class LoadTimeWeaverPostProcessor implements ModuleBeanFactoryPostProcessor {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ public void postProcess(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory) {
+ if (beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {
+ AbstractBeanDefinition ltwBean = (AbstractBeanDefinition) beanFactory.getBeanDefinition(LOAD_TIME_WEAVER_BEAN_NAME);
+ ltwBean.setBeanClass(KernelLoadTimeWeaver.class);
+ logger.info("Found load-time weaver bean for bundle '{}'. Switching to ServerLoadTimeWeaver.", bundleContext.getBundle());
+ } else {
+ logger.info("Load-time weaving not enabled for bundle '{}',", bundleContext.getBundle());
+ }
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/MBeanExporterPostProcessor.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/MBeanExporterPostProcessor.java
new file mode 100644
index 00000000..d675f043
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/MBeanExporterPostProcessor.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import org.eclipse.virgo.kernel.dmfragment.ModuleBeanFactoryPostProcessor;
+import org.eclipse.virgo.kernel.shim.serviceability.TracingService;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.beans.factory.support.AbstractBeanDefinition;
+import org.springframework.jmx.export.MBeanExporter;
+import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
+
+
+final class MBeanExporterPostProcessor implements ModuleBeanFactoryPostProcessor {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ private final TracingService tracingService;
+
+ public MBeanExporterPostProcessor(TracingService tracingService) {
+ this.tracingService = tracingService;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void postProcess(BundleContext bundleContext, ConfigurableListableBeanFactory beanFactory) {
+ boolean foundExporter = false;
+ String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
+ for (String beanDefinitionName : beanDefinitionNames) {
+ AbstractBeanDefinition definition = (AbstractBeanDefinition) beanFactory.getBeanDefinition(beanDefinitionName);
+ if (MBeanExporter.class.getName().equals(definition.getBeanClassName())) {
+ definition.setBeanClass(KernelMBeanExporter.class);
+ definition.getConstructorArgumentValues().addGenericArgumentValue(this.tracingService);
+ foundExporter = true;
+ } else if (AnnotationMBeanExporter.class.getName().equals(definition.getBeanClassName())) {
+ definition.setBeanClass(KernelAnnotationMBeanExporter.class);
+ definition.getConstructorArgumentValues().addGenericArgumentValue(this.tracingService);
+ foundExporter = true;
+ }
+ }
+ if (foundExporter) {
+ logger.info("Found MBean exporter bean for bundle '{}'. Switching to ServerMBeanExporter or ServerAnnotationMBeanExporter.",
+ bundleContext.getBundle());
+ } else {
+ logger.info("MBean exporting not enabled for bundle '{}',", bundleContext.getBundle());
+ }
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ServiceProxyRetryDisablingBundleListener.java b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ServiceProxyRetryDisablingBundleListener.java
new file mode 100644
index 00000000..48af4475
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/java/org/eclipse/virgo/kernel/dmfragment/internal/ServiceProxyRetryDisablingBundleListener.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008, 2010 VMware Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VMware Inc. - initial contribution
+ *******************************************************************************/
+
+package org.eclipse.virgo.kernel.dmfragment.internal;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.SynchronousBundleListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
+import org.springframework.osgi.service.importer.support.OsgiServiceProxyFactoryBean;
+
+/**
+ * A {@link SynchronousBundleListener} that reacts to a {@link BundleEvent#STOPPING STOPPING} event for the system
+ * bundle. Upon such an event being received the listener retrieves all {@link ApplicationContext ApplicationContexts}
+ * from the service registry and disables retry on any {@link OsgiServiceProxyFactoryBean OsgiServiceProxyFactoryBeans}
+ * which they contain.
+ * <p />
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ *
+ * Thread-safe.
+ *
+ *
+ * @see ApplicationContextShutdownBean#disableServiceProxyRetry(ApplicationContext)
+ */
+class ServiceProxyRetryDisablingBundleListener implements SynchronousBundleListener {
+
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ ServiceProxyRetryDisablingBundleListener(BundleContext bundleContext) {
+ bundleContext.addBundleListener(this);
+ }
+
+ public void bundleChanged(BundleEvent event) {
+ if (event.getBundle().getBundleId() == 0 && event.getType() == BundleEvent.STOPPING) {
+ BundleContext bundleContext = event.getBundle().getBundleContext();
+ try {
+ ServiceReference[] applicationContextServiceReferences = event.getBundle().getBundleContext().getAllServiceReferences(
+ ApplicationContext.class.getName(), null);
+
+ for (ServiceReference applicationContextServiceReference : applicationContextServiceReferences) {
+ ApplicationContext applicationContext = (ApplicationContext) bundleContext.getService(applicationContextServiceReference);
+ ApplicationContextShutdownBean.disableServiceProxyRetry(applicationContext);
+ bundleContext.ungetService(applicationContextServiceReference);
+ }
+ } catch (InvalidSyntaxException ise) {
+ logger.error("Failed to retrieve all application contexts from service registry", ise);
+ }
+ }
+ }
+}
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/main/resources/META-INF/spring/extender/kernel-dmfragment-context.xml b/org.eclipse.virgo.kernel.dmfragment/src/main/resources/META-INF/spring/extender/kernel-dmfragment-context.xml
new file mode 100644
index 00000000..93ceda9a
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/main/resources/META-INF/spring/extender/kernel-dmfragment-context.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://www.springframework.org/schema/beans"
+ xmlns:osgi="http://www.springframework.org/schema/osgi"
+ xsi:schemaLocation="http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <osgi:reference id="tracingService" interface="org.eclipse.virgo.kernel.shim.serviceability.TracingService"/>
+
+ <bean id="serverExtensionConfigurer" class="org.eclipse.virgo.kernel.dmfragment.internal.KernelExtensionConfiguringOsgiPostProcessor">
+ <constructor-arg>
+ <list>
+ <bean class="org.eclipse.virgo.kernel.dmfragment.internal.ContextClassLoaderPostProcessor"/>
+ <bean class="org.eclipse.virgo.kernel.dmfragment.internal.LoadTimeWeaverPostProcessor"/>
+ <bean class="org.eclipse.virgo.kernel.dmfragment.internal.MBeanExporterPostProcessor">
+ <constructor-arg ref="tracingService"/>
+ </bean>
+ <bean class="org.eclipse.virgo.kernel.dmfragment.internal.ApplicationContextShutdownBeanPostProcessor"/>
+ </list>
+ </constructor-arg>
+ </bean>
+
+ <osgi:service ref="serverExtensionConfigurer" interface="org.springframework.osgi.extender.OsgiBeanFactoryPostProcessor" />
+
+ <bean id="taskExecutor" class="org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExecutor">
+ <constructor-arg value="region-dm-" />
+ <constructor-arg value="15" />
+ <constructor-arg ref="bundleContext"/>
+ </bean>
+
+ <alias alias="shutdownTaskExecutor" name="taskExecutor"/>
+
+ <bean id="serviceProxyRetryDisabler" class="org.eclipse.virgo.kernel.dmfragment.internal.ServiceProxyRetryDisablingBundleListener">
+ <constructor-arg ref="bundleContext"/>
+ </bean>
+
+</beans>
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/test/java/.gitignore b/org.eclipse.virgo.kernel.dmfragment/src/test/java/.gitignore
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/test/java/.gitignore
diff --git a/org.eclipse.virgo.kernel.dmfragment/src/test/resources/.gitignore b/org.eclipse.virgo.kernel.dmfragment/src/test/resources/.gitignore
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.dmfragment/src/test/resources/.gitignore

Back to the top