[jboss-cvs] JBossAS SVN: r76258 - trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Jul 27 14:04:00 EDT 2008
Author: bstansberry at jboss.com
Date: 2008-07-27 14:04:00 -0400 (Sun, 27 Jul 2008)
New Revision: 76258
Added:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossWebMicrocontainerBeanLocator.java
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/MicrocontainerIntegrationLifecycleListener.java
Modified:
trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
Log:
[JBAS-5658] Initial Mod-Cluster integration into the JBossWeb Server
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossWebMicrocontainerBeanLocator.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossWebMicrocontainerBeanLocator.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/JBossWebMicrocontainerBeanLocator.java 2008-07-27 18:04:00 UTC (rev 76258)
@@ -0,0 +1,70 @@
+/*
+ * 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.web.tomcat.service.deployers;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.dependency.KernelController;
+
+/**
+ * Service locator utility for finding microcontainer beans associated with
+ * the <code>KernelController</code> that manages the local {@link TomcatService}.
+ *
+ * @author Brian Stansberry
+ *
+ */
+public class JBossWebMicrocontainerBeanLocator
+{
+ private static KernelController kernelController;
+
+ /**
+ * Returns the bean installed under the given name.
+ *
+ * @param beanName the name of the bean
+ * @return the bean, or <code>null</code> if no bean is installed under <code>name</code>
+ *
+ * @throws IllegalStateException if no KernelController is available to perform
+ * the lookup
+ */
+ public static Object getInstalledBean(Object beanName)
+ {
+ if (kernelController == null)
+ {
+ throw new IllegalStateException("KernelController not installed");
+ }
+
+ ControllerContext context = kernelController.getInstalledContext(beanName);
+ return context == null ? null : context.getTarget();
+ }
+
+ static void setKernelController(KernelController controller)
+ {
+ kernelController = controller;
+ }
+
+ /** Prevent instantiation */
+ private JBossWebMicrocontainerBeanLocator()
+ {
+
+ }
+
+}
Added: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/MicrocontainerIntegrationLifecycleListener.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/MicrocontainerIntegrationLifecycleListener.java (rev 0)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/MicrocontainerIntegrationLifecycleListener.java 2008-07-27 18:04:00 UTC (rev 76258)
@@ -0,0 +1,131 @@
+/*
+ * 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.web.tomcat.service.deployers;
+
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.jboss.logging.Logger;
+
+/**
+ * {@link LifecycleListener} that delegates handling of event callbacks
+ * to an arbitrary microcontainer bean that also implements
+ * <code>LifecycleListener</code>. Serves as an integration hook to allow
+ * microcontainer-based beans to integrate into the <code>server.xml</code> and
+ * <code>org.apache.tomcat.util.digester.Digester</code>-based process by
+ * which the JBoss Web server is instantiated.
+ * <p>
+ * Listener exposes a {@link #getDelegateBeanName() delegateBeanName} property
+ * (configurable in <code>server.xml</code>). Upon first
+ * {@link #lifecycleEvent(LifecycleEvent) receipt of a lifecycle event},
+ * a service lookup of the bean registered in the microcontainer under
+ * <code>delegateBeanName</code> is performed. All lifecycle event callbacks
+ * are delegated to that bean.
+ * </p>
+ *
+ * @author Brian Stansberry
+ */
+public class MicrocontainerIntegrationLifecycleListener implements LifecycleListener
+{
+ private static final Logger log = Logger.getLogger(MicrocontainerIntegrationLifecycleListener.class);
+
+ private volatile boolean inited;
+ private LifecycleListener delegate;
+ private String delegateBeanName;
+ private boolean failIfBeanMissing = true;
+ private boolean warnIfBeanMissing = true;
+
+ public final String getDelegateBeanName()
+ {
+ return this.delegateBeanName;
+ }
+
+ public final void setDelegateBeanName(String delegateBeanName)
+ {
+ this.delegateBeanName = delegateBeanName;
+ }
+
+ public boolean getFailIfBeanMissing()
+ {
+ return this.failIfBeanMissing;
+ }
+
+ public void setFailIfBeanMissing(boolean failIfBeanMissing)
+ {
+ this.failIfBeanMissing = failIfBeanMissing;
+ }
+
+ public final boolean getWarnIfBeanMissing()
+ {
+ return this.warnIfBeanMissing;
+ }
+
+ public final void setWarnIfBeanMissing(boolean warnIfBeanMissing)
+ {
+ this.warnIfBeanMissing = warnIfBeanMissing;
+ }
+
+ /**
+ * Passes the event to the delegate bean. On first invocation does
+ * the lookup of the delegate bean.
+ *
+ * @param event the event
+ */
+ public void lifecycleEvent(LifecycleEvent event)
+ {
+ if (!inited)
+ {
+ init();
+ }
+
+ if (this.delegate != null)
+ {
+ this.delegate.lifecycleEvent(event);
+ }
+ }
+
+ private synchronized void init()
+ {
+ if (!inited)
+ {
+ if (this.delegateBeanName != null)
+ {
+ this.delegate = (LifecycleListener) JBossWebMicrocontainerBeanLocator.getInstalledBean(this.delegateBeanName);
+ }
+
+ if (this.delegate == null)
+ {
+ if (this.failIfBeanMissing)
+ {
+ throw new IllegalStateException("Unable to locate delegate bean " + this.delegateBeanName + "; listener is nonfunctional");
+ }
+ else if (this.warnIfBeanMissing)
+ {
+ log.warn("Unable to locate delegate bean " + this.delegateBeanName + "; listener is nonfunctional");
+ }
+ }
+
+ this.inited = true;
+ }
+ }
+
+}
Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java 2008-07-27 09:39:53 UTC (rev 76257)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatService.java 2008-07-27 18:04:00 UTC (rev 76258)
@@ -39,6 +39,8 @@
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.CatalinaProperties;
import org.apache.tomcat.util.modeler.Registry;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.security.plugins.JaasSecurityManagerServiceMBean;
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.system.server.Server;
@@ -62,6 +64,7 @@
*/
public class TomcatService extends ServiceMBeanSupport implements NotificationListener, TomcatServiceMBean
{
+
/** The associated Tomcat deployer * */
private TomcatDeployer tomcatDeployer;
@@ -491,4 +494,31 @@
if (this.tomcatDeployer != null)
this.tomcatDeployer.setSessionCookieForSSOAuth(sessionCookieForSSOAuth);
}
+
+ /**
+ * {@inheritDoc}
+ *
+ * Overrides the superclass version to inject the <code>KernelController</code>
+ * into {@link JBossWebMicrocontainerBeanLocator}.
+ */
+ @Override
+ public void setKernelControllerContext(KernelControllerContext controllerContext) throws Exception
+ {
+ super.setKernelControllerContext(controllerContext);
+ KernelController kernelController = controllerContext == null ? null : controllerContext.getKernel().getController();
+ JBossWebMicrocontainerBeanLocator.setKernelController(kernelController);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Overrides the superclass version to clear the <code>KernelController</code>
+ * from {@link JBossWebMicrocontainerBeanLocator}.
+ */
+ @Override
+ public void unsetKernelControllerContext(KernelControllerContext controllerContext) throws Exception
+ {
+ super.unsetKernelControllerContext(controllerContext);
+ JBossWebMicrocontainerBeanLocator.setKernelController(null);
+ }
}
More information about the jboss-cvs-commits
mailing list