[jboss-cvs] JBossAS SVN: r88274 - in branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management: views and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 6 12:01:16 EDT 2009
Author: emuckenhuber
Date: 2009-05-06 12:01:15 -0400 (Wed, 06 May 2009)
New Revision: 88274
Added:
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AggregatingManagementView.java
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractManagedDeploymentView.java
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractProfileView.java
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/BootstrapProfileView.java
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/MBeanProfileView.java
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/PlatformMbeansView.java
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/ProfileView.java
Log:
basic mgtView using multiple single profile views.
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AggregatingManagementView.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AggregatingManagementView.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/AggregatingManagementView.java 2009-05-06 16:01:15 UTC (rev 88274)
@@ -0,0 +1,700 @@
+/*
+ * 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.profileservice.management;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.management.DeploymentTemplate;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.NameMatcher;
+import org.jboss.deployers.spi.management.RuntimeComponentDispatcher;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ActivationPolicy;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.profileservice.management.views.AbstractProfileView;
+import org.jboss.profileservice.management.views.BootstrapProfileView;
+import org.jboss.profileservice.management.views.PlatformMbeansView;
+import org.jboss.profileservice.management.views.ProfileView;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
+import org.jboss.profileservice.spi.NoSuchProfileException;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.system.server.profileservice.attachments.AttachmentStore;
+
+/**
+ * A aggregating management view, handling profile views for all active profiles.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class AggregatingManagementView extends AbstractTemplateCreator implements ManagementView
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AggregatingManagementView.class);
+
+ /** The bundle name. */
+ private static final String BUNDLE_NAME = "org.jboss.profileservice.management.messages";
+
+ /** The internationalization resource bundle. */
+ private ResourceBundle i18n;
+ /** the Locale for the i18n messages. */
+ private Locale currentLocale;
+ /** The formatter used for i18n messages. */
+ private MessageFormat formatter = new MessageFormat("");
+
+ /** The profile service. */
+ private ProfileService ps;
+
+ /** The runtime component dispatcher. */
+ private RuntimeComponentDispatcher dispatcher;
+ private ManagedOperationProxyFactory proxyFactory;
+
+ /** The main deployer. */
+ private MainDeployer mainDeployer;
+
+ /** The attachment store. */
+ private AttachmentStore store;
+
+ /** The bootstrap deployment name to ManagedDeployment map. */
+ private Map<String, ManagedDeployment> bootstrapManagedDeployments = Collections.emptyMap();
+
+ /** The deployment templates that have been registered with the MV. */
+ private HashMap<String, DeploymentTemplate> templates = new HashMap<String, DeploymentTemplate>();
+
+ /** The profile views. */
+ private Map<ProfileKey, AbstractProfileView> profileViews = new ConcurrentHashMap<ProfileKey, AbstractProfileView>();
+
+ public AggregatingManagementView()
+ {
+ currentLocale = Locale.getDefault();
+ formatter.setLocale(currentLocale);
+ i18n = ResourceBundle.getBundle(BUNDLE_NAME, currentLocale);
+ }
+
+ public RuntimeComponentDispatcher getDispatcher()
+ {
+ return dispatcher;
+ }
+
+ public void setDispatcher(RuntimeComponentDispatcher dispatcher)
+ {
+ this.dispatcher = dispatcher;
+ }
+
+ public ProfileService getProfileService()
+ {
+ return ps;
+ }
+
+ public void setProfileService(ProfileService ps)
+ {
+ this.ps = ps;
+ }
+
+ public ManagedOperationProxyFactory getProxyFactory()
+ {
+ return proxyFactory;
+ }
+
+ public void setProxyFactory(ManagedOperationProxyFactory proxyFactory)
+ {
+ this.proxyFactory = proxyFactory;
+ }
+
+ public AttachmentStore getAttachmentStore()
+ {
+ return store;
+ }
+
+ public void setAttachmentStore(AttachmentStore store)
+ {
+ this.store = store;
+ }
+
+ public MainDeployer getMainDeployer()
+ {
+ return mainDeployer;
+ }
+
+ public void setMainDeployer(MainDeployer mainDeployer)
+ {
+ this.mainDeployer = mainDeployer;
+ }
+
+ public Map<String, ManagedDeployment> getBootstrapManagedDeployments()
+ {
+ return bootstrapManagedDeployments;
+ }
+
+ public void setBootstrapManagedDeployments(Map<String, ManagedDeployment> bootstrapManagedDeployments)
+ {
+ this.bootstrapManagedDeployments = bootstrapManagedDeployments;
+ }
+
+ public void start() throws Exception
+ {
+ if(this.proxyFactory == null)
+ throw new IllegalStateException("proxy factory not injected");
+
+ // Add the platform MBeans
+ addView(new PlatformMbeansView(this.proxyFactory));
+
+ // Add the bootstrap deployments
+ if(this.bootstrapManagedDeployments != null)
+ {
+ addView(new BootstrapProfileView(this.proxyFactory,
+ this.bootstrapManagedDeployments.values()));
+ }
+ }
+
+ public boolean load()
+ {
+ return loadProfiles(false);
+ }
+
+ public void reload()
+ {
+ loadProfiles(true);
+ }
+
+ public void process() throws Exception
+ {
+ // FIXME process
+ }
+
+ public void addView(AbstractProfileView view)
+ {
+ if(view == null)
+ throw new IllegalArgumentException("null view");
+ if(view.getProfileKey() == null)
+ throw new IllegalArgumentException("null profile key");
+
+ this.profileViews.put(view.getProfileKey(), view);
+ log.debug("add view: " + view);
+ }
+
+ public void removeView(AbstractProfileView view)
+ {
+ if(view == null)
+ throw new IllegalArgumentException("null view");
+ if(view.getProfileKey() == null)
+ throw new IllegalArgumentException("null profile key");
+
+ this.profileViews.remove(view.getProfileKey());
+ log.debug("remove view: " + view);
+ }
+
+ public void addTemplate(DeploymentTemplate template)
+ {
+ this.templates.put(template.getInfo().getName(), template);
+ log.debug("addTemplate: " + template);
+ }
+
+ public void removeTemplate(DeploymentTemplate template)
+ {
+ this.templates.remove(template.getInfo().getName());
+ log.debug("removeTemplate: " + template);
+ }
+
+ public void applyTemplate(String deploymentBaseName, DeploymentTemplateInfo info) throws Exception
+ {
+ if(deploymentBaseName == null)
+ throw new IllegalArgumentException("Null deployment base name.");
+ if(info == null)
+ throw new IllegalArgumentException("Null template info.");
+
+ DeploymentTemplate template = templates.get(info.getName());
+ if( template == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchTemplate"));
+ Object[] args = {info.getName()};
+ String msg = formatter.format(args);
+ throw new IllegalStateException(msg);
+ }
+
+ // Create a deployment base from the template
+ if( log.isTraceEnabled() )
+ log.trace("applyTemplate, deploymentBaseName=" + deploymentBaseName + ", info=" + info);
+
+ // Apply the template
+ super.applyTemplate(template, deploymentBaseName, info);
+
+ // reload this profile
+ this.profileViews.put(getDefaulProfiletKey(), createProfileView(getDefaulProfiletKey()));
+ }
+
+ public ManagedComponent getComponent(String name, ComponentType type) throws Exception
+ {
+ Set<ManagedComponent> components = getComponentsForType(type);
+ ManagedComponent comp = null;
+ if(components != null)
+ {
+ for(ManagedComponent mc : components)
+ {
+ if(mc.getName().equals(name))
+ {
+ comp = mc;
+ break;
+ }
+ }
+ }
+ if(comp != null)
+ {
+ Map<String, ManagedProperty> props = comp.getProperties();
+ Set<ManagedOperation> ops = comp.getOperations();
+ log.debug("Component"
+ +"(ops.size="
+ +ops != null ? ops.size() : 0
+ +",props.size=)"
+ +props != null ? props.size() : 0);
+ }
+ return comp;
+ }
+
+ public Set<ManagedComponent> getComponentsForType(ComponentType type) throws Exception
+ {
+ Set<ManagedComponent> components = new HashSet<ManagedComponent>();
+ for(AbstractProfileView view : profileViews.values())
+ {
+ components.addAll(view.getComponentsForType(type));
+ }
+ return components;
+ }
+
+ public ManagedDeployment getDeployment(String name) throws NoSuchDeploymentException
+ {
+ List<ManagedDeployment> deployments = new ArrayList<ManagedDeployment>();
+ for(AbstractProfileView view : profileViews.values())
+ {
+ deployments.addAll(view.getDeployment(name));
+ }
+ if(deployments.size() == 0)
+ {
+ throw new NoSuchDeploymentException(name);
+ }
+ else if(deployments.size() > 1)
+ {
+ throw new NoSuchDeploymentException("multiple matching deployments found for name: " + name
+ + ", available: " + deployments);
+ }
+ return deployments.get(0);
+ }
+
+ public Set<String> getDeploymentNames()
+ {
+ Set<String> deploymentNames = new TreeSet<String>();
+ for(AbstractProfileView view : profileViews.values())
+ {
+ deploymentNames.addAll(view.getDeploymentNames());
+ }
+ return deploymentNames;
+ }
+
+ public Set<String> getDeploymentNamesForType(String type)
+ {
+ Set<String> deploymentNames = new TreeSet<String>();
+ for(AbstractProfileView view : profileViews.values())
+ {
+ deploymentNames.addAll(view.getDeploymentNamesForType(type));
+ }
+ return deploymentNames;
+ }
+
+ public Set<ManagedDeployment> getDeploymentsForType(String type) throws Exception
+ {
+ Set<ManagedDeployment> deployments = new HashSet<ManagedDeployment>();
+ for(AbstractProfileView view : profileViews.values())
+ {
+ deployments.addAll(view.getDeploymentsForType(type));
+ }
+ return deployments;
+ }
+
+ public Set<ManagedComponent> getMatchingComponents(String name, ComponentType type,
+ NameMatcher<ManagedComponent> matcher)
+ throws Exception
+ {
+ Set<ManagedComponent> components = getComponentsForType(type);
+ Set<ManagedComponent> matched = new HashSet<ManagedComponent>();
+ if(components != null)
+ {
+ for(ManagedComponent mc : components)
+ {
+ if(matcher.matches(mc, name))
+ matched.add(mc);
+ }
+ }
+ if(matched.size() > 0)
+ {
+ log.debug("getComponents matched: "+matched);
+ }
+ return matched;
+ }
+
+ public Set<String> getMatchingDeploymentName(String regex)
+ throws NoSuchDeploymentException
+ {
+ Set<String> names = getDeploymentNames();
+ HashSet<String> matches = new HashSet<String>();
+ Pattern p = Pattern.compile(regex);
+ for(String name : names)
+ {
+ Matcher m = p.matcher(name);
+ if( m.matches() )
+ matches.add(name);
+ }
+ if( matches.size() == 0 )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchDeploymentException")); //$NON-NLS-1$
+ Object[] args = {regex};
+ String msg = formatter.format(args);
+ throw new NoSuchDeploymentException(msg);
+ }
+ return matches;
+ }
+
+ public Set<ManagedDeployment> getMatchingDeployments(String name, NameMatcher<ManagedDeployment> matcher)
+ throws NoSuchDeploymentException, Exception
+ {
+ // FIXME getMatchingDeployments
+ return new HashSet<ManagedDeployment>();
+ }
+
+ public DeploymentTemplateInfo getTemplate(String name)
+ throws NoSuchDeploymentException
+ {
+ DeploymentTemplate template = templates.get(name);
+ if( template == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchTemplate")); //$NON-NLS-1$
+ Object[] args = {name};
+ String msg = formatter.format(args);
+ throw new IllegalStateException(msg);
+ }
+
+ // Make sure to return a copy to avoid call by reference uses modifying the template values
+ DeploymentTemplateInfo info = template.getInfo();
+ info = info.copy();
+ log.debug("getTemplate, "+info);
+ return info;
+ }
+
+ public Set<String> getTemplateNames()
+ {
+ return new HashSet<String>(templates.keySet());
+ }
+
+ public void removeComponent(ManagedComponent comp) throws Exception
+ {
+ if(comp == null)
+ throw new IllegalArgumentException("null managed component.");
+ //
+ ManagedDeployment md = comp.getDeployment();
+
+ // Get the parent
+ while( md.getParent() != null )
+ md = md.getParent();
+
+ String name = md.getName();
+ ProfileDeployment profileDeployment = getProfileDeployment(name);
+ if( profileDeployment == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchDeploymentException")); //$NON-NLS-1$
+ Object[] args = {name};
+ String msg = formatter.format(args);
+ throw new NoSuchDeploymentException(msg);
+ }
+
+ // Apply the managed properties to the server ManagedDeployment/ManagedComponent
+ ManagedDeployment compMD = getDeployment(md.getName());
+ log.debug("updateComponent, deploymentName="+name+": "+compMD);
+
+ ManagedComponent serverComp = null;
+ // Find the managed component again
+ if(comp.getDeployment().getParent() == null)
+ {
+ serverComp = compMD.getComponent(comp.getName());
+ }
+ else
+ {
+ // Look at the children
+ // TODO - support more levels of nested deployments ?
+ if(compMD.getChildren() != null && compMD.getChildren().isEmpty() == false)
+ {
+ for(ManagedDeployment child : compMD.getChildren())
+ {
+ if(serverComp != null)
+ break;
+
+ serverComp = child.getComponent(comp.getName());
+ }
+ }
+ }
+ if(serverComp == null)
+ {
+ log.debug("Name: "+comp.getName()+" does not map to existing ManagedComponet in ManagedDeployment: "+md.getName()
+ + ", components: "+compMD.getComponents());
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidComponentName")); //$NON-NLS-1$
+ Object[] args = {comp.getName(), md.getName()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+
+ //
+ log.debug("remove component: " + comp + ", deployment: "+ profileDeployment);
+ // Remove
+ Profile profile = getProfileForDeployment(md.getName());
+ this.store.removeComponent(profileDeployment, serverComp);
+ this.profileViews.put(profile.getKey(), createProfileView(profile));
+ }
+
+ public void updateComponent(ManagedComponent comp)
+ throws Exception
+ {
+ if(comp == null)
+ throw new IllegalArgumentException("Null managed component.");
+ // Find the comp deployment
+ ManagedDeployment md = comp.getDeployment();
+
+ // Get the parent
+ while( md.getParent() != null )
+ md = md.getParent();
+
+ String name = md.getName();
+ ProfileDeployment compDeployment = getProfileDeployment(name);
+ if( compDeployment == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.NoSuchDeploymentException")); //$NON-NLS-1$
+ Object[] args = {name};
+ String msg = formatter.format(args);
+ throw new NoSuchDeploymentException(msg);
+ }
+
+ // Apply the managed properties to the server ManagedDeployment/ManagedComponent
+ ManagedDeployment compMD = getDeployment(md.getName());
+ log.debug("updateComponent, deploymentName="+name+": "+compMD);
+
+ ManagedComponent serverComp = null;
+ // Find the managed component again
+ if(comp.getDeployment().getParent() == null)
+ {
+ serverComp = compMD.getComponent(comp.getName());
+ }
+ else
+ {
+ // Look at the children
+ // TODO - support more levels of nested deployments ?
+ if(compMD.getChildren() != null && compMD.getChildren().isEmpty() == false)
+ {
+ for(ManagedDeployment child : compMD.getChildren())
+ {
+ if(serverComp != null)
+ break;
+
+ serverComp = child.getComponent(comp.getName());
+ }
+ }
+ }
+ if(serverComp == null)
+ {
+ log.debug("Name: "+comp.getName()+" does not map to existing ManagedComponet in ManagedDeployment: " + md.getName()
+ + ", components: "+compMD.getComponents());
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidComponentName")); //$NON-NLS-1$
+ Object[] args = {comp.getName(), md.getName()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+
+ // Dispatch any runtime component property values
+ for(ManagedProperty prop : comp.getProperties().values())
+ {
+ // Skip null values && non-CONFIGURATION values, unmodified values, and removed values
+ boolean skip = prop.getValue() == null
+ || prop.isReadOnly()
+ || prop.hasViewUse(ViewUse.CONFIGURATION) == false
+ // || prop.isModified() == false
+ || prop.isRemoved() == true;
+ if( skip )
+ {
+ if(log.isTraceEnabled())
+ log.trace("Skipping component property: "+prop);
+ continue;
+ }
+
+ ManagedProperty ctxProp = serverComp.getProperties().get(prop.getName());
+ // Check for a mapped name
+ if( ctxProp == null )
+ {
+ String mappedName = prop.getMappedName();
+ if( mappedName != null )
+ ctxProp = serverComp.getProperties().get(mappedName);
+ }
+ if( ctxProp == null )
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidTemplateProperty")); //$NON-NLS-1$
+ Object[] args = {prop.getName()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+ // The property value must be a MetaValue
+ Object value = prop.getValue();
+ if ((value instanceof MetaValue) == false)
+ {
+ formatter.applyPattern(i18n.getString("ManagementView.InvalidPropertyValue")); //$NON-NLS-1$
+ Object[] args = {prop.getName(), value.getClass()};
+ String msg = formatter.format(args);
+ throw new IllegalArgumentException(msg);
+ }
+ // Update the serverComp
+ MetaValue metaValue = (MetaValue)value;
+ ctxProp.setField(Fields.META_TYPE, metaValue.getMetaType());
+ ctxProp.setValue(metaValue);
+
+ // Dispatch any runtime component property values
+ Object componentName = getComponentName(ctxProp);
+ ActivationPolicy policy = ctxProp.getActivationPolicy();
+
+ if (componentName != null && policy.equals(ActivationPolicy.IMMEDIATE))
+ {
+ AbstractRuntimeComponentDispatcher.setActiveProperty(ctxProp);
+ dispatcher.set(componentName, ctxProp.getName(), metaValue);
+ }
+ }
+
+ // Persist the changed values
+ Profile profile = getProfileForDeployment(md.getName());
+ this.store.updateDeployment(compDeployment, serverComp);
+ this.profileViews.put(profile.getKey(), createProfileView(profile));
+ }
+
+ protected boolean loadProfiles(boolean forceReload)
+ {
+ boolean wasReloaded = false;
+ Collection<ProfileKey> activeProfiles = ps.getActiveProfileKeys();
+ for(ProfileKey key : activeProfiles)
+ {
+ if(loadProfile(key, forceReload))
+ wasReloaded = true;
+ }
+ return wasReloaded;
+ }
+
+ protected boolean loadProfile(ProfileKey key, boolean forceReload)
+ {
+ boolean wasModified = false;
+ try
+ {
+ // The active profile
+ Profile profile = ps.getActiveProfile(key);
+ AbstractProfileView view = this.profileViews.get(profile.getKey());
+
+ // Check if we need to reload the profile
+ wasModified = forceReload
+ || view == null
+ || view.hasBeenModified(profile);
+
+ if(wasModified)
+ {
+ this.profileViews.put(key, createProfileView(profile));
+ wasModified = true;
+ }
+ }
+ catch(NoSuchProfileException e)
+ {
+ wasModified = profileViews.remove(key) != null;
+ log.debug("Failed to load profile " + key);
+ }
+ return wasModified;
+ }
+
+ protected AbstractProfileView createProfileView(ProfileKey key) throws NoSuchProfileException
+ {
+ Profile profile = this.ps.getActiveProfile(key);
+ return createProfileView(profile);
+ }
+
+ protected AbstractProfileView createProfileView(Profile profile)
+ {
+ return new ProfileView(profile, proxyFactory, mainDeployer);
+ }
+
+ protected Object getComponentName(ManagedProperty property)
+ {
+ // first check target
+ ManagedObject targetObject = property.getTargetManagedObject();
+ if (targetObject != null)
+ return targetObject.getComponentName();
+
+ // check owner
+ targetObject = property.getManagedObject();
+ return targetObject != null ? targetObject.getComponentName() : null;
+ }
+
+ private ProfileKey getProfileKeyForDeployemnt(String name) throws NoSuchDeploymentException
+ {
+ ManagedDeployment md = getDeployment(name);
+ return md.getAttachment(ProfileKey.class);
+ }
+
+ private Profile getProfileForDeployment(String name) throws Exception
+ {
+ ProfileKey key = getProfileKeyForDeployemnt(name);
+ if(key == null)
+ throw new NoSuchDeploymentException("No associated profile found for deployment:" + name);
+
+ return this.ps.getActiveProfile(key);
+ }
+
+ private ProfileDeployment getProfileDeployment(String name) throws Exception
+ {
+ Profile profile = getProfileForDeployment(name);
+ return profile.getDeployment(name);
+ }
+
+}
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractManagedDeploymentView.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractManagedDeploymentView.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractManagedDeploymentView.java 2009-05-06 16:01:15 UTC (rev 88274)
@@ -0,0 +1,521 @@
+/*
+ * 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.profileservice.management.views;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.DeploymentState;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.MutableManagedObject;
+import org.jboss.managed.api.RunState;
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementObjectRef;
+import org.jboss.managed.plugins.ManagedComponentImpl;
+import org.jboss.managed.plugins.ManagedDeploymentImpl;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
+
+/**
+ * A abstract managed deployment view.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author adrian at jboss.org
+ * @author ales.justin at jboss.org
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ *
+ * @version $Revision$
+ */
+public abstract class AbstractManagedDeploymentView
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractManagedDeploymentView.class);
+
+ /** An index of ManagedComponent by ComponentType */
+ private Map<ComponentType, Set<ManagedComponent>> compByCompType = new HashMap<ComponentType, Set<ManagedComponent>>();
+
+ /** id/type key to ManagedObject map */
+ private Map<String, ManagedObject> moRegistry = new HashMap<String, ManagedObject>();
+
+ /** The ManagedPropertys with unresolved ManagementObjectRefs */
+ private Map<String, Set<ManagedProperty>> unresolvedRefs = new HashMap<String, Set<ManagedProperty>>();
+
+ /** A map of runtime ManagedObjects needing to be merged with their matching ManagedObject. */
+ private Map<String, ManagedObject> runtimeMOs = new HashMap<String, ManagedObject>();
+
+ /** The deployment name to ManagedDeployment map */
+ private Map<String, ManagedDeployment> managedDeployments = new TreeMap<String, ManagedDeployment>();
+
+ /** The root deployments to resolve the deployment name. */
+ private List<String> rootDeployments = new ArrayList<String>();
+
+ /**
+ * Process managed deployment.
+ *
+ * @param md the managed deployment
+ * @param profile the associated profile key
+ * @param state the deployment state
+ * @param level depth level
+ * @param trace is trace enabled
+ * @throws Exception for any error
+ */
+ protected void processManagedDeployment(ManagedDeployment md, DeploymentState state, int level, boolean trace) throws Exception
+ {
+ String name = md.getName();
+ if (trace)
+ log.trace(name + " ManagedDeployment_" + level + ": " + md);
+ Map<String, ManagedObject> mos = md.getManagedObjects();
+ if (trace)
+ log.trace(name + " ManagedObjects_ " + level + ": " + mos);
+
+ // Set the deployment state
+ if(state != null && md instanceof ManagedDeploymentImpl)
+ ((ManagedDeploymentImpl)md).setDeploymentState(state);
+
+ for(ManagedObject mo : mos.values())
+ {
+ processManagedObject(mo, md);
+ }
+ managedDeployments.put(name, md);
+
+ // Add root deployments
+ if(level == 0)
+ this.rootDeployments.add(name);
+
+ // Process children
+ List<ManagedDeployment> mdChildren = md.getChildren();
+ if(mdChildren != null && mdChildren.isEmpty() == false)
+ {
+ for(ManagedDeployment mdChild : mdChildren)
+ {
+ // process the child deployments, with the state of the parent.
+ processManagedDeployment(mdChild, state, level + 1, trace);
+ }
+ }
+ }
+
+ /**
+ * Get the deployment names for a given type.
+ *
+ * @param type the deployment type
+ * @return the matching deployments
+ */
+ public Set<String> getDeploymentNamesForType(String type)
+ {
+ boolean trace = log.isTraceEnabled();
+ HashSet<String> matches = new HashSet<String>();
+ for(ManagedDeployment md : managedDeployments.values())
+ {
+ String name = md.getName();
+ Set<String> types = md.getTypes();
+ if(types != null)
+ {
+ if(types.contains(type))
+ {
+ if(trace)
+ log.trace(name+" matches type: "+type+", types:"+types);
+ matches.add(name);
+ }
+ }
+ }
+ return matches;
+ }
+
+ /**
+ * Get the deployments for a given type.
+ *
+ * @param type the deployment type.
+ * @return the matching deployments
+ */
+ public Set<ManagedDeployment> getDeploymentsForType(String type)
+ {
+ Set<String> names = getDeploymentNamesForType(type);
+ HashSet<ManagedDeployment> mds = new HashSet<ManagedDeployment>();
+ for(String name : names)
+ {
+ ManagedDeployment md = this.managedDeployments.get(name);
+ mds.add(md);
+ }
+ return mds;
+ }
+
+ /**
+ * Get component for a given type.
+ *
+ * @param type the component type
+ * @return a set of matching components
+ */
+ public Set<ManagedComponent> getComponentsForType(ComponentType type)
+ {
+ Set<ManagedComponent> comps = compByCompType.get(type);
+ if(comps == null)
+ comps = Collections.emptySet();
+ return comps;
+ }
+
+ /**
+ * Get the deployment names.
+ *
+ * @return the deployment names
+ */
+ public Set<String> getDeploymentNames()
+ {
+ return this.managedDeployments.keySet();
+ }
+
+ /**
+ * Find a deployment.
+ *
+ * @param name
+ * @return
+ * @throws NoSuchDeploymentException
+ */
+ public Collection<ManagedDeployment> getDeployment(String name) throws NoSuchDeploymentException
+ {
+ if(name == null)
+ throw new IllegalArgumentException("Null deployment name");
+
+ List<ManagedDeployment> deployments = new ArrayList<ManagedDeployment>();
+ // Check the file name
+
+ if(this.managedDeployments.containsKey(name))
+ {
+ ManagedDeployment md = this.managedDeployments.get(name);
+ if(md != null)
+ deployments.add(md);
+ }
+ else
+ {
+ // Look for a simple name
+ for(String deployment : this.rootDeployments)
+ {
+ String fixedDeploymentName = deployment;
+ if(deployment.endsWith("/"))
+ fixedDeploymentName = deployment.substring(0, deployment.length() - 1);
+
+ if(fixedDeploymentName.endsWith(name))
+ {
+ ManagedDeployment md = this.managedDeployments.get(deployment);
+ if(md != null)
+ deployments.add(md);
+ }
+ }
+ }
+ return deployments;
+ }
+
+ protected abstract void mergeRuntimeMO(ManagedObject mo, ManagedObject runtimeMO) throws Exception;
+
+ protected abstract Set<ManagedOperation> createOperationProxies(ManagedObject mo, Set<ManagedOperation> runtimeOps) throws Exception;
+
+ protected abstract RunState updateRunState(ManagedObject mo, ManagedComponent comp) throws Exception;
+
+ /**
+ * Process managed object.
+ *
+ * @param mo the managed object
+ * @param md the managed deployment
+ */
+ protected void processManagedObject(ManagedObject mo, ManagedDeployment md)
+ throws Exception
+ {
+ String key = mo.getName() + "/" + mo.getNameType();
+ if(mo.getName().equals("org.jboss.security.plugins.SecurityConfig"))
+ log.info("Saw SecurityConfig MO");
+ log.debug("ID for ManagedObject: "+key+", attachmentName: "+mo.getAttachmentName());
+
+ // See if this is a runtime ManagedObject
+ Map<String, Annotation> moAnns = mo.getAnnotations();
+ ManagementObject managementObject = (ManagementObject) moAnns.get(ManagementObject.class.getName());
+ if (managementObject.isRuntime())
+ {
+ boolean merged = false;
+ ManagementComponent mc = managementObject.componentType();
+ boolean isMC = !(mc.type().length() == 0 && mc.subtype().length() == 0);
+
+ // Merge this with the ManagedObject
+ ManagedObject parentMO = moRegistry.get(key);
+ if (parentMO == null && isMC == false)
+ {
+ log.debug("Deferring resolution of runtime ManagedObject: "+managementObject);
+ // Save the runtime mo for merging
+ runtimeMOs.put(key, mo);
+ }
+ else
+ {
+ mergeRuntimeMO(parentMO, mo);
+ merged = true;
+ runtimeMOs.remove(key);
+ }
+ // Update the runtime state of any ManagedComponent associated with this runtime mo
+ ManagedComponent comp = md.getComponent(mo.getName());
+ if (comp != null)
+ {
+ RunState state = updateRunState(mo, comp);
+ log.debug("Updated component: "+comp+" run state to: "+state);
+ }
+ // There is no further processing of runtime ManagedObjects, unless its marked as a component
+ if (isMC == false)
+ return;
+ //
+ else if (merged == false)
+ {
+ Set<ManagedOperation> runtimeOps = mo.getOperations();
+ runtimeOps = createOperationProxies(mo, runtimeOps);
+ MutableManagedObject moi = (MutableManagedObject) mo;
+ moi.setOperations(runtimeOps);
+ }
+ }
+ else
+ {
+ // See if there is runtime info to merge
+ ManagedObject runtimeMO = runtimeMOs.get(key);
+ if (runtimeMO != null)
+ {
+ mergeRuntimeMO(mo, runtimeMO);
+ runtimeMOs.remove(key);
+ // Update the runtime state of any ManagedComponent associated with this runtime mo
+ ManagedComponent comp = md.getComponent(mo.getName());
+ if (comp != null)
+ {
+ RunState state = updateRunState(runtimeMO, comp);
+ log.debug("Updated component: "+comp+" run state to: "+state);
+ }
+ }
+ }
+
+ // Update the MO registry
+ // TODO - does this make sense? In case of a MetaType.isCollection we could get different results then
+// ManagedObject prevMO = moRegistry.put(key, mo);
+// if( prevMO != null )
+// {
+// // This should only matter for ManagedObjects that have a ManagementObjectID
+// log.debug("Duplicate mo for key: "+key+", prevMO: "+prevMO);
+// return;
+// }
+ // Check for unresolved refs
+ checkForReferences(key, mo);
+
+ // Map any existing ManagedComponent types
+ for(ManagedComponent comp : md.getComponents().values())
+ {
+ log.debug("Updating ManagementComponent: "+comp);
+ ComponentType type = comp.getType();
+ Set<ManagedComponent> typeComps = compByCompType.get(type);
+ if (typeComps == null)
+ {
+ typeComps = new HashSet<ManagedComponent>();
+ compByCompType.put(type, typeComps);
+ }
+ typeComps.add(comp);
+ }
+
+ // Create ManagedComponents for ManagedObjects annotated with ManagementComponent
+ ManagementComponent mc = (ManagementComponent) moAnns.get(ManagementComponent.class.getName());
+ if (mc != null && md.getComponent(mo.getName()) == null)
+ {
+ ComponentType type = new ComponentType(mc.type(), mc.subtype());
+ ManagedComponentImpl comp = new ManagedComponentImpl(type, md, mo);
+ md.addComponent(mo.getName(), comp);
+ log.debug("Processing ManagementComponent("+mo.getName()+"): "+comp);
+ Set<ManagedComponent> typeComps = compByCompType.get(type);
+ if (typeComps == null)
+ {
+ typeComps = new HashSet<ManagedComponent>();
+ compByCompType.put(type, typeComps);
+ }
+ typeComps.add(comp);
+ updateRunState(null, comp);
+ }
+
+ // Scan for @ManagementObjectRef
+ for(ManagedProperty prop : mo.getProperties().values())
+ {
+ log.debug("Checking property: "+prop);
+ // See if this is a ManagementObjectID
+ Map<String, Annotation> pannotations = prop.getAnnotations();
+ if (pannotations != null && pannotations.isEmpty() == false)
+ {
+ ManagementObjectID id = (ManagementObjectID) pannotations.get(ManagementObjectID.class.getName());
+ if (id != null)
+ {
+ Object refName = getRefName(prop.getValue());
+ if (refName == null)
+ refName = id.name();
+ String propKey = refName + "/" + id.type();
+ log.debug("ManagedProperty level ID for ManagedObject: "+propKey+", attachmentName: "+mo.getAttachmentName());
+ moRegistry.put(propKey, mo);
+ checkForReferences(propKey, mo);
+ }
+ // See if this is a ManagementObjectRef
+ ManagementObjectRef ref = (ManagementObjectRef) pannotations.get(ManagementObjectRef.class.getName());
+ if ( ref != null )
+ {
+ // The reference key is the prop value + ref.type()
+ log.debug("Property("+prop.getName()+") references: "+ref);
+ Object refName = getRefName(prop.getValue());
+ if (refName == null)
+ refName = ref.name();
+ String targetKey = refName + "/" + ref.type();
+ ManagedObject target = moRegistry.get(targetKey);
+ if (target != null)
+ {
+ log.debug("Resolved property("+prop.getName()+") reference to: "+targetKey);
+ prop.setTargetManagedObject(target);
+ }
+ else
+ {
+ Set<ManagedProperty> referers = unresolvedRefs.get(targetKey);
+ if (referers == null)
+ {
+ referers = new HashSet<ManagedProperty>();
+ unresolvedRefs.put(targetKey, referers);
+ }
+ referers.add(prop);
+ }
+ }
+ }
+
+ MetaType propType = prop.getMetaType();
+ if (propType == AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE)
+ {
+ processGenericValue ((GenericValue)prop.getValue(), md);
+ }
+ else if (propType.isArray())
+ {
+ ArrayMetaType amt = (ArrayMetaType) propType;
+ MetaType etype = amt.getElementType();
+ if (etype == AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE)
+ {
+ ArrayValue avalue = (ArrayValue) prop.getValue();
+ int length = avalue != null ? avalue.getLength() : 0;
+ for(int n = 0; n < length; n ++)
+ processGenericValue((GenericValue) avalue.getValue(n), md);
+ }
+ }
+ else if (propType.isCollection())
+ {
+ CollectionMetaType amt = (CollectionMetaType) propType;
+ MetaType etype = amt.getElementType();
+ if (etype == AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE)
+ {
+ CollectionValue avalue = (CollectionValue) prop.getValue();
+ if(avalue != null)
+ {
+ MetaValue[] elements = avalue.getElements();
+ for(int n = 0; n < avalue.getSize(); n ++)
+ {
+ GenericValue gv = (GenericValue) elements[n];
+ ManagedObject propMO = (ManagedObject) gv.getValue();
+ if(propMO != null)
+ processManagedObject(propMO, md);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Get ref name.
+ *
+ * @param value property value
+ * @return plain value
+ */
+ protected Object getRefName(Object value)
+ {
+ if (value instanceof MetaValue)
+ {
+ MetaValue metaValue = (MetaValue)value;
+ if (metaValue.getMetaType().isSimple() == false)
+ throw new IllegalArgumentException("Can only get ref from simple value: " + value);
+ SimpleValue svalue = (SimpleValue) metaValue;
+ return svalue.getValue();
+ }
+ return value;
+ }
+
+ /**
+ * Check for references.
+ *
+ * @param key the property key
+ * @param mo the managed object
+ */
+ protected void checkForReferences(String key, ManagedObject mo)
+ {
+ Set<ManagedProperty> referers = unresolvedRefs.get(key);
+ log.debug("checkForReferences, "+key+" has referers: "+referers);
+ if (referers != null)
+ {
+ for(ManagedProperty prop : referers)
+ {
+ prop.setTargetManagedObject(mo);
+ }
+ unresolvedRefs.remove(key);
+ }
+ }
+
+ /**
+ * Process generic value.
+ *
+ * @param genericValue the generic value
+ * @param md the managed deployment
+ * @throws Exception for any error
+ */
+ protected void processGenericValue(GenericValue genericValue, ManagedDeployment md) throws Exception
+ {
+ // TODO: a null is probably an error condition
+ if (genericValue != null)
+ {
+ ManagedObject propMO = (ManagedObject) genericValue.getValue();
+ // TODO: a null is probably an error condition
+ if (propMO != null)
+ processManagedObject(propMO, md);
+ }
+ }
+
+}
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractProfileView.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractProfileView.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/AbstractProfileView.java 2009-05-06 16:01:15 UTC (rev 88274)
@@ -0,0 +1,285 @@
+/*
+ * 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.profileservice.management.views;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.management.RuntimeComponentDispatcher;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.DeploymentState;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.MutableManagedComponent;
+import org.jboss.managed.api.MutableManagedObject;
+import org.jboss.managed.api.RunState;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.profileservice.management.AbstractRuntimeComponentDispatcher;
+import org.jboss.profileservice.management.ContextStateMapper;
+import org.jboss.profileservice.management.ManagedOperationProxyFactory;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileKey;
+
+/**
+ * A abstract profile view.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author adrian at jboss.org
+ * @author ales.justin at jboss.org
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ *
+ * @version $Revision$
+ */
+public abstract class AbstractProfileView extends AbstractManagedDeploymentView
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractProfileView.class);
+
+ /** The state mappings. */
+ private static final ContextStateMapper<RunState> runStateMapper;
+ private static final ContextStateMapper<DeploymentState> deploymentStateMapper;
+
+ /** The runtime component dispatcher. */
+ private RuntimeComponentDispatcher dispatcher;
+
+ /** The proxy factory. */
+ private ManagedOperationProxyFactory proxyFactory;
+
+ static
+ {
+ // Set default run state mappings for mc beans/mbeans
+ Map<String, RunState> runStateMappings = new HashMap<String, RunState>();
+ runStateMappings.put("**ERROR**", RunState.FAILED);
+ runStateMappings.put("Not Installed", RunState.STOPPED);
+ runStateMappings.put("PreInstall", RunState.STOPPED);
+ runStateMappings.put("Described", RunState.STOPPED);
+ runStateMappings.put("Instantiated", RunState.STOPPED);
+ runStateMappings.put("Configured", RunState.STOPPED);
+ runStateMappings.put("Create", RunState.STOPPED);
+ runStateMappings.put("Start", RunState.STOPPED);
+ runStateMappings.put("Installed", RunState.RUNNING);
+
+ runStateMapper = new ContextStateMapper<RunState>(runStateMappings,
+ RunState.STARTING, RunState.STOPPED, RunState.FAILED, RunState.UNKNOWN);
+
+ Map<String, DeploymentState> deploymentMappings = new HashMap<String, DeploymentState>();
+ deploymentMappings.put("**ERROR**", DeploymentState.FAILED);
+ deploymentMappings.put("Not Installed", DeploymentState.STOPPED);
+ deploymentMappings.put("Installed", DeploymentState.STARTED);
+
+ deploymentStateMapper = new ContextStateMapper<DeploymentState>(deploymentMappings,
+ DeploymentState.STARTING, DeploymentState.STOPPING, DeploymentState.FAILED, DeploymentState.UNKNOWN);
+ }
+
+ public AbstractProfileView(ManagedOperationProxyFactory proxyFactory)
+ {
+ if(proxyFactory == null)
+ throw new IllegalArgumentException("null proxy factory");
+ if(proxyFactory.getDispatcher() == null)
+ throw new IllegalArgumentException("null runtime component dispatcher");
+
+ this.proxyFactory = proxyFactory;
+ this.dispatcher = proxyFactory.getDispatcher();
+ }
+
+ public abstract boolean hasBeenModified(Profile profile);
+
+ public abstract ProfileKey getProfileKey();
+
+ protected void processRootManagedDeployment(ManagedDeployment md, boolean trace) throws Exception
+ {
+ DeploymentState state = getDeploymentState(md);
+ processManagedDeployment(md, state, 0, trace);
+ }
+
+ @Override
+ protected void mergeRuntimeMO(ManagedObject mo, ManagedObject runtimeMO)
+ throws Exception
+ {
+ Map<String, ManagedProperty> runtimeProps = runtimeMO.getProperties();
+ Set<ManagedOperation> runtimeOps = runtimeMO.getOperations();
+ // Get the runtime MO component name
+ Object componentName = runtimeMO.getComponentName();
+ log.debug("Merging runtime: "+runtimeMO.getName()+", compnent name: "+componentName);
+ Map<String, ManagedProperty> moProps = null;
+ Set<ManagedOperation> moOps = null;
+ HashMap<String, ManagedProperty> props = null;
+ HashSet<ManagedOperation> ops = null;
+ // If mo is null, the merge target is the runtimeMO
+ if (mo == null)
+ {
+ // Just proxy the runtime props/ops
+ mo = runtimeMO;
+ moProps = mo.getProperties();
+ moOps = mo.getOperations();
+ // These will be updated with the proxied values, don't duplicate props/ops
+ props = new HashMap<String, ManagedProperty>();
+ ops = new HashSet<ManagedOperation>();
+ }
+ else
+ {
+ // Merge the runtime props/ops
+ moProps = mo.getProperties();
+ moOps = mo.getOperations();
+ props = new HashMap<String, ManagedProperty>(moProps);
+ ops = new HashSet<ManagedOperation>(moOps);
+ }
+
+ if (runtimeProps != null && runtimeProps.size() > 0)
+ {
+ log.debug("Properties before:"+props);
+ // We need to pull the runtime values for stats
+ for(ManagedProperty prop : runtimeProps.values())
+ {
+ if(prop.hasViewUse(ViewUse.STATISTIC))
+ {
+ String propName = prop.getMappedName();
+ try
+ {
+ AbstractRuntimeComponentDispatcher.setActiveProperty(prop);
+ MetaValue propValue = dispatcher.get(componentName, propName);
+ if(propValue != null)
+ prop.setValue(propValue);
+ }
+ catch(Throwable t)
+ {
+ log.debug("Failed to get stat value, "+componentName+":"+propName);
+ }
+ ManagedProperty proxiedProp = createPropertyProxy(prop);
+ props.put(prop.getName(), proxiedProp);
+ }
+ else
+ {
+ props.put(prop.getName(), prop);
+ }
+ // Keep the property associated with the runtime MO for invocations/updates
+ if (prop.getTargetManagedObject() == null)
+ prop.setTargetManagedObject(runtimeMO);
+ }
+
+ log.debug("Properties after:"+props);
+ }
+ if (runtimeOps != null && runtimeOps.size() > 0)
+ {
+ log.debug("Ops before:"+ops);
+ runtimeOps = createOperationProxies(runtimeMO, runtimeOps);
+ ops.addAll(runtimeOps);
+ log.debug("Ops after:"+ops);
+ }
+
+ MutableManagedObject moi = (MutableManagedObject) mo;
+ moi.setProperties(props);
+ moi.setOperations(ops);
+ }
+
+ @Override
+ protected Set<ManagedOperation> createOperationProxies(ManagedObject mo, Set<ManagedOperation> ops)
+ throws Exception
+ {
+ if (proxyFactory == null)
+ throw new IllegalArgumentException("Missing RuntimeComponentDispatcher.");
+
+ Object componentName = mo.getComponentName();
+ return createOperationProxies(ops, componentName);
+ }
+
+ protected Set<ManagedOperation> createOperationProxies(Set<ManagedOperation> ops, Object componentName)
+ throws Exception
+ {
+ // Create the delegate operation
+ return proxyFactory.createOperationProxies(ops, componentName);
+ }
+
+ private ManagedProperty createPropertyProxy(ManagedProperty prop)
+ throws Exception
+ {
+ if (proxyFactory == null)
+ throw new IllegalArgumentException("Missing RuntimeComponentDispatcher.");
+
+ // Create the delegate property
+ Object componentName = prop.getManagedObject().getComponentName();
+ return proxyFactory.createPropertyProxy(prop, componentName);
+ }
+
+ protected RunState updateRunState(ManagedObject runtimeMO, ManagedComponent comp)
+ {
+ RunState state = comp.getRunState();
+ if (state == RunState.UNKNOWN && dispatcher != null)
+ {
+ Object name = comp.getComponentName();
+ if (name == null && runtimeMO != null)
+ name = runtimeMO.getComponentName();
+ if (name != null)
+ {
+ state = getMappedState(name, runStateMapper);
+ if (comp instanceof MutableManagedComponent)
+ {
+ MutableManagedComponent mcomp = MutableManagedComponent.class.cast(comp);
+ mcomp.setRunState(state);
+ }
+ }
+ }
+ return state;
+ }
+
+ protected DeploymentState getDeploymentState(ManagedDeployment md)
+ {
+ DeploymentState state = md.getDeploymentState();
+ if(state == DeploymentState.UNKNOWN && dispatcher != null)
+ {
+ Object name = md.getName();
+ if(name != null)
+ {
+ state = getMappedState(name, deploymentStateMapper);
+ }
+ }
+ return state;
+ }
+
+ protected <T extends Enum<?>> T getMappedState(Object name, ContextStateMapper<T> mapper)
+ {
+ T state = null;
+ if(dispatcher != null)
+ {
+ try
+ {
+ //TODO, update RuntimeComponentDispatcher
+ AbstractRuntimeComponentDispatcher xdispatcher = (AbstractRuntimeComponentDispatcher) dispatcher;
+ state = xdispatcher.mapControllerState(name, mapper);
+ }
+ catch(Exception e)
+ {
+ state = mapper.getErrorState();
+ }
+ }
+ return state;
+ }
+
+}
+
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/BootstrapProfileView.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/BootstrapProfileView.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/BootstrapProfileView.java 2009-05-06 16:01:15 UTC (rev 88274)
@@ -0,0 +1,86 @@
+/*
+ * 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.profileservice.management.views;
+
+import java.util.Collection;
+
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.DeploymentState;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.management.ManagedOperationProxyFactory;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileKey;
+
+/**
+ * The bootstrap deployment view.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class BootstrapProfileView extends AbstractProfileView
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(BootstrapProfileView.class);
+
+ /** A fake profile key. */
+ private static final ProfileKey key = new ProfileKey(BootstrapProfileView.class.getName());
+
+ public BootstrapProfileView(ManagedOperationProxyFactory proxyFactory, Collection<ManagedDeployment> deployments)
+ {
+ super(proxyFactory);
+ // Load the bootstrap deployments
+ load(deployments);
+ }
+
+ @Override
+ public ProfileKey getProfileKey()
+ {
+ return key;
+ }
+
+ @Override
+ public boolean hasBeenModified(Profile profile)
+ {
+ return false;
+ }
+
+ protected void load(Collection<ManagedDeployment> deployments)
+ {
+ if(deployments == null)
+ throw new IllegalArgumentException("null deployments.");
+
+ for(ManagedDeployment deployment : deployments)
+ {
+ try
+ {
+ processManagedDeployment(deployment, DeploymentState.STARTED, 0, false);
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to process managed deployment " + deployment);
+ }
+ }
+ }
+
+}
+
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/MBeanProfileView.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/MBeanProfileView.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/MBeanProfileView.java 2009-05-06 16:01:15 UTC (rev 88274)
@@ -0,0 +1,173 @@
+/*
+ * 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.profileservice.management.views;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+import javax.management.MBeanInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.annotation.factory.AnnotationCreator;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.DeploymentState;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.plugins.ManagedDeploymentImpl;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.profileservic.spi.ManagedMBeanDeploymentFactory;
+import org.jboss.profileservic.spi.ManagedMBeanDeploymentFactory.MBeanComponent;
+import org.jboss.profileservic.spi.ManagedMBeanDeploymentFactory.MBeanDeployment;
+import org.jboss.profileservice.management.MBeanManagedObjectFactory;
+import org.jboss.profileservice.management.ManagedOperationProxyFactory;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileKey;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class MBeanProfileView extends AbstractProfileView
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(MBeanProfileView.class);
+
+ /** A fake profile key. */
+ private static final ProfileKey key = new ProfileKey(MBeanProfileView.class.getName());
+
+ /** */
+ private HashMap<String, ManagedMBeanDeploymentFactory> mdfs =
+ new HashMap<String, ManagedMBeanDeploymentFactory>();
+ private MBeanServer mbeanServer;
+ private MBeanManagedObjectFactory mbeanMOFactory = new MBeanManagedObjectFactory();
+
+ public MBeanProfileView(ManagedOperationProxyFactory proxyFactory)
+ {
+ super(proxyFactory);
+ }
+
+ public MBeanServer getMbeanServer()
+ {
+ return mbeanServer;
+ }
+
+ public void setMbeanServer(MBeanServer mbeanServer)
+ {
+ this.mbeanServer = mbeanServer;
+ }
+
+ public void addManagedMBeanDeployments(ManagedMBeanDeploymentFactory factory)
+ {
+ log.info("addManagedDeployment, "+factory);
+ String name = factory.getFactoryName();
+ this.mdfs.put(name, factory);
+ }
+ public void removeManagedMBeanDeployments(ManagedMBeanDeploymentFactory factory)
+ {
+ log.info("removeManagedDeployment, "+factory);
+ String name = factory.getFactoryName();
+ this.mdfs.remove(name);
+ }
+
+ @Override
+ public ProfileKey getProfileKey()
+ {
+ return key;
+ }
+
+ protected void load()
+ {
+ boolean trace = log.isTraceEnabled();
+ // Process mbean components that need to be exposed as ManagedDeployment/ManagedComponent
+ for(ManagedMBeanDeploymentFactory mdf : mdfs.values())
+ {
+ log.debug("Processing deployments for factory: "+mdf.getFactoryName());
+ Collection<MBeanDeployment> deployments = mdf.getDeployments(mbeanServer);
+ for(MBeanDeployment md : deployments)
+ {
+ log.debug("Saw MBeanDeployment: "+md);
+ HashMap<String, ManagedObject> unitMOs = new HashMap<String, ManagedObject>();
+ Collection<MBeanComponent> components = md.getComponents();
+ if(components != null)
+ {
+ for(MBeanComponent comp : components)
+ {
+ log.debug("Saw MBeanComponent: "+comp);
+ try
+ {
+ ManagedObject mo = createManagedObject(comp.getName());
+ // Add a ManagementComponent annotation
+ String annotationExpr = "@org.jboss.managed.api.annotation.ManagementObject("
+ + "name=\""+comp.getName()+"\","
+ + "componentType=@org.jboss.managed.api.annotation.ManagementComponent(type=\""
+ + comp.getType()+"\",subtype=\""+comp.getSubtype()+"\")"
+ + ")";
+ // System.err.println(annotationExpr);
+ ManagementObject moAnn = (ManagementObject) AnnotationCreator.createAnnotation(
+ annotationExpr, ManagementObject.class);
+ // Bot the ManagementObject and ManagementComponent annotation need to be in the MO annotations
+ mo.getAnnotations().put(ManagementObject.class.getName(), moAnn);
+ ManagementComponent mcAnn = moAnn.componentType();
+ mo.getAnnotations().put(ManagementComponent.class.getName(), mcAnn);
+ unitMOs.put(comp.getName().getCanonicalName(), mo);
+ }
+ catch(Exception e)
+ {
+ log.warn("Failed to create ManagedObject for: "+comp, e);
+ }
+ }
+ }
+ ManagedDeploymentImpl mdi = new ManagedDeploymentImpl(md.getName(), md.getName(), null, unitMOs);
+ try
+ {
+ processManagedDeployment(mdi, DeploymentState.STARTED, 0, trace);
+ }
+ catch(Exception e)
+ {
+ log.warn("Failed to process ManagedDeployment for: " + md.getName(), e);
+ }
+ }
+ }
+ }
+
+ private ManagedObject createManagedObject(ObjectName mbean)
+ throws Exception
+ {
+ MBeanInfo info = mbeanServer.getMBeanInfo(mbean);
+ ClassLoader mbeanLoader = mbeanServer.getClassLoaderFor(mbean);
+ MetaData metaData = null;
+ ManagedObject mo = mbeanMOFactory.getManagedObject(mbean, info, mbeanLoader, metaData);
+ return mo;
+ }
+
+ @Override
+ public boolean hasBeenModified(Profile profile)
+ {
+ return false;
+ }
+
+}
+
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/PlatformMbeansView.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/PlatformMbeansView.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/PlatformMbeansView.java 2009-05-06 16:01:15 UTC (rev 88274)
@@ -0,0 +1,101 @@
+/*
+ * 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.profileservice.management.views;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.DeploymentState;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.ManagedDeploymentImpl;
+import org.jboss.managed.plugins.jmx.ManagementFactoryUtils;
+import org.jboss.profileservice.management.ManagedOperationProxyFactory;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileKey;
+
+/**
+ * The PlatformMBean management view.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ *
+ * @version $Revision$
+ */
+public class PlatformMbeansView extends AbstractProfileView
+{
+
+ /** The managed object factory. */
+ private static final ManagedObjectFactory managedObjFactory = ManagedObjectFactory.getInstance();
+
+ /** A fake profile key. */
+ private static final ProfileKey key = new ProfileKey(PlatformMbeansView.class.getName());
+
+
+ protected static ManagedDeployment getDeployment()
+ {
+ Map<String, ManagedObject> platformMBeanMOs = ManagementFactoryUtils.getPlatformMBeanMOs(managedObjFactory);
+ ManagedDeploymentImpl platformMBeans = new ManagedDeploymentImpl("JDK PlatformMBeans", "PlatformMBeans", null,
+ platformMBeanMOs);
+ List<ManagedObject> gcMbeans = ManagementFactoryUtils.getGarbageCollectorMXBeans(managedObjFactory);
+ Map<String, ManagedObject> gcMOs = new HashMap<String, ManagedObject>();
+ for (ManagedObject mo : gcMbeans)
+ gcMOs.put(mo.getName(), mo);
+ List<ManagedObject> mmMbeans = ManagementFactoryUtils.getMemoryManagerMXBeans(managedObjFactory);
+ Map<String, ManagedObject> mmMOs = new HashMap<String, ManagedObject>();
+ for (ManagedObject mo : mmMbeans)
+ mmMOs.put(mo.getName(), mo);
+ List<ManagedObject> mpoolMBeans = ManagementFactoryUtils.getMemoryPoolMXBeans(managedObjFactory);
+ Map<String, ManagedObject> mpoolMOs = new HashMap<String, ManagedObject>();
+ for (ManagedObject mo : mpoolMBeans)
+ mpoolMOs.put(mo.getName(), mo);
+ ManagedDeploymentImpl gcMD = new ManagedDeploymentImpl("GarbageCollectorMXBeans", "GarbageCollectorMXBeans",
+ null, gcMOs);
+ platformMBeans.getChildren().add(gcMD);
+ ManagedDeploymentImpl mmMD = new ManagedDeploymentImpl("MemoryManagerMXBeans", "MemoryManagerMXBeans", null, mmMOs);
+ platformMBeans.getChildren().add(mmMD);
+ ManagedDeploymentImpl mpoolMD = new ManagedDeploymentImpl("MemoryPoolMXBeans", "MemoryPoolMXBeans", null, mpoolMOs);
+ platformMBeans.getChildren().add(mpoolMD);
+ return platformMBeans;
+ }
+
+ public PlatformMbeansView(ManagedOperationProxyFactory proxyFactory) throws Exception
+ {
+ super(proxyFactory);
+ processManagedDeployment(getDeployment(), DeploymentState.STARTED, 0, false);
+ }
+
+ @Override
+ public ProfileKey getProfileKey()
+ {
+ return key;
+ }
+
+ @Override
+ public boolean hasBeenModified(Profile profile)
+ {
+ return false;
+ }
+}
+
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/ProfileView.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/ProfileView.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/views/ProfileView.java 2009-05-06 16:01:15 UTC (rev 88274)
@@ -0,0 +1,166 @@
+/*
+ * 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.profileservice.management.views;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.management.KnownDeploymentTypes;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.DeploymentState;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.plugins.ManagedDeploymentImpl;
+import org.jboss.profileservice.management.ManagedOperationProxyFactory;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.system.server.profileservice.repository.AbstractProfileDeployment;
+
+/**
+ * The profile view.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ProfileView extends AbstractProfileView
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(ProfileView.class);
+
+ /** The main deployer. */
+ private final MainDeployer mainDeployer;
+
+ /** The profile key. */
+ private final ProfileKey key;
+
+ /** The last modified. */
+ private final long lastModified;
+
+ public ProfileView(Profile profile, ManagedOperationProxyFactory proxyFactory, MainDeployer mainDeployer)
+ {
+ super(proxyFactory);
+ if(profile == null)
+ throw new IllegalArgumentException("null profile");
+ if(profile.getKey() == null)
+ throw new IllegalArgumentException("null profile key");
+ if(mainDeployer == null)
+ throw new IllegalArgumentException("null main deployer");
+ //
+ this.key = profile.getKey();
+ this.mainDeployer = mainDeployer;
+ this.lastModified = profile.getLastModified();
+ // Load the deployments
+ load(profile.getDeployments());
+ }
+
+ public ProfileKey getProfileKey()
+ {
+ return this.key;
+ }
+
+ protected void load(Collection<ProfileDeployment> deployments)
+ {
+ if(deployments == null)
+ throw new IllegalArgumentException("null deployments.");
+
+ boolean trace = log.isTraceEnabled();
+ for(ProfileDeployment deployment : deployments)
+ {
+ try
+ {
+ try
+ {
+ ManagedDeployment md = mainDeployer.getManagedDeployment(deployment.getName());
+ processRootManagedDeployment(md, trace);
+
+ // Cache the deployment types
+ if(md.getTypes() != null && md.getTypes().isEmpty() == false)
+ ((AbstractProfileDeployment)deployment)
+ .addTransientAttachment(KnownDeploymentTypes.class.getName(), md.getTypes());
+ }
+ catch(DeploymentException e)
+ {
+ // FIXME Assume a undeployed (stopped) deployment
+ ManagedDeployment md = createStoppedManagedDeployment(deployment);
+ processManagedDeployment(md, DeploymentState.STOPPED, 0, trace);
+ }
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create ManagedDeployment for: " + deployment.getName(), e);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected ManagedDeployment createStoppedManagedDeployment(ProfileDeployment deployment)
+ {
+ String deploymentName = deployment.getName();
+ ManagedDeployment md = new ManagedDeploymentImpl(deploymentName,
+ deployment.getRoot().getName());
+
+ // Try to get the cached deployment type
+ Collection<String> deploymentTypes = ((AbstractProfileDeployment)deployment)
+ .getTransientAttachment(KnownDeploymentTypes.class.getName(), Collection.class);
+
+ if(deploymentTypes != null && deploymentTypes.isEmpty() == false)
+ {
+ md.setTypes(new HashSet<String>(deploymentTypes));
+ }
+ else
+ {
+ int i = deploymentName.lastIndexOf(".");
+ if(i != -1 && (i + 1) < deploymentName.length())
+ {
+ String guessedType = deploymentName.substring(i + 1, deploymentName.length());
+ if(guessedType.endsWith("/"))
+ guessedType = guessedType.substring(0, guessedType.length() -1 );
+ md.setTypes(new HashSet<String>(1));
+ md.addType(guessedType);
+ }
+ }
+ return md;
+ }
+
+ @Override
+ protected void processManagedDeployment(ManagedDeployment md, DeploymentState state, int level, boolean trace)
+ throws Exception
+ {
+ super.processManagedDeployment(md, state, level, trace);
+ // Set the profile key
+ md.setAttachment(ProfileKey.class.getName(), getProfileKey());
+ }
+
+ @Override
+ public boolean hasBeenModified(Profile profile)
+ {
+ if(profile == null)
+ throw new IllegalArgumentException("null profile.");
+
+ return this.lastModified < profile.getLastModified();
+ }
+
+}
+
More information about the jboss-cvs-commits
mailing list