[jboss-cvs] JBossAS SVN: r100821 - in projects/profileservice/trunk: core/src/main/java/org/jboss/profileservice/management/event and 10 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 10 13:26:34 EST 2010
Author: emuckenhuber
Date: 2010-02-10 13:26:33 -0500 (Wed, 10 Feb 2010)
New Revision: 100821
Added:
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/actions/
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/actions/ProfileViewUpdateAction.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/messages.properties
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/DefaultContextStateMapper.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ProfileViewProcessorHelper.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/package-info.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileViewWrapper.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/RegisteredProfileView.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewProcessingContext.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java
Removed:
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/PlatformMBeanView.java
Modified:
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/AbstractActionController.java
projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/event/ProfileLifeCycleEvent.java
projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/resolver/test/ActivationCallbackUnitTestCase.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ManagedDeploymentProcessor.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileView.java
projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileView.java
projects/profileservice/trunk/spi/pom.xml
projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java
projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ManagementView.java
projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ActionController.java
projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ModificationEvent.java
projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/types/ControllerStateMetaType.java
Log:
remove mvn-dependency of the spi-module on kernel-dependency and some more work on the mgtView plugin(s)
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/AbstractActionController.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/AbstractActionController.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/AbstractActionController.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -21,8 +21,11 @@
*/
package org.jboss.profileservice.management;
+import java.util.Collections;
+import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.jboss.profileservice.management.event.ProfileLifeCycleEvent;
@@ -44,12 +47,14 @@
{
/** The profiles. */
- private Map<ProfileKey, ProfileWrapper> profiles = new ConcurrentHashMap<ProfileKey, ProfileWrapper>();
+ private List<ProfileKey> profiles = new CopyOnWriteArrayList<ProfileKey>();
+ private Map<ProfileKey, ProfileWrapper> profilesByName = new ConcurrentHashMap<ProfileKey, ProfileWrapper>();
public void addProfile(Profile profile)
{
ProfileKey key = profile.getKey();
- this.profiles.put(key, new ProfileWrapper(profile));
+ this.profiles.add(key);
+ this.profilesByName.put(key, new ProfileWrapper(profile));
fireModificationEvent(new ProfileLifeCycleEvent(key, LifeCycleState.INSTALLED));
}
@@ -57,7 +62,9 @@
{
ProfileKey key = profile.getKey();
fireModificationEvent(new ProfileLifeCycleEvent(key, LifeCycleState.UNINSTALLED));
- ProfileWrapper wrapper = this.profiles.remove(key);
+ // Remove
+ this.profiles.remove(key);
+ ProfileWrapper wrapper = this.profilesByName.remove(key);
if(wrapper != null)
{
wrapper.lockWrite();
@@ -73,13 +80,19 @@
}
@Override
+ public List<ProfileKey> getActiveProfiles()
+ {
+ return Collections.unmodifiableList(this.profiles);
+ }
+
+ @Override
public ModificationStatus perfom(ProfileKey key, ProfileModificationActions<?> actions)
{
if(key == null)
{
throw new IllegalArgumentException("null profile key");
}
- ProfileWrapper wrapper = profiles.get(key);
+ ProfileWrapper wrapper = profilesByName.get(key);
if(wrapper == null)
{
throw new IllegalStateException("no such profile registered" + key);
Modified: projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/event/ProfileLifeCycleEvent.java
===================================================================
--- projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/event/ProfileLifeCycleEvent.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/core/src/main/java/org/jboss/profileservice/management/event/ProfileLifeCycleEvent.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -33,6 +33,7 @@
public class ProfileLifeCycleEvent implements ModificationEvent
{
+ /** The lifecycle state. */
public static enum LifeCycleState { INSTALLED, UNINSTALLED }
/** The state. */
Modified: projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/resolver/test/ActivationCallbackUnitTestCase.java
===================================================================
--- projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/resolver/test/ActivationCallbackUnitTestCase.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/core/src/test/java/org/jboss/test/profileservice/resolver/test/ActivationCallbackUnitTestCase.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -59,10 +59,5 @@
assertOrdering(result, "other", "test", "test1", "test2", "activation-group2");
}
- public void testWait() throws Exception
- {
- Thread.sleep(3 * 60 * 1000);
- }
-
}
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/AggregatingLocalManagementView.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -21,60 +21,491 @@
*/
package org.jboss.profileservice.plugins.management;
+import java.text.MessageFormat;
+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.CopyOnWriteArrayList;
-import org.jboss.profileservice.plugins.management.view.AbstractProfileView;
+import org.jboss.deployers.spi.management.DeploymentTemplate;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.NameMatcher;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.plugins.management.util.AbstractManagementProxyFactory;
+import org.jboss.profileservice.plugins.management.util.ProfileViewProcessorHelper;
import org.jboss.profileservice.plugins.spi.ProfileView;
+import org.jboss.profileservice.plugins.spi.ProfileViewWrapper;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
/**
- * The aggregating management view.
+ * The aggregating management view. This represents the local view of
+ * the server. The view on the domain will most probably aggregate
+ * the <code>ManagedObject</code>s defined in the <code>DomainMetaData</code>
+ * and expose them over a <code>DomainView</code>
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-class AggregatingLocalManagementView
+class AggregatingLocalManagementView implements ManagementView
{
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AggregatingLocalManagementView.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 views. */
- private List<ProfileView> views = new CopyOnWriteArrayList<ProfileView>();
+ private List<ProfileViewWrapper> views = new CopyOnWriteArrayList<ProfileViewWrapper>();
- public boolean load()
+ /** The deployment templates that have been registered with the MV. */
+ private Map<String, DeploymentTemplate> templates = new HashMap<String, DeploymentTemplate>();
+
+ /** The proxy factory. */
+ private AbstractManagementProxyFactory proxyFactory;
+
+ /** The processor helper. */
+ private ProfileViewProcessorHelper processorHelper;
+
+ public AggregatingLocalManagementView()
{
+ currentLocale = Locale.getDefault();
+ formatter.setLocale(currentLocale);
+ i18n = ResourceBundle.getBundle(BUNDLE_NAME, currentLocale);
+ }
+
+ public AbstractManagementProxyFactory getProxyFactory()
+ {
+ return proxyFactory;
+ }
+
+ public void setProxyFactory(AbstractManagementProxyFactory proxyFactory)
+ {
+ if(proxyFactory == null)
+ {
+ throw new IllegalArgumentException("null proxy factory");
+ }
+ this.proxyFactory = proxyFactory;
+ }
+
+ public void start()
+ {
+ if(proxyFactory == null)
+ {
+ throw new IllegalStateException("null proxy factory");
+ }
+ this.processorHelper = new ProfileViewProcessorHelper(proxyFactory);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public synchronized boolean load()
+ {
+ // Clear any thread interrupt
+ boolean wasInterrupted = Thread.interrupted();
+ if(wasInterrupted)
+ {
+ log.debug("Cleared interrupted state of calling thread");
+ }
boolean changed = false;
- for(ProfileView view : views)
+ for(final ProfileView view : views)
{
if(view.load())
changed = true;
}
+ // FIXME
+ processorHelper.clear();
+ //
+ if(wasInterrupted)
+ {
+ Thread.currentThread().interrupt();
+ log.debug("Restored interrupted state of calling thread");
+ }
return changed;
}
- public void addProfileView(AbstractProfileView view)
+ /**
+ * Add a profile view wrapper.
+ *
+ * @param view the profile view wrapper.
+ */
+ public void addProfileView(ProfileViewWrapper view)
{
if(view == null)
{
throw new IllegalArgumentException("null profile view");
}
- if(view.getKey() == null)
- {
- throw new IllegalArgumentException("null profile key");
- }
+ // FIXME
+ view.setProcessorHelper(processorHelper);
this.views.add(view);
}
- public void removeProfileView(AbstractProfileView view)
+ /**
+ * Remove profile view wrapper.
+ *
+ * @param view the profile view wrapper
+ */
+ public void removeProfileView(ProfileViewWrapper view)
{
if(view == null)
{
throw new IllegalArgumentException("null profile view");
}
- if(view.getKey() == null)
+ this.views.remove(view);
+ }
+
+ /**
+ * Add a deployment template.
+ *
+ * @param template the deployment template
+ */
+ public void addTemplate(DeploymentTemplate template)
+ {
+ if(template == null)
{
- throw new IllegalArgumentException("null profile key");
+ throw new IllegalArgumentException("null deployment template");
}
- this.views.remove(view);
+ if(template.getInfo() == null)
+ {
+ throw new IllegalArgumentException("null deployment template info");
+ }
+ if(template.getInfo().getName() == null)
+ {
+ throw new IllegalArgumentException("null deployment template info name");
+ }
+ this.templates.put(template.getInfo().getName(), template);
}
+ /**
+ * Remove a deployment template.
+ *
+ * @param template the deployment template
+ */
+ public void removeTemplate(DeploymentTemplate template)
+ {
+ if(template == null)
+ {
+ throw new IllegalArgumentException("null deployment template");
+ }
+ if(template.getInfo() == null)
+ {
+ throw new IllegalArgumentException("null deployment template info");
+ }
+ if(template.getInfo().getName() == null)
+ {
+ throw new IllegalArgumentException("null deployment template info name");
+ }
+ this.templates.remove(template.getInfo().getName());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ 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.");
+ }
+
+
+ final 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);
+ }
+
+ // TODO use deploy actions to distribute the content.
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedComponent getComponent(String name, ComponentType type) throws Exception
+ {
+ if(name == null)
+ {
+ throw new IllegalArgumentException("null component name");
+ }
+ ManagedComponent component = null;
+ for(final ProfileView view : views)
+ {
+ ManagedComponent resolved = view.getComponent(name, type);
+ if(resolved != null)
+ {
+ component = resolved;
+ }
+ // TODO fail on multiple results
+ }
+ if(component == null)
+ {
+ // TODO throw localized exception
+ throw new IllegalStateException("failed to find component for name " + name);
+ }
+ return component;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ComponentType> getComponentTypes()
+ {
+ Set<ComponentType> types = new HashSet<ComponentType>();
+ for(final ProfileView view : views)
+ {
+ types.addAll(view.getComponentTypes());
+ }
+ return types;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getComponentsForType(ComponentType type)
+ {
+ if(type == null)
+ {
+ throw new IllegalArgumentException("null component type");
+ }
+ Set<ManagedComponent> components = new HashSet<ManagedComponent>();
+ for(final ProfileView view : views)
+ {
+ components.addAll(view.getComponentsForType(type));
+ }
+ return components;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedDeployment getDeployment(String name) throws NoSuchDeploymentException
+ {
+ if(name == null)
+ {
+ throw new IllegalArgumentException("null deployment name");
+ }
+ ManagedDeployment deployment = null;
+ for(final ProfileView view : views)
+ {
+ ManagedDeployment resolved = view.getManagedDeployment(name);
+ if(resolved != null)
+ {
+ deployment = resolved;
+ }
+ // TODO fail on multiple results
+ }
+ if(deployment == null)
+ {
+ // TODO localized message
+ throw new NoSuchDeploymentException("Managed deployment: " + name + " not found.");
+ }
+ return deployment;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getDeploymentNames()
+ {
+ final Set<String> deploymentNames = new TreeSet<String>();
+ for(final ProfileView view : views)
+ {
+ deploymentNames.addAll(view.getDeploymentNames());
+ }
+ return deploymentNames;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getDeploymentNamesForType(String type)
+ {
+ if(type == null)
+ {
+ throw new IllegalArgumentException("null deployment type");
+ }
+ Set<String> deployments = new TreeSet<String>();
+ for(final ProfileView view: views)
+ {
+ deployments.addAll(view.getDeploymentNamesForType(type));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getDeploymentsForType(String type)
+ {
+ if(type == null)
+ {
+ throw new IllegalArgumentException("null deployment type");
+ }
+ Set<ManagedDeployment> deployments = new HashSet<ManagedDeployment>();
+ for(final ProfileView view : views)
+ {
+ deployments.addAll(view.getDeploymentsForType(type));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getMatchingComponents(String name, ComponentType type,
+ NameMatcher<ManagedComponent> matcher)
+ {
+ if(name == null)
+ {
+ throw new IllegalArgumentException("null component name");
+ }
+ if(type == null)
+ {
+ throw new IllegalArgumentException("null component type");
+ }
+ if(matcher == null)
+ {
+ throw new IllegalArgumentException("null component name matcher");
+ }
+ Set<ManagedComponent> components = new HashSet<ManagedComponent>();
+ for(final ProfileView view : views)
+ {
+ components.addAll(view.getMatchingComponents(name, type, matcher));
+ }
+ return components;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getMatchingDeploymentName(String regex) throws NoSuchDeploymentException
+ {
+ if(regex == null)
+ {
+ throw new IllegalArgumentException("null regex");
+ }
+ Set<String> deployments = new TreeSet<String>();
+ for(final ProfileView view : views)
+ {
+ deployments.addAll(view.getMatchingDeploymentName(regex));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getMatchingDeployments(String name, NameMatcher<ManagedDeployment> matcher)
+ {
+ if(name == null)
+ {
+ throw new IllegalArgumentException("null deployment name");
+ }
+ if(matcher == null)
+ {
+ throw new IllegalArgumentException("null deployment matcher");
+ }
+ Set<ManagedDeployment> deployments = new HashSet<ManagedDeployment>();
+ for(final ProfileView view : views)
+ {
+ deployments.addAll(view.getMatchingDeployments(name, matcher));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public DeploymentTemplateInfo getTemplate(String name) throws NoSuchDeploymentException
+ {
+ if(name == null)
+ {
+ throw new IllegalArgumentException("null template name");
+ }
+ final DeploymentTemplate template = this.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 NoSuchDeploymentException(msg);
+ }
+ // Make sure to return a copy to avoid call by reference uses modifying the template values
+ final DeploymentTemplateInfo info = template.getInfo();
+ return info.copy();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getTemplateNames()
+ {
+ return new TreeSet<String>(this.templates.keySet());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void process() throws Exception
+ {
+ // nothing ...
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void reload()
+ {
+ load();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void removeComponent(ManagedComponent comp) throws Exception
+ {
+ if(comp == null)
+ {
+ throw new IllegalArgumentException("null managed component");
+ }
+ // TODO
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void updateComponent(ManagedComponent comp) throws Exception
+ {
+ if(comp == null)
+ {
+ throw new IllegalArgumentException("null managed component");
+ }
+ // TODO
+ }
+
}
Deleted: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/PlatformMBeanView.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/PlatformMBeanView.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/PlatformMBeanView.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -1,39 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt 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.plugins.management;
-
-/**
- * A ProfileView exposing the Platform MBeans as ManagedComponents.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class PlatformMBeanView
-{
-
- public void start()
- {
- // ...
- }
-
-}
-
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/RegisteredProfileViewsWrapper.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,286 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.deployers.spi.management.NameMatcher;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.plugins.management.actions.ProfileViewUpdateAction;
+import org.jboss.profileservice.plugins.management.util.ProfileViewProcessorHelper;
+import org.jboss.profileservice.plugins.management.view.RegisteredProfileView;
+import org.jboss.profileservice.plugins.spi.ProfileView;
+import org.jboss.profileservice.plugins.spi.ProfileViewWrapper;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.action.ProfileModificationAction;
+import org.jboss.profileservice.spi.action.ProfileModificationContext;
+import org.jboss.profileservice.spi.action.engine.ActionController;
+import org.jboss.profileservice.spi.action.engine.EventBus;
+import org.jboss.profileservice.spi.action.engine.ModificationEvent;
+
+
+/**
+ * A wrapper to handle multiple registered <code>ProfileView</code>s.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class RegisteredProfileViewsWrapper implements ProfileViewWrapper
+{
+
+ /** The profiles. */
+ private List<ProfileKey> registeredKeys = new ArrayList<ProfileKey>();
+ private Map<ProfileKey, RegisteredProfileView> viewsByName = new ConcurrentHashMap<ProfileKey, RegisteredProfileView>();
+
+ /** The helper. */
+ private ProfileViewProcessorHelper helper;
+
+ /** The action controller. */
+ private final ActionController controller;
+
+ public RegisteredProfileViewsWrapper(ActionController controller)
+ {
+ if(controller == null)
+ {
+ throw new IllegalArgumentException("null action controller");
+ }
+ this.controller = controller;
+ }
+
+ public synchronized boolean load()
+ {
+ boolean changed = false;
+
+ List<ProfileKey> have = registeredKeys;
+ this.registeredKeys = new ArrayList<ProfileKey>();
+ // Additions
+ for(ProfileKey key : controller.getActiveProfiles())
+ {
+ have.remove(key);
+ registeredKeys.add(key);
+
+ RegisteredProfileView view = createProfileView(key);
+ viewsByName.put(key, view);
+
+ // TODO
+ EventBus.class.cast(controller).addListener(view);
+ }
+ // Removals
+ for(ProfileKey key : have)
+ {
+ ProfileView view = viewsByName.remove(key);
+ // TODO
+ EventBus.class.cast(controller).removeListener(view);
+ changed = true;
+ }
+ // Load and process
+ for(ProfileView view : viewsByName.values())
+ {
+ if(view.load())
+ {
+ ProfileModificationAction<ProfileModificationContext> action = new ProfileViewUpdateAction();
+ // big TODO use the controller to dispatch the updateAction
+ changed = true;
+ }
+ }
+ //
+ return changed;
+ }
+
+ RegisteredProfileView createProfileView(ProfileKey key)
+ {
+ return new RegisteredProfileView(key);
+ }
+
+ protected Collection<RegisteredProfileView> getViews()
+ {
+ return this.viewsByName.values();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setProcessorHelper(ProfileViewProcessorHelper processorHelper)
+ {
+ this.helper = processorHelper;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedComponent getComponent(String name, ComponentType type)
+ {
+ ManagedComponent component = null;
+ for(final ProfileView view : getViews())
+ {
+ ManagedComponent resolved = view.getComponent(name, type);
+ if(resolved != null)
+ {
+ component = resolved;
+ }
+ // TODO fail on duplicates ?
+ // maybe should be done by the top level view?
+ }
+ return component;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ComponentType> getComponentTypes()
+ {
+ Set<ComponentType> types = new HashSet<ComponentType>();
+ for(final ProfileView view : getViews())
+ {
+ types.addAll(view.getComponentTypes());
+ }
+ return types;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getComponentsForType(ComponentType type)
+ {
+ Set<ManagedComponent> components = new HashSet<ManagedComponent>();
+ for(final ProfileView view : getViews())
+ {
+ components.addAll(view.getComponentsForType(type));
+ }
+ return components;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<String> getDeploymentNames()
+ {
+ Set<String> deployments = new TreeSet<String>();
+ for(final ProfileView view : getViews())
+ {
+ deployments.addAll(view.getDeploymentNames());
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getDeploymentNamesForType(String type)
+ {
+ Set<String> deployments = new TreeSet<String>();
+ for(final ProfileView view : getViews())
+ {
+ deployments.addAll(view.getDeploymentNamesForType(type));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getDeploymentsForType(String type)
+ {
+ Set<ManagedDeployment> deployments = new HashSet<ManagedDeployment>();
+ for(final ProfileView view : getViews())
+ {
+ deployments.addAll(view.getDeploymentsForType(type));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedDeployment getManagedDeployment(String name)
+ {
+ ManagedDeployment deployment = null;
+ for(final ProfileView view : getViews())
+ {
+ final ManagedDeployment resolved = view.getManagedDeployment(name);
+ if(resolved != null)
+ {
+ deployment = resolved;
+ }
+ }
+ return deployment;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getMatchingComponents(String name, ComponentType type,
+ NameMatcher<ManagedComponent> matcher)
+ {
+ Set<ManagedComponent> components = new HashSet<ManagedComponent>();
+ for(final ProfileView view : getViews())
+ {
+ components.addAll(view.getMatchingComponents(name, type, matcher));
+ }
+ return components;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getMatchingDeploymentName(String regex)
+ {
+ Set<String> deployments = new TreeSet<String>();
+ for(final ProfileView view : getViews())
+ {
+ deployments.addAll(view.getMatchingDeploymentName(regex));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getMatchingDeployments(String name, NameMatcher<ManagedDeployment> matcher)
+ {
+ Set<ManagedDeployment> deployments = new HashSet<ManagedDeployment>();
+ for(final ProfileView view : getViews())
+ {
+ deployments.addAll(view.getMatchingDeployments(name, matcher));
+ }
+ return deployments;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void notify(ModificationEvent event)
+ {
+ // nothing
+ }
+
+}
+
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/actions/ProfileViewUpdateAction.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/actions/ProfileViewUpdateAction.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/actions/ProfileViewUpdateAction.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,96 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management.actions;
+
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.deployment.ProfileDeployerPlugin;
+import org.jboss.profileservice.plugins.management.util.ProfileViewProcessorHelper;
+import org.jboss.profileservice.plugins.spi.ProfileViewProcessingContext;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.profileservice.spi.action.ProfileModificationAction;
+import org.jboss.profileservice.spi.action.ProfileModificationContext;
+import org.jboss.profileservice.spi.metadata.ProfileMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ProfileViewUpdateAction implements ProfileModificationAction<ProfileModificationContext>
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(ProfileViewUpdateAction.class);
+
+ private boolean complete = false;
+
+ Profile profile; // has to come from the ActionController
+ ProfileMetaData metaData; // has to come from the ActionController
+ ProfileDeployerPlugin deployer; // has to come from the ActionController
+
+ ProfileViewProcessorHelper helper; // modification context ?
+ ProfileViewProcessingContext context;
+
+ @Override
+ public ProfileModificationContext getContext()
+ {
+ return null;
+ }
+
+ public void complete()
+ {
+ for(ProfileDeployment deployment : profile.getDeployments())
+ {
+ try
+ {
+ ManagedDeployment md = deployer.getManagedDeployment(deployment);
+ helper.processRootManagedDeployment(md, context);
+ }
+ catch(Exception e)
+ {
+ log.debug("failed to process managed deployment " + deployment.getName(), e);
+ }
+ }
+ }
+
+ @Override
+ public void cancel()
+ {
+ //
+ }
+
+ @Override
+ public boolean isCancelled()
+ {
+ return false;
+ }
+
+ @Override
+ public boolean isComplete()
+ {
+ return complete;
+ }
+
+
+}
+
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/messages.properties
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/messages.properties (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/messages.properties 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,11 @@
+#
+ManagementView.NoSuchProfileException=Failed to find profile for key: {0}
+ManagementView.NoProfileLoadedException=No profile has been loaded, use loadProfile(ProfileKey, boolean)
+ManagementView.NoSuchDeploymentException=Failed to find deployment for name: {0}
+ManagementView.MainDeployerRemoveException=MainDeployer failed to remove deployment for name: {0}
+ManagementView.NoSuchTemplate=Failed to find template for: {0}
+ManagementView.InvalidTemplateKey=Failed to map key: {0} to managed attachments for deployment
+ManagementView.InvalidTemplateProperty=Failed to map property: {0} to managed properties for deployment
+ManagementView.InvalidTemplatePropertyMO=Property: {0} does not use ManagedObjectImpl
+ManagementView.InvalidComponentName=Name: {0} does not map to existing ManagedComponet in ManagedDeployment: {1}
+ManagementView.InvalidPropertyValue=Property: {0} value type is not a MetaValue, type: {1}
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/AbstractManagementProxyFactory.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -21,11 +21,16 @@
*/
package org.jboss.profileservice.plugins.management.util;
+import org.jboss.deployers.spi.management.RuntimeComponentDispatcher;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedOperation;
import org.jboss.managed.api.ManagedProperty;
/**
+ * The abstract managed proxy factory. A internal factory class
+ * creating AOP proxies to allow runtime dispatching from the
+ * client.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
@@ -33,12 +38,19 @@
{
/**
+ * Get the runtime component dispatcher.
+ *
+ * @return the runtime component dispatcher
+ */
+ protected abstract RuntimeComponentDispatcher getDispatcher();
+
+ /**
* Create a proxy component.
*
* @param delegate the delegate component
* @return the proxy component
*/
- protected abstract ManagedComponent createComponentProxy(ManagedComponent delegate);
+ protected abstract ManagedComponent createComponentProxy(ManagedComponent delegate, Object componentName);
/**
* Create a proxy property.
@@ -46,7 +58,7 @@
* @param delegate the delegate property
* @return the proxy property
*/
- protected abstract ManagedProperty createPropertyProxy(ManagedProperty delegate);
+ protected abstract ManagedProperty createPropertyProxy(ManagedProperty delegate, Object componentName);
/**
* Create a proxy operation.
@@ -54,7 +66,7 @@
* @param delegate the delegate operation
* @return the proxy operation
*/
- protected abstract ManagedOperation createOperationProxy(ManagedOperation delegate);
+ protected abstract ManagedOperation createOperationProxy(ManagedOperation delegate, Object componentName);
}
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/DefaultContextStateMapper.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/DefaultContextStateMapper.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/DefaultContextStateMapper.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management.util;
+
+import java.util.Map;
+
+import org.jboss.deployers.spi.management.ContextStateMapper;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DefaultContextStateMapper<T extends Enum<?>> extends ContextStateMapper<T>
+{
+
+ public DefaultContextStateMapper(Map<String, T> mappings, T installState, T uninstallState,
+ T error, T unknown)
+ {
+ super(mappings, installState, uninstallState, error, unknown);
+ }
+
+ @Override
+ public T map(String currentState, String toState)
+ {
+ // TODO dependency missing on jboss-kernel
+
+// // If the context is in the required state
+// if(toState == null || currentState.equals(toState))
+// return getMapping(currentState);
+// // The error state
+// if(ControllerState.ERROR.equals(currentState))
+// return error;
+// // installing state
+// if(ControllerState.INSTALLED.equals(toState))
+// return installState;
+// // uninstalling state
+// if(ControllerState.NOT_INSTALLED.equals(toState))
+// return uninstallState;
+// // Fallback
+// return getMapping(currentState);
+ return unknown;
+ }
+
+
+}
+
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ManagedDeploymentProcessor.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ManagedDeploymentProcessor.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ManagedDeploymentProcessor.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -21,54 +21,390 @@
*/
package org.jboss.profileservice.plugins.management.util;
+import java.lang.annotation.Annotation;
import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
-import org.jboss.deployers.spi.management.ContextStateMapper;
+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.plugins.spi.ProfileViewProcessingContext;
/**
* A helper to process managed deployments.
*
- * TODO we need to change how ManagedDeployments/ManagedObjects/ManagedComponents
+ * TODO we need separate the registry out of the processor.
+ *
+ * TODO (long term) we need to change how ManagedDeployments/ManagedObjects/ManagedComponents
* are created. This is a temporary solution to make things work.
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class ManagedDeploymentProcessor
+public abstract class ManagedDeploymentProcessor
{
- /** The state mappings. */
- private static final ContextStateMapper<RunState> runStateMapper;
- private static final ContextStateMapper<DeploymentState> deploymentStateMapper;
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(ManagedDeploymentProcessor.class);
- static
+ /** 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>();
+
+ /**
+ * FIXME clear()
+ */
+ public void clear()
{
- // 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);
+ moRegistry.clear();
+ unresolvedRefs.clear();
+ runtimeMOs.clear();
+ }
+
+ // runtime functionality
+
+ protected abstract void mergeRuntimeMO(ManagedObject mo, ManagedObject runtimeMO) throws Exception;
- runStateMapper = new ContextStateMapper<RunState>(runStateMappings,
- RunState.STARTING, RunState.STOPPED, RunState.FAILED, RunState.UNKNOWN);
+ protected abstract Set<ManagedOperation> createOperationProxies(ManagedObject mo, Set<ManagedOperation> runtimeOps) throws Exception;
- Map<String, DeploymentState> deploymentMappings = new HashMap<String, DeploymentState>();
- deploymentMappings.put("**ERROR**", DeploymentState.FAILED);
- deploymentMappings.put("Not Installed", DeploymentState.STOPPED);
- deploymentMappings.put("Installed", DeploymentState.STARTED);
+ protected abstract RunState updateRunState(ManagedObject mo, ManagedComponent comp) throws Exception;
- deploymentStateMapper = new ContextStateMapper<DeploymentState>(deploymentMappings,
- DeploymentState.STARTING, DeploymentState.STOPPING, DeploymentState.FAILED, DeploymentState.UNKNOWN);
+ // use the implementation from the previous ManagementViewImpl
+
+ protected void processManagedDeployment(ManagedDeployment md, DeploymentState state, int level, ProfileViewProcessingContext context) throws Exception
+ {
+ boolean trace = log.isTraceEnabled();
+
+ 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, context);
+ }
+ // Add the deployment
+ context.addManagedDeployment(md);
+
+ // 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, context);
+ }
+ }
}
+
+ /**
+ * Process managed object.
+ *
+ * @param mo the managed object
+ * @param md the managed deployment
+ */
+ protected void processManagedObject(ManagedObject mo, ManagedDeployment md, ProfileViewProcessingContext context)
+ throws Exception
+ {
+ boolean trace = log.isTraceEnabled();
+
+ String key = mo.getName() + "/" + mo.getNameType();
+ if(trace)
+ {
+ log.trace("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)
+ {
+ if(trace)
+ {
+ log.trace("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);
+ if(trace)
+ {
+ log.trace("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);
+ if(trace)
+ {
+ log.trace("Updated component: "+comp+" run state to: "+state);
+ }
+ }
+ }
+ }
+ // Check for unresolved refs
+ checkForReferences(key, mo);
+
+ // Map any existing ManagedComponent types
+ for(ManagedComponent comp : md.getComponents().values())
+ {
+ if(trace)
+ {
+ log.trace("Updating ManagementComponent: "+comp);
+ }
+ context.addManagedComponent(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);
+ if(trace)
+ {
+ log.trace("Processing ManagementComponent("+mo.getName()+"): "+comp);
+ }
+
+ context.addManagedComponent(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();
+ if(trace)
+ {
+ log.trace("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()
+ if(trace)
+ {
+ log.trace("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)
+ {
+ if(trace)
+ {
+ log.trace("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, context);
+ }
+ 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, context);
+ }
+ }
+ 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, context);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * 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.trace("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, ProfileViewProcessingContext context) 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, context);
+ }
+ }
+
+
}
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ProfileViewProcessorHelper.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ProfileViewProcessorHelper.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/ProfileViewProcessorHelper.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,296 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management.util;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.management.ContextStateMapper;
+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.plugins.spi.ProfileViewProcessingContext;
+
+/**
+ * The profile view processor helper.
+ *
+ * TODO we need to make the this stateless.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ProfileViewProcessorHelper extends ManagedDeploymentProcessor
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(ProfileViewProcessorHelper.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 AbstractManagementProxyFactory 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 DefaultContextStateMapper<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 DefaultContextStateMapper<DeploymentState>(deploymentMappings,
+ DeploymentState.STARTING, DeploymentState.STOPPING, DeploymentState.FAILED, DeploymentState.UNKNOWN);
+ }
+
+ public ProfileViewProcessorHelper(AbstractManagementProxyFactory 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 void processRootManagedDeployment(ManagedDeployment md, ProfileViewProcessingContext context) throws Exception
+ {
+ DeploymentState state = getDeploymentState(md);
+ processManagedDeployment(md, state, 0, context);
+ }
+
+ @Override
+ protected void mergeRuntimeMO(ManagedObject mo, ManagedObject runtimeMO)
+ throws Exception
+ {
+ boolean trace = log.isTraceEnabled();
+
+ Map<String, ManagedProperty> runtimeProps = runtimeMO.getProperties();
+ Set<ManagedOperation> runtimeOps = runtimeMO.getOperations();
+ // Get the runtime MO component name
+ Object componentName = runtimeMO.getComponentName();
+ if(trace)
+ {
+ log.trace("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)
+ {
+ if(trace)
+ {
+ log.trace("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
+ {
+ // RuntimeComponentDispatcher.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);
+ }
+ if(trace)
+ {
+ log.trace("Properties after:"+props);
+ }
+ }
+ if (runtimeOps != null && runtimeOps.size() > 0)
+ {
+ if(trace)
+ {
+ log.trace("Ops before:"+ops);
+ }
+ runtimeOps = createOperationProxies(runtimeMO, runtimeOps);
+ ops.addAll(runtimeOps);
+ if(trace)
+ {
+ log.trace("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
+ Set<ManagedOperation> operations = new HashSet<ManagedOperation>();
+ for(ManagedOperation op : ops)
+ {
+ ManagedOperation operation = proxyFactory.createOperationProxy(op, componentName);
+ operations.add(operation);
+ }
+ return operations;
+ }
+
+ 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
+ RuntimeComponentDispatcher xdispatcher = dispatcher;
+ state = xdispatcher.mapControllerState(name, mapper);
+ }
+ catch(Exception e)
+ {
+ state = mapper.getErrorState();
+ }
+ }
+ return state;
+ }
+
+}
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/package-info.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/package-info.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/util/package-info.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,25 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management.util;
\ No newline at end of file
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileView.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileView.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileView.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -22,78 +22,286 @@
package org.jboss.profileservice.plugins.management.view;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.jboss.deployers.spi.management.KnownComponentTypes;
+import org.jboss.deployers.spi.management.NameMatcher;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment;
-import org.jboss.profileservice.deployment.ProfileDeployerPlugin;
+import org.jboss.managed.api.ManagedObject;
import org.jboss.profileservice.plugins.spi.ProfileView;
-import org.jboss.profileservice.spi.Profile;
-import org.jboss.profileservice.spi.ProfileDeployment;
-import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.profileservice.spi.metadata.ProfileMetaData;
+import org.jboss.profileservice.plugins.spi.ProfileViewProcessingContext;
+import org.jboss.profileservice.spi.action.engine.ModificationEvent;
+import org.jboss.profileservice.spi.action.engine.ModificationListener;
-
/**
+ * The abstract profile view.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class AbstractProfileView implements ProfileView
+public class AbstractProfileView implements ProfileView, ProfileViewProcessingContext, ModificationListener
{
+
+ /** The managed components by ComponentType. */
+ private Map<ComponentType, Set<ManagedComponent>> compByCompType = new HashMap<ComponentType, Set<ManagedComponent>>();
- /** The profile. */
- private final Profile profile;
- private final ProfileMetaData metaData;
- private final ProfileDeployerPlugin deployer;
+ /** The managed deployments by name. */
+ private Map<String, ManagedDeployment> managedDeployments = new HashMap<String, ManagedDeployment>();
+
+ /** Is modified. */
+ private final AtomicBoolean modified;
- public AbstractProfileView(Profile profile, ProfileMetaData metaData, ProfileDeployerPlugin deployer)
+ public AbstractProfileView()
{
- if(profile == null)
+ // Set true for the first load()
+ this.modified = new AtomicBoolean(true);
+ }
+
+ public boolean load()
+ {
+ if(this.modified.getAndSet(false))
{
- throw new IllegalArgumentException("null profile");
+ return false;
}
- if(metaData == null)
- {
- throw new IllegalArgumentException("null profile meta data");
- }
- this.profile = profile;
- this.deployer = deployer;
- this.metaData = metaData;
+ // Clear the stuff
+ compByCompType.clear();
+ managedDeployments.clear();
+
+ return true;
}
- public ProfileKey getKey()
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<String> getDeploymentNames()
{
- return this.profile.getKey();
+ return managedDeployments.keySet();
}
- @Override
- public Collection<String> getDeploymentNames()
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedDeployment getManagedDeployment(final String name)
{
- // FIXME getDeploymentNames
+ ManagedDeployment deployment = managedDeployments.get(name);
+ if(deployment == null)
+ {
+ for(final ManagedDeployment d : managedDeployments.values())
+ {
+ if(name.equals(d.getSimpleName()))
+ {
+ deployment = d;
+ break;
+ }
+ }
+ }
return null;
}
- @Override
- public ManagedDeployment getManagedDeployment(String name)
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getMatchingDeploymentName(final String regex)
{
- // FIXME getManagedDeployment
+ final Collection<String> names = getDeploymentNames();
+ final HashSet<String> matches = new HashSet<String>();
+ final Pattern p = Pattern.compile(regex);
+ for(final String name : names)
+ {
+ final Matcher m = p.matcher(name);
+ if( m.matches() )
+ {
+ matches.add(name);
+ }
+ }
+ return matches;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getMatchingDeployments(final String name, final NameMatcher<ManagedDeployment> matcher)
+ {
+ final Set<ManagedDeployment> matches = new HashSet<ManagedDeployment>();
+ for(final ManagedDeployment deployment : this.managedDeployments.values())
+ {
+ if(matcher.matches(deployment, name))
+ {
+ matches.add(deployment);
+ }
+ }
+ return matches;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getDeploymentNamesForType(String type)
+ {
+ final Set<String> matches = new TreeSet<String>();
+ for(final ManagedDeployment md : managedDeployments.values())
+ {
+ final String name = md.getName();
+ final Set<String> types = md.getTypes();
+ if(types != null)
+ {
+ if(types.contains(type))
+ {
+ matches.add(name);
+ }
+ }
+ }
+ return matches;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedComponent getComponent(final String name, final ComponentType type)
+ {
+ final Set<ManagedComponent> components = compByCompType.get(type);
+ if(components != null)
+ {
+ for(final ManagedComponent mc : components)
+ {
+ if(mc.getName().equals(name))
+ {
+ return mc;
+ }
+ }
+ }
return null;
}
- public boolean load()
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ComponentType> getComponentTypes()
{
- for(ProfileDeployment deployment : profile.getDeployments())
+ return compByCompType.keySet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getComponentsForType(ComponentType type)
+ {
+ Set<ManagedComponent> comps = null;
+ // Check the any component type
+ if(type.equals(KnownComponentTypes.ANY_TYPE))
{
- try
+ HashSet<ManagedComponent> all = new HashSet<ManagedComponent>();
+ for(Set<ManagedComponent> typeComps : compByCompType.values())
{
- ManagedDeployment md = deployer.getManagedDeployment(deployment);
+ for(ManagedComponent comp : typeComps)
+ {
+ all.add(comp);
+ }
}
- catch(Exception e)
+ comps = all;
+ }
+ else
+ {
+ comps = compByCompType.get(type);
+ }
+ if(comps == null)
+ {
+ comps = Collections.emptySet();
+ }
+ return comps;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getDeploymentsForType(String type)
+ {
+ final Set<String> names = getDeploymentNamesForType(type);
+ final HashSet<ManagedDeployment> mds = new HashSet<ManagedDeployment>();
+ for(String name : names)
+ {
+ final ManagedDeployment md = getManagedDeployment(name);
+ mds.add(md);
+ }
+ return mds;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getMatchingComponents(final String name, final ComponentType type,
+ final NameMatcher<ManagedComponent> matcher)
+ {
+ Set<ManagedComponent> components = compByCompType.get(type);
+ Set<ManagedComponent> matched = new HashSet<ManagedComponent>();
+ if(components != null)
+ {
+ for(ManagedComponent mc : components)
{
-
+ if(matcher.matches(mc, name))
+ matched.add(mc);
}
-
}
- return true;
+ return matched;
}
+
+ // ProfileViewProcessingContext
+ /**
+ * {@inheritDoc}
+ */
+ public void addManagedComponent(final ManagedComponent component)
+ {
+ final ComponentType type = component.getType();
+ Set<ManagedComponent> components = compByCompType.get(type);
+ if(components == null)
+ {
+ components = new HashSet<ManagedComponent>();
+ compByCompType.put(type, components);
+ }
+ components.add(component);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addManagedDeployment(ManagedDeployment deployment)
+ {
+ this.managedDeployments.put(deployment.getName(), deployment);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void addManagedObject(ManagedObject managedObject)
+ {
+ throw new IllegalStateException("unsupported operation");
+ }
+
+ // ModificationListener
+
+ /**
+ * {@inheritDoc}
+ */
+ public void notify(ModificationEvent event)
+ {
+ // nothing here
+ }
+
+ void markAsModified()
+ {
+ this.modified.set(true);
+ }
+
}
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileViewWrapper.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileViewWrapper.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/AbstractProfileViewWrapper.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,158 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management.view;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.jboss.deployers.spi.management.NameMatcher;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.plugins.management.util.ProfileViewProcessorHelper;
+import org.jboss.profileservice.plugins.spi.ProfileView;
+import org.jboss.profileservice.plugins.spi.ProfileViewWrapper;
+import org.jboss.profileservice.spi.action.engine.ModificationEvent;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractProfileViewWrapper implements ProfileViewWrapper
+{
+
+ /** The processor helper... */
+ private ProfileViewProcessorHelper processorHelper;
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract boolean load();
+
+ /**
+ * Get the delegate.
+ *
+ * @return the delegate profile view
+ */
+ protected abstract ProfileView getDelegate();
+
+ public ProfileViewProcessorHelper getProcessorHelper()
+ {
+ return processorHelper;
+ }
+
+ public void setProcessorHelper(ProfileViewProcessorHelper processorHelper)
+ {
+ this.processorHelper = processorHelper;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedComponent getComponent(String name, ComponentType type)
+ {
+ return getDelegate().getComponent(name, type);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getComponentsForType(ComponentType type)
+ {
+ return getDelegate().getComponentsForType(type);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ComponentType> getComponentTypes()
+ {
+ return getDelegate().getComponentTypes();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Collection<String> getDeploymentNames()
+ {
+ return getDelegate().getDeploymentNames();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getDeploymentNamesForType(String type)
+ {
+ return getDelegate().getDeploymentNamesForType(type);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getDeploymentsForType(String type)
+ {
+ return getDelegate().getDeploymentsForType(type);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedDeployment getManagedDeployment(String name)
+ {
+ return getDelegate().getManagedDeployment(name);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedComponent> getMatchingComponents(String name, ComponentType type,
+ NameMatcher<ManagedComponent> matcher)
+ {
+ return getDelegate().getMatchingComponents(name, type, matcher);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<String> getMatchingDeploymentName(String regex)
+ {
+ return getDelegate().getMatchingDeploymentName(regex);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Set<ManagedDeployment> getMatchingDeployments(String name, NameMatcher<ManagedDeployment> matcher)
+ {
+ return getDelegate().getMatchingDeployments(name, matcher);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void notify(ModificationEvent event)
+ {
+ getDelegate().notify(event);
+ }
+
+}
+
Copied: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java (from rev 100807, projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/PlatformMBeanView.java)
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/PlatformMBeanView.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,117 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management.view;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+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.plugins.spi.ProfileView;
+
+/**
+ * A ProfileView exposing the Platform MBeans as <code>ManagedComponents</code>.
+ *
+ * This view is immutable, it will only get create the first time
+ * the view gets loaded. Therefore all containing <code>ManagedObject</code>s
+ * and/or <code>ManagedComponent</code>s need to declare dynamic properties,
+ * as <code>ViewUse.STATISTIC</code> and <code>runtime=true</code>.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class PlatformMBeanView extends AbstractProfileViewWrapper
+{
+
+ /** The managed object factory. */
+ private static final ManagedObjectFactory managedObjFactory = ManagedObjectFactory.getInstance();
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(PlatformMBeanView.class);
+
+ /** The profile view. */
+ private final AbstractProfileView view;
+
+ protected static ManagedDeployment getDeployment()
+ {
+ // TODO we need a more flexible way to declare/add ManagedObjects/Components
+ // Creating non-existing deployments to reuse existing code does not make much sense
+ 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 PlatformMBeanView()
+ {
+ this.view = new AbstractProfileView();
+ }
+
+ @Override
+ protected ProfileView getDelegate()
+ {
+ return view;
+ }
+
+ public boolean load()
+ {
+ if(view.load())
+ {
+ try
+ {
+ getProcessorHelper().processRootManagedDeployment(getDeployment(), view);
+ }
+ catch(Exception e)
+ {
+ log.debug("failed to create platform MBean management interfaces", e);
+ }
+ return true;
+ }
+ return false;
+ }
+
+}
+
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/RegisteredProfileView.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/RegisteredProfileView.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/management/view/RegisteredProfileView.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.management.view;
+
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.action.engine.ModificationEvent;
+
+/**
+ * A view of an active <code>Profile</code> using <code>ProfileService</code>.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class RegisteredProfileView extends AbstractProfileView
+{
+
+ /** The profile. */
+ private final ProfileKey key;
+
+ public RegisteredProfileView(ProfileKey key)
+ {
+ super();
+ if(key == null)
+ {
+ throw new IllegalArgumentException("null profile key");
+ }
+ this.key = key;
+ }
+
+ public ProfileKey getKey()
+ {
+ return key;
+ }
+
+ @Override
+ public void notify(final ModificationEvent event)
+ {
+ // TODO this should be more fine grained
+ if(getKey().equals(event.getKey()))
+ {
+ markAsModified();
+ }
+ }
+
+}
+
Modified: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileView.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileView.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileView.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -22,9 +22,13 @@
package org.jboss.profileservice.plugins.spi;
import java.util.Collection;
+import java.util.Set;
+import org.jboss.deployers.spi.management.NameMatcher;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment;
-import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.action.engine.ModificationListener;
/**
* A management view of a single profile and extension point for integrating
@@ -33,24 +37,17 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public interface ProfileView
+public interface ProfileView extends ModificationListener
{
/**
- * Load a profile view.
+ * Load the profile view.
*
* @return if there were changes
*/
boolean load();
/**
- * Get the profile key.
- *
- * @return the profile key
- */
- ProfileKey getKey();
-
- /**
* Get the deployment names.
*
* @return the deployment names
@@ -65,5 +62,74 @@
*/
ManagedDeployment getManagedDeployment(String name);
+ /**
+ * Get the names of the deployment that have the given deployment type.
+ *
+ * @param type - the deployment type
+ * @return the names
+ */
+ Set<String> getDeploymentNamesForType(String type);
+
+ /**
+ * Search for all deployment names with a name matching the regex expression.
+ *
+ * @param regex - the regex to query deployment name
+ * @return the deployment name.
+ */
+ Set<String> getMatchingDeploymentName(String regex);
+
+ /**
+ * Search for all deployments matched by the matcher.
+ *
+ * @param name - the name to input to the matcher
+ * @param matcher - the matcher
+ * @return a possibly empty set of ManagedDeployment accepted by the matcher
+ */
+ Set<ManagedDeployment> getMatchingDeployments(String name, NameMatcher<ManagedDeployment> matcher);
+
+ /**
+ * Get the deployments of a type.
+ *
+ * @param type - the deployment or module type.
+ * @return the possibly empty set of deployment with the given type.
+ * @throws Exception
+ */
+ Set<ManagedDeployment> getDeploymentsForType(String type);
+
+ /**
+ * Get a set of the component types in use in the profiles
+ *
+ * @return set of component types in use
+ */
+ Set<ComponentType> getComponentTypes();
+
+ /**
+ * Get the components of a type.
+ *
+ * @param type - the component type.
+ * @return the possibly empty set of components with the given type.
+ */
+ Set<ManagedComponent> getComponentsForType(ComponentType type);
+
+ /**
+ * Obtain the ManagedComponent for the given name/type
+ *
+ * @see #getComponent(String, ComponentType, NameMatcher)
+ * @param name - the ManagedComponent#getName value to match
+ * @param type - the component type
+ * @return the possibly null ManagedComponent
+ */
+ ManagedComponent getComponent(String name, ComponentType type);
+ /**
+ * Obtain the ManagedComponents for the given name/type and matcher.
+ *
+ * @param name - the ManagedComponent#getName value to match
+ * @param type - the component type
+ * @param matcher - a matcher that compares name to candidate ManagedComponent
+ * @return the possibly empty set of ManagedComponent matches.
+ */
+ Set<ManagedComponent> getMatchingComponents(String name, ComponentType type,
+ NameMatcher<ManagedComponent> matcher);
+
}
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewProcessingContext.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewProcessingContext.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewProcessingContext.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.spi;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+
+/**
+ * The management deployment processing context.
+ *
+ * We are going to update the deployers integration to support
+ * a visitor pattern to build the server-side view of MOs in future.
+ * This will likely be similar, just based on a deployment level -
+ * not on the whole profile.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface ProfileViewProcessingContext
+{
+
+ /**
+ * Add a managed object.
+ *
+ * @param managedObject the managed object
+ */
+ // TODO this cannot be really used for now.
+ public void addManagedObject(ManagedObject managedObject);
+
+ /**
+ * Add a managed component.
+ *
+ * @param component the managed component
+ */
+ public void addManagedComponent(ManagedComponent component);
+
+ /**
+ * Add a managed deployment.
+ *
+ * @param deployment the managed deployment
+ */
+ public void addManagedDeployment(ManagedDeployment deployment);
+
+}
+
Added: projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java
===================================================================
--- projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java (rev 0)
+++ projects/profileservice/trunk/plugins/src/main/java/org/jboss/profileservice/plugins/spi/ProfileViewWrapper.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -0,0 +1,37 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2010, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.plugins.spi;
+
+import org.jboss.profileservice.plugins.management.util.ProfileViewProcessorHelper;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface ProfileViewWrapper extends ProfileView
+{
+
+ // FIXME
+ void setProcessorHelper(ProfileViewProcessorHelper processorHelper);
+
+}
+
Modified: projects/profileservice/trunk/spi/pom.xml
===================================================================
--- projects/profileservice/trunk/spi/pom.xml 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/spi/pom.xml 2010-02-10 18:26:33 UTC (rev 100821)
@@ -14,30 +14,30 @@
<url>http://www.jboss.org/jbossas</url>
<description>JBoss ProfileService SPI</description>
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.5</version>
- <configuration>
- <doclet>net.gleamynode.apiviz.APIviz</doclet>
- <docletArtifact>
- <groupId>org.jboss.apiviz</groupId>
- <artifactId>apiviz</artifactId>
- <version>1.2.5.GA</version>
- </docletArtifact>
- <doctitle><![CDATA[ProfileService SPI ]]>${version}</doctitle>
- <header><![CDATA[ProfileService SPI ]]>${version}</header>
- <footer><![CDATA[ProfileService SPI ]]>${version}</footer>
- <bottom><![CDATA[<i>Copyright © 2009 JBoss, a division of Red Hat, Inc.</i>]]></bottom>
- <links>
- <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
- </links>
- </configuration>
- </plugin>
- </plugins>
- </reporting>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <doclet>net.gleamynode.apiviz.APIviz</doclet>
+ <docletArtifact>
+ <groupId>org.jboss.apiviz</groupId>
+ <artifactId>apiviz</artifactId>
+ <version>1.2.5.GA</version>
+ </docletArtifact>
+ <doctitle><![CDATA[ProfileService SPI ]]>${version}</doctitle>
+ <header><![CDATA[ProfileService SPI ]]>${version}</header>
+ <footer><![CDATA[ProfileService SPI ]]>${version}</footer>
+ <bottom><![CDATA[<i>Copyright © 2009 JBoss, a division of Red Hat, Inc.</i>]]></bottom>
+ <links>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
+ </links>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
<dependencies>
<dependency>
@@ -52,9 +52,10 @@
<groupId>org.jboss</groupId>
<artifactId>jboss-vfs</artifactId>
</dependency>
+ <!-- jboss-man depends on reflect, so we can depend on it as well -->
<dependency>
- <groupId>org.jboss.kernel</groupId>
- <artifactId>jboss-dependency</artifactId>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
</dependency>
</dependencies>
Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ContextStateMapper.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -23,31 +23,29 @@
import java.util.Map;
-import org.jboss.dependency.spi.ControllerState;
-
/**
* Basic state mapper.
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class ContextStateMapper<T extends Enum<?>>
+public abstract class ContextStateMapper<T extends Enum<?>>
{
/** The state mappings. */
- private Map<String, T> mappings;
+ protected final Map<String, T> mappings;
/** Installing state. */
- private T installState;
+ protected final T installState;
/** Uninstalling state. */
- private T uninstallState;
+ protected final T uninstallState;
/** The unknown state. */
- private T unknown;
+ protected final T unknown;
/** The error state. */
- private T error;
+ protected final T error;
public ContextStateMapper(Map<String, T> mappings,
T installState, T uninstallState, T error, T unknown)
@@ -64,29 +62,13 @@
return this.error;
}
- public T map(ControllerState currentState, ControllerState toState)
- {
- // If the context is in the required state
- if(toState == null || currentState.equals(toState))
- return getMapping(currentState);
- // The error state
- if(ControllerState.ERROR.equals(currentState))
- return error;
- // installing state
- if(ControllerState.INSTALLED.equals(toState))
- return installState;
- // uninstalling state
- if(ControllerState.NOT_INSTALLED.equals(toState))
- return uninstallState;
- // Fallback
- return getMapping(currentState);
- }
+ public abstract T map(String currentState, String toState);
- protected T getMapping(ControllerState controllerState)
+ protected T getMapping(String controllerState)
{
T state = unknown;
if(controllerState != null)
- state = mappings.get(controllerState.getStateString());
+ state = mappings.get(controllerState);
return state;
}
Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ManagementView.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ManagementView.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/deployers/spi/management/ManagementView.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -49,7 +49,10 @@
/**
* Reload the current profiles managed deployments/objects.
+ *
+ * @deprecated there should not be a need for forcing a reload any more, use load() instead
*/
+ @Deprecated
void reload();
/**
@@ -203,6 +206,7 @@
*
* @throws Exception
*/
+ @Deprecated
void process() throws Exception;
}
Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ActionController.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ActionController.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ActionController.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -21,6 +21,8 @@
*/
package org.jboss.profileservice.spi.action.engine;
+import java.util.List;
+
import org.jboss.profileservice.spi.ProfileKey;
import org.jboss.profileservice.spi.action.ProfileModificationActions;
@@ -30,6 +32,13 @@
*/
public interface ActionController
{
+
+ /**
+ * Get a list of active profiles.
+ *
+ * @return the active profiles
+ */
+ public List<ProfileKey> getActiveProfiles();
/**
* Perform a set of modification actions.
Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ModificationEvent.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ModificationEvent.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/action/engine/ModificationEvent.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -21,6 +21,8 @@
*/
package org.jboss.profileservice.spi.action.engine;
+import org.jboss.profileservice.spi.ProfileKey;
+
/**
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
@@ -28,5 +30,12 @@
public interface ModificationEvent
{
+ /**
+ * Get the affected profile.
+ *
+ * @return the profile key
+ */
+ ProfileKey getKey();
+
}
Modified: projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/types/ControllerStateMetaType.java
===================================================================
--- projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/types/ControllerStateMetaType.java 2010-02-10 18:25:52 UTC (rev 100820)
+++ projects/profileservice/trunk/spi/src/main/java/org/jboss/profileservice/spi/types/ControllerStateMetaType.java 2010-02-10 18:26:33 UTC (rev 100821)
@@ -23,7 +23,6 @@
import java.util.Arrays;
-import org.jboss.dependency.spi.ControllerState;
import org.jboss.metatype.api.types.EnumMetaType;
/**
@@ -32,6 +31,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
+// TODO we need to move this out of the SPI
public class ControllerStateMetaType extends EnumMetaType
{
private static final long serialVersionUID = 2;
@@ -50,6 +50,6 @@
private ControllerStateMetaType()
{
- super(ControllerState.class.getName(), Arrays.asList(VALID_VALUES));
+ super("org.jboss.dependency.spi.ControllerState", Arrays.asList(VALID_VALUES));
}
}
More information about the jboss-cvs-commits
mailing list