001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.management.j2ee.factory;
023:
024: import org.jboss.deployment.DeploymentInfo;
025: import org.jboss.logging.Logger;
026: import org.jboss.management.j2ee.MBean;
027: import org.jboss.management.j2ee.ServiceModule;
028:
029: import javax.management.MBeanServer;
030: import javax.management.ObjectName;
031: import java.util.List;
032: import java.util.ListIterator;
033:
034: /**
035: * @author Scott.Stark@jboss.org
036: * @version $Revision: 57197 $
037: */
038: public class ServiceModuleFactory implements ManagedObjectFactory {
039: private static Logger log = Logger
040: .getLogger(ServiceModuleFactory.class);
041:
042: /**
043: * Create JSR-77 SAR-Module
044: *
045: * @param server the MBeanServer context
046: * @param data arbitrary data associated with the creation context
047: */
048: public ObjectName create(MBeanServer server, Object data) {
049: if ((data instanceof DeploymentInfo) == false)
050: return null;
051:
052: DeploymentInfo di = (DeploymentInfo) data;
053: String moduleName = di.shortName;
054: ObjectName sarName = ServiceModule.create(server, moduleName,
055: di.localUrl);
056: if (sarName != null) {
057: log.debug("Created ServiceModule: " + sarName);
058: }
059:
060: try {
061: List mbeans = di.mbeans;
062: for (int i = 0; i < mbeans.size(); i++) {
063: ObjectName mbeanName = (ObjectName) mbeans.get(i);
064: // Create JSR-77 MBean
065: MBean.create(server, sarName.toString(), mbeanName);
066: log.debug("Create MBean, name: " + mbeanName
067: + ", SAR Module: " + sarName);
068: }
069: } catch (Throwable e) {
070: log.debug("Failed to create MBean, sarName:" + sarName, e);
071: }
072:
073: return sarName;
074: }
075:
076: public void destroy(MBeanServer server, Object data) {
077: if ((data instanceof DeploymentInfo) == false)
078: return;
079:
080: DeploymentInfo di = (DeploymentInfo) data;
081: List services = di.mbeans;
082: int lastService = services.size();
083:
084: for (ListIterator i = services.listIterator(lastService); i
085: .hasPrevious();) {
086: ObjectName name = (ObjectName) i.previous();
087: try {
088: // Destroy JSR-77 MBean
089: MBean.destroy(server, name.toString());
090: log.debug("Destroy MBean, name: " + name);
091: } catch (Throwable e) {
092: log.debug("Failed to remove remove JSR-77 MBean", e);
093: } // end of try-catch
094: }
095:
096: // Remove JSR-77 SAR-Module
097: String moduleName = di.shortName;
098: try {
099: ServiceModule.destroy(server, moduleName);
100: log.debug("Removed JSR-77 SAR: " + moduleName);
101: } catch (Throwable e) {
102: log.debug("Failed to remove JSR-77 SAR: " + moduleName);
103: }
104: }
105: }
|