[jboss-svn-commits] JBL Code SVN: r29914 - labs/jbossesb/workspace/tfennelly/war-deploy-barrier.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Nov 3 11:37:33 EST 2009


Author: tfennelly
Date: 2009-11-03 11:37:32 -0500 (Tue, 03 Nov 2009)
New Revision: 29914

Added:
   labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierController.java
   labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierControllerMBean.java
Log:
added

Added: labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierController.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierController.java	                        (rev 0)
+++ labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierController.java	2009-11-03 16:37:32 UTC (rev 29914)
@@ -0,0 +1,164 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.dependencies;
+
+import org.jboss.system.ListenerServiceMBeanSupport;
+import org.jboss.system.ServiceMBean;
+import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.deployment.DeploymentInfo;
+import org.jboss.deployment.SubDeployer;
+import org.jboss.metadata.WebMetaData;
+import org.jboss.logging.Logger;
+import org.jboss.mx.server.ServerObjectInstance;
+
+import javax.management.*;
+import java.util.*;
+
+/**
+ * WAR Deployment Barrier Controller Service MBean.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class WarDeploymentBarrierController extends ListenerServiceMBeanSupport implements WarDeploymentBarrierControllerMBean {
+
+    private final static Logger logger = Logger.getLogger(WarDeploymentBarrierController.class);
+
+    private static final String JBOSS_ESB_WARBARRIER_ON_PREFIX = "jboss.esb:WARBarrier=";
+
+    private Map<ObjectName, WarDeploymentBarrierController.WarDeploymentBarrier> warDeploymentBarriers = new HashMap<ObjectName, WarDeploymentBarrierController.WarDeploymentBarrier>();
+
+    protected void createService() throws Exception {
+        List<SubscriptionInfo> subscriptions = new ArrayList<SubscriptionInfo>();
+        ObjectName wsObjectName = new ObjectName("jboss.web:service=WebServer");
+
+        subscriptions.add(new SubscriptionInfo(wsObjectName, "WebServer", null));
+        subscribe(subscriptions, true, getServiceName());
+
+        // Some wars may already be deployed.  Need to add barrier beans for those...
+        registerExistingDeployments();
+    }
+
+    protected void destroyService() throws Exception {
+        try {
+            unsubscribe();
+        } finally {
+            if(!warDeploymentBarriers.isEmpty()) {
+                Set<Map.Entry<ObjectName, WarDeploymentBarrier>> barriers = warDeploymentBarriers.entrySet();
+                for(Map.Entry<ObjectName, WarDeploymentBarrier> barrier : barriers) {
+                    unregisterBarrierMBean(barrier.getKey(), barrier.getValue());
+                }
+            }
+        }
+    }
+
+    private void handle(Notification notification) {
+        Object userData = notification.getUserData();
+
+        if(userData instanceof DeploymentInfo) {
+            DeploymentInfo deploymentInfo = (DeploymentInfo) userData;
+
+            if(deploymentInfo.metaData instanceof WebMetaData) {
+                ObjectName barrierObjectName;
+
+                try {
+                    barrierObjectName = toBarrierObjectName(deploymentInfo.shortName);
+                } catch (MalformedObjectNameException e) {
+                    logger.warn("Failed to create WAR Deployment Barrier MBean ObjectName for WAR deployment '" + deploymentInfo.shortName + "'.", e);
+                    return;
+                }
+
+                if(notification.getType().equals(SubDeployer.START_NOTIFICATION)) {
+                    if(!warDeploymentBarriers.containsKey(barrierObjectName)) {
+                        registerBarrierMBean(barrierObjectName);
+                    }
+                } else if(notification.getType().equals(SubDeployer.STOP_NOTIFICATION)) {
+                    WarDeploymentBarrier barrier = warDeploymentBarriers.get(barrierObjectName);
+                    if(barrier != null) {
+                        unregisterBarrierMBean(barrierObjectName, barrier);
+                    }
+                }
+            }
+        }
+    }
+
+    private void registerBarrierMBean(ObjectName barrierObjectName) {
+        WarDeploymentBarrier barrier = new WarDeploymentBarrier();
+        try {
+            getServer().registerMBean(barrier, barrierObjectName);
+            barrier.create();
+            barrier.start();
+            warDeploymentBarriers.put(barrierObjectName, barrier);
+            logger.debug("Registered WAR Barrier: " + barrierObjectName);
+        } catch (Exception e) {
+            logger.warn("Failed to register WAR Deployment Barrier MBean.", e);
+        }
+    }
+
+    private void unregisterBarrierMBean(ObjectName barrierObjectName, WarDeploymentBarrier barrier) {
+        try {
+            barrier.stop();
+            barrier.destroy();
+            getServer().unregisterMBean(barrierObjectName);
+            logger.debug("Unregistered WAR Barrier: " + barrierObjectName);
+        } catch (Exception e) {
+            logger.warn("Failed to unregister WAR Deployment Barrier MBean.", e);
+        } finally {
+            warDeploymentBarriers.remove(barrierObjectName);
+        }
+    }
+
+    private void registerExistingDeployments() {
+        try {
+            Set<ServerObjectInstance> existingDeployments = getServer().queryMBeans(new ObjectName("jboss.web.deployment:*"), null);
+            for(ServerObjectInstance deployment : existingDeployments) {
+                ObjectName warObjectName = deployment.getObjectName();
+                Hashtable keyPropertyList = warObjectName.getKeyPropertyList();
+
+                if(keyPropertyList != null) {
+                    String warName = (String) keyPropertyList.get("war");
+                    if(warName != null) {
+                        registerBarrierMBean(toBarrierObjectName(warName));
+                    }
+                }
+            }                                   
+        } catch (MalformedObjectNameException e) {
+            logger.warn("Failed to capture list of deployed web objects.", e);
+        }
+    }
+
+    private ObjectName toBarrierObjectName(String warName) throws MalformedObjectNameException {
+        return new ObjectName(JBOSS_ESB_WARBARRIER_ON_PREFIX + warName);
+    }
+
+    public void handleNotification(Notification notification, Object handback) {
+        handle(notification);
+        super.handleNotification(notification, handback);
+    }
+
+    public void handleNotification2(Notification notification, Object handback) {
+        handle(notification);
+        super.handleNotification2(notification, handback);
+    }
+
+    public static interface WarDeploymentBarrierMBean extends ServiceMBean {
+    }
+    public static class WarDeploymentBarrier extends ServiceMBeanSupport implements WarDeploymentBarrierMBean {
+    }
+}

Added: labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierControllerMBean.java
===================================================================
--- labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierControllerMBean.java	                        (rev 0)
+++ labs/jbossesb/workspace/tfennelly/war-deploy-barrier/WarDeploymentBarrierControllerMBean.java	2009-11-03 16:37:32 UTC (rev 29914)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.dependencies;
+
+import org.jboss.system.ListenerServiceMBean;
+
+/**
+ * WAR Deployment Barrier Controller Service MBean interface.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface WarDeploymentBarrierControllerMBean extends ListenerServiceMBean {
+    
+}



More information about the jboss-svn-commits mailing list