You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2003/08/17 01:16:24 UTC
cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/plan StartMBeanInstance.java CreateMBeanInstance.java InitializeMBeanInstance.java
dain 2003/08/16 16:16:24
Modified: modules/core/src/java/org/apache/geronimo/deployment/plan
StartMBeanInstance.java CreateMBeanInstance.java
InitializeMBeanInstance.java
Log:
Initial revision of deployment dependency management system.
Revision Changes Path
1.3 +69 -16 incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/plan/StartMBeanInstance.java
Index: StartMBeanInstance.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/plan/StartMBeanInstance.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StartMBeanInstance.java 14 Aug 2003 00:02:38 -0000 1.2
+++ StartMBeanInstance.java 16 Aug 2003 23:16:24 -0000 1.3
@@ -61,7 +61,10 @@
import javax.management.ObjectName;
import javax.management.ReflectionException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.deployment.DeploymentException;
+import org.apache.geronimo.deployment.service.MBeanMetadata;
/**
*
@@ -69,12 +72,13 @@
* @version $Revision$ $Date$
*/
public class StartMBeanInstance implements DeploymentTask {
+ private final Log log = LogFactory.getLog(getClass());
private final MBeanServer server;
- private final ObjectName name;
+ private final MBeanMetadata metadata;
- public StartMBeanInstance(MBeanServer server, ObjectName name) {
+ public StartMBeanInstance(MBeanServer server, MBeanMetadata metadata) {
this.server = server;
- this.name = name;
+ this.metadata = metadata;
}
public boolean canRun() throws DeploymentException {
@@ -82,27 +86,76 @@
}
public void perform() throws DeploymentException {
+ ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+ ClassLoader newCL;
try {
- server.invoke(name, "start", null, null);
- } catch (RuntimeException e) {
- throw new DeploymentException(e);
- } catch (InstanceNotFoundException e) {
- throw new DeploymentException(e);
- } catch (MBeanException e) {
- throw new DeploymentException(e);
- } catch (ReflectionException e) {
- if (e.getTargetException() instanceof NoSuchMethodException) {
- // did not have a start method - ok
- } else {
+ // Get the class loader
+ try {
+ newCL = server.getClassLoader(metadata.getLoaderName());
+ Thread.currentThread().setContextClassLoader(newCL);
+ } catch (InstanceNotFoundException e) {
throw new DeploymentException(e);
}
+
+ try {
+ server.invoke(metadata.getName(), "start", null, null);
+ } catch (RuntimeException e) {
+ throw new DeploymentException(e);
+ } catch (InstanceNotFoundException e) {
+ throw new DeploymentException(e);
+ } catch (MBeanException e) {
+ throw new DeploymentException(e);
+ } catch (ReflectionException e) {
+ if (e.getTargetException() instanceof NoSuchMethodException) {
+ // did not have a start method - ok
+ } else {
+ throw new DeploymentException(e);
+ }
+ }
+ } catch (DeploymentException e) {
+ undo();
+ throw e;
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCL);
}
}
public void undo() {
+ ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+ ClassLoader newCL;
+ try {
+ // Get the class loader
+ try {
+ newCL = server.getClassLoader(metadata.getLoaderName());
+ Thread.currentThread().setContextClassLoader(newCL);
+ } catch (InstanceNotFoundException e) {
+ log.warn("Class loader not found", e);
+ return;
+ }
+
+ // Add a deployment plan to initialize the MBeans
+ ObjectName objectName = metadata.getName();
+ try {
+ server.invoke(objectName, "stop", null, null);
+ } catch (RuntimeException e) {
+ log.error("Error while stopping MBean: name=" + objectName, e);
+ } catch (InstanceNotFoundException e) {
+ // ok -- instance has already been removed
+ } catch (MBeanException e) {
+ log.error("Error while stopping MBean: name=" + objectName, e);
+ } catch (ReflectionException e) {
+ if (e.getTargetException() instanceof NoSuchMethodException) {
+ // did not have a start method - ok
+ } else {
+ log.error("Error while stopping MBean: name=" + objectName, e);
+ }
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ }
}
public String toString() {
- return "StartMBeanInstance " + name;
+ return "StartMBeanInstance " + metadata.getName();
}
}
1.6 +92 -85 incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/plan/CreateMBeanInstance.java
Index: CreateMBeanInstance.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/plan/CreateMBeanInstance.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CreateMBeanInstance.java 14 Aug 2003 00:02:38 -0000 1.5
+++ CreateMBeanInstance.java 16 Aug 2003 23:16:24 -0000 1.6
@@ -58,29 +58,30 @@
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Constructor;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
-import javax.management.Attribute;
-import javax.management.AttributeList;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
-import javax.management.IntrospectionException;
-import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
-import javax.management.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
+import javax.management.relation.RelationServiceMBean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.core.util.ClassUtil;
import org.apache.geronimo.deployment.DeploymentException;
+import org.apache.geronimo.deployment.dependency.DependencyServiceMBean;
+import org.apache.geronimo.deployment.service.MBeanDependency;
import org.apache.geronimo.deployment.service.MBeanMetadata;
+import org.apache.geronimo.deployment.service.MBeanRelationship;
+import org.apache.geronimo.jmx.JMXUtil;
/**
* Creates an new MBean instance and intializes it according to the specified MBeanMetadata metadata
@@ -89,27 +90,47 @@
*/
public class CreateMBeanInstance implements DeploymentTask {
private final Log log = LogFactory.getLog(this.getClass());
- private final Set plans;
private final MBeanServer server;
- private final ObjectName parent;
- private final ObjectName loaderName;
private final MBeanMetadata metadata;
+ private final DependencyServiceMBean dependencyService;
+ private final RelationServiceMBean relationService;
private ObjectName actualName;
- public CreateMBeanInstance(Set plans, MBeanServer server, ObjectName parent, MBeanMetadata metadata, ObjectName loaderName) {
- this.plans = plans;
+ public CreateMBeanInstance(MBeanServer server, MBeanMetadata metadata) {
this.server = server;
- this.parent = parent;
this.metadata = metadata;
- this.loaderName = loaderName;
+ dependencyService = JMXUtil.getDependencyService(server);
+ relationService = JMXUtil.getRelationService(server);
}
public boolean canRun() throws DeploymentException {
- return true;
+ boolean canRun = true;
+
+ ObjectName loaderName = metadata.getLoaderName();
+ if (loaderName != null && !server.isRegistered(loaderName)) {
+ log.trace("Cannot run because class loader is not registered: loaderName=" + loaderName);
+ canRun = false;
+ }
+
+ Set relationships = metadata.getRelationships();
+ for (Iterator i = relationships.iterator(); i.hasNext();) {
+ MBeanRelationship relationship = (MBeanRelationship) i.next();
+
+ // if there is no existing relationship...
+ String relationshipName = relationship.getName();
+ if (!relationService.hasRelation(relationshipName).booleanValue()) {
+ // check if the relationship type has been registered
+ String relationshipType = relationship.getType();
+ if (!relationService.getAllRelationTypeNames().contains(relationshipType)) {
+ log.trace("Cannot run because relationship type is not registered: relationType=" + relationshipType);
+ canRun = false;
+ }
+ }
+ }
+ return canRun;
}
public void perform() throws DeploymentException {
- boolean trace = log.isTraceEnabled();
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
ClassLoader newCL;
@@ -117,7 +138,7 @@
try {
// Get the class loader
try {
- newCL = server.getClassLoader(loaderName);
+ newCL = server.getClassLoader(metadata.getLoaderName());
Thread.currentThread().setContextClassLoader(newCL);
} catch (InstanceNotFoundException e) {
throw new DeploymentException(e);
@@ -125,6 +146,7 @@
// Create and register the MBean
try {
+ // Get the constructor arguments
Object[] consValues = metadata.getConstructorArgs().toArray();
List constructorTypes = metadata.getConstructorTypes();
String[] consTypes = (String[]) constructorTypes.toArray(new String[constructorTypes.size()]);
@@ -136,14 +158,33 @@
consValues[i] = value;
}
}
- if (trace) {
+
+ // Create the mbean
+ if (log.isTraceEnabled()) {
log.trace("Creating MBean name=" + metadata.getName() + " class=" + metadata.getCode());
}
- actualName = server.createMBean(metadata.getCode(), metadata.getName(), loaderName, consValues, consTypes).getObjectName();
- if (trace && !actualName.equals(metadata.getName())) {
+ actualName = server.createMBean(metadata.getCode(), metadata.getName(), metadata.getLoaderName(), consValues, consTypes).getObjectName();
+ if (log.isTraceEnabled() && !actualName.equals(metadata.getName())) {
log.trace("Actual MBean name is " + actualName);
}
- server.invoke(parent, "addChild", new Object[]{actualName}, new String[]{"javax.management.ObjectName"});
+ metadata.setName(actualName);
+
+ // Add the mbean to it's parent
+ ObjectName parentName = metadata.getParentName();
+ if (parentName != null) {
+ server.invoke(metadata.getParentName(), "addChild", new Object[]{actualName}, new String[]{"javax.management.ObjectName"});
+ }
+
+ // Register the dependencies with the dependecy service
+ Set dependencies = new HashSet();
+ for (Iterator i = metadata.getDependencies().iterator(); i.hasNext();) {
+ MBeanDependency dependency = (MBeanDependency) i.next();
+ dependencies.add(new ObjectName(dependency.getName()));
+ }
+ dependencyService.addStartDependencies(actualName, dependencies);
+ dependencyService.addRelationships(actualName, metadata.getRelationships());
+ } catch (MalformedObjectNameException e) {
+ throw new DeploymentException(e);
} catch (RuntimeException e) {
throw new DeploymentException(e);
} catch (InstanceNotFoundException e) {
@@ -157,55 +198,6 @@
} catch (NotCompliantMBeanException e) {
throw new DeploymentException(e);
}
-
- // Set the MBean attributes
- MBeanInfo mbInfo;
- try {
- mbInfo = server.getMBeanInfo(actualName);
- } catch (InstanceNotFoundException e) {
- throw new DeploymentException(e);
- } catch (IntrospectionException e) {
- throw new DeploymentException(e);
- } catch (ReflectionException e) {
- throw new DeploymentException(e);
- }
- MBeanAttributeInfo[] attrInfo = mbInfo.getAttributes();
- Map attributeValues = metadata.getAttributeValues();
- AttributeList attrs = new AttributeList(attributeValues.size());
- for (int i = 0; i < attrInfo.length; i++) {
- MBeanAttributeInfo mBeanAttributeInfo = attrInfo[i];
- String attrName = mBeanAttributeInfo.getName();
- if (!attributeValues.containsKey(attrName)) {
- continue;
- }
- Object value = attributeValues.get(attrName);
- if (value instanceof String) {
- value = getValue(newCL, mBeanAttributeInfo.getType(), (String) value);
- }
-
- attrs.add(new Attribute(attrName, value));
- }
-
- if (trace) {
- for (Iterator i = attrs.iterator(); i.hasNext();) {
- Attribute attr = (Attribute) i.next();
- log.trace("Attribute " + attr.getName() + " will be set to " + attr.getValue());
- }
- }
- try {
- AttributeList attrsSet = server.setAttributes(actualName, attrs);
- if (attrsSet.size() != attrs.size()) {
- throw new DeploymentException("Unable to set all supplied attributes");
- }
- } catch (InstanceNotFoundException e) {
- throw new DeploymentException(e);
- } catch (ReflectionException e) {
- throw new DeploymentException(e);
- }
-
- // Add a deployment plan to initialize the MBeans
- DeploymentTask initTask = new InitializeMBeanInstance(plans, server, actualName, parent, metadata, loaderName);
- plans.add(new DeploymentPlan(initTask));
} catch (DeploymentException e) {
undo();
throw e;
@@ -219,23 +211,38 @@
return;
}
+ ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+ ClassLoader newCL;
try {
- server.invoke(parent, "removeChild", new Object[]{actualName}, new String[]{"javax.management.ObjectName"});
- } catch (InstanceNotFoundException e) {
- log.warn("Could not remove from parent", e);
- } catch (MBeanException e) {
- log.error("Error while removing MBean " + actualName + " from parent", e);
- } catch (ReflectionException e) {
- log.error("Error while removing MBean " + actualName + " from parent", e);
- }
+ // Get the class loader
+ try {
+ newCL = server.getClassLoader(metadata.getLoaderName());
+ Thread.currentThread().setContextClassLoader(newCL);
+ } catch (InstanceNotFoundException e) {
+ log.warn("Class loader not found", e);
+ return;
+ }
- try {
- server.unregisterMBean(actualName);
- } catch (InstanceNotFoundException e) {
- log.warn("MBean was already removed " + actualName, e);
- return;
- } catch (MBeanRegistrationException e) {
- log.error("Error while unregistering MBean " + actualName, e);
+ try {
+ server.invoke(metadata.getParentName(), "removeChild", new Object[]{actualName}, new String[]{"javax.management.ObjectName"});
+ } catch (InstanceNotFoundException e) {
+ log.warn("Could not remove from parent", e);
+ } catch (MBeanException e) {
+ log.error("Error while removing MBean " + actualName + " from parent", e);
+ } catch (ReflectionException e) {
+ log.error("Error while removing MBean " + actualName + " from parent", e);
+ }
+
+ try {
+ server.unregisterMBean(actualName);
+ } catch (InstanceNotFoundException e) {
+ log.warn("MBean was already removed " + actualName, e);
+ return;
+ } catch (MBeanRegistrationException e) {
+ log.error("Error while unregistering MBean " + actualName, e);
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCL);
}
}
1.2 +44 -192 incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/plan/InitializeMBeanInstance.java
Index: InitializeMBeanInstance.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/deployment/plan/InitializeMBeanInstance.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InitializeMBeanInstance.java 14 Aug 2003 00:02:38 -0000 1.1
+++ InitializeMBeanInstance.java 16 Aug 2003 23:16:24 -0000 1.2
@@ -58,30 +58,22 @@
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.lang.reflect.Constructor;
-import java.util.Collections;
import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import java.util.Map;
+import javax.management.Attribute;
+import javax.management.AttributeList;
import javax.management.InstanceNotFoundException;
-import javax.management.MBeanException;
-import javax.management.MBeanRegistrationException;
+import javax.management.IntrospectionException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanInfo;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
import javax.management.ReflectionException;
-import javax.management.relation.RelationServiceMBean;
-import javax.management.relation.Role;
-import javax.management.relation.RoleInfo;
-import javax.management.relation.RoleList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.geronimo.core.util.ClassUtil;
import org.apache.geronimo.deployment.DeploymentException;
import org.apache.geronimo.deployment.service.MBeanMetadata;
-import org.apache.geronimo.deployment.service.MBeanOperation;
-import org.apache.geronimo.deployment.service.MBeanRelationship;
-import org.apache.geronimo.jmx.JMXUtil;
/**
*
@@ -90,69 +82,19 @@
*/
public class InitializeMBeanInstance implements DeploymentTask {
private final Log log = LogFactory.getLog(this.getClass());
- private final Set plans;
private final MBeanServer server;
- private final RelationServiceMBean relationService;
- private final ObjectName parent;
- private final ObjectName loaderName;
private final MBeanMetadata metadata;
- private ObjectName objectName;
- private boolean createCalled;
- public InitializeMBeanInstance(Set plans, MBeanServer server, ObjectName objectName, ObjectName parent, MBeanMetadata metadata, ObjectName loaderName) {
- this.plans = plans;
+ public InitializeMBeanInstance(MBeanServer server, MBeanMetadata metadata) {
this.server = server;
- this.objectName = objectName;
- this.parent = parent;
this.metadata = metadata;
- this.loaderName = loaderName;
- relationService = JMXUtil.getRelationService(server);
}
public boolean canRun() throws DeploymentException {
- boolean canRun = true;
-
- if (!server.isRegistered(objectName)) {
- log.trace("Plan can run because MBean has been unregistered. Plan will execute but will do nothing");
- return true;
- }
-
- Set relationships = metadata.getRelationships();
- for (Iterator i = relationships.iterator(); i.hasNext();) {
- MBeanRelationship relationship = (MBeanRelationship) i.next();
-
- // if there is no existing relationship...
- String relationshipName = relationship.getName();
- if (!relationService.hasRelation(relationshipName).booleanValue()) {
- // check if the relationship type has been registered
- String relationshipType = relationship.getType();
- if (!relationService.getAllRelationTypeNames().contains(relationshipType)) {
- log.trace("Cannot run because relationship type is not registered: relationType=" + relationshipType);
- canRun = false;
- }
-
- // if we have a target, check that is is registered
- String target = relationship.getTarget();
- if (target != null && target.length() > 0) {
- try {
- if (!server.isRegistered(new ObjectName(target))) {
- log.trace("Cannot run because relationship target object is not registered: target=" + target);
- canRun = false;
- }
- } catch (MalformedObjectNameException e) {
- throw new DeploymentException("Target is not a valid ObjectName: target=" + target);
- }
- }
- }
- }
- return canRun;
+ return true;
}
public void perform() throws DeploymentException {
- if (!server.isRegistered(objectName)) {
- return;
- }
-
ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
ClassLoader newCL;
@@ -160,153 +102,63 @@
try {
// Get the class loader
try {
- newCL = server.getClassLoader(loaderName);
+ newCL = server.getClassLoader(metadata.getLoaderName());
Thread.currentThread().setContextClassLoader(newCL);
} catch (InstanceNotFoundException e) {
throw new DeploymentException(e);
}
- // Resolve and enroll in all relationships
- Set relationships = metadata.getRelationships();
+ MBeanInfo mbeanInfo;
try {
- for (Iterator i = relationships.iterator(); i.hasNext();) {
- MBeanRelationship relationship = (MBeanRelationship) i.next();
-
- // if we don't have a relationship instance create one
- String relationshipName = relationship.getName();
- String relationshipRole = relationship.getRole();
- if (!relationService.hasRelation(relationshipName).booleanValue()) {
- // if we don't have a relationship of the
- String relationshipType = relationship.getType();
- if (!relationService.getAllRelationTypeNames().contains(relationshipType)) {
- throw new DeploymentException("Relationship type is not registered: relationType=" + relationshipType);
- }
-
- RoleList roleList = new RoleList();
- roleList.add(new Role(relationshipRole, Collections.singletonList(objectName)));
-
- // if we have a target we need to add it to the role list
- String target = relationship.getTarget();
- if (target != null && target.length() > 0) {
- String targetRoleName = relationship.getTargetRole();
- if (targetRoleName == null || targetRoleName.length() == 0) {
- List roles = relationService.getRoleInfos(relationshipType);
- if (roles.size() < 2) {
- throw new DeploymentException("Relationship has less than two roles. You cannot specify a target");
- }
- if (roles.size() > 2) {
- throw new DeploymentException("Relationship has more than two roles. You must use targetRoleName");
- }
- if (((RoleInfo) roles.get(0)).getName().equals(relationshipRole)) {
- targetRoleName = ((RoleInfo) roles.get(1)).getName();
- } else {
- targetRoleName = ((RoleInfo) roles.get(0)).getName();
- }
- }
-
- roleList.add(new Role(targetRoleName, Collections.singletonList(new ObjectName(target))));
- }
- relationService.createRelation(relationshipName, relationshipType, roleList);
- } else {
- // We have an exiting relationship -- just add to the existing role
- List members = relationService.getRole(relationshipName, relationshipRole);
- members.add(objectName);
- relationService.setRole(relationshipName, new Role(relationshipRole, members));
- }
- }
- } catch (DeploymentException e) {
- throw e;
- } catch (Exception e) {
- throw new DeploymentException(e);
- }
-
- // Invoke the create callback method
- try {
- server.invoke(objectName, "create", null, null);
- createCalled = true;
- } catch (RuntimeException e) {
- throw new DeploymentException(e);
+ mbeanInfo = server.getMBeanInfo(metadata.getName());
} catch (InstanceNotFoundException e) {
throw new DeploymentException(e);
- } catch (MBeanException e) {
+ } catch (IntrospectionException e) {
throw new DeploymentException(e);
} catch (ReflectionException e) {
- if (e.getTargetException() instanceof NoSuchMethodException) {
- // did not have a create method - ok
- } else {
- throw new DeploymentException(e);
+ throw new DeploymentException(e);
+ }
+ MBeanAttributeInfo[] attributeInfos = mbeanInfo.getAttributes();
+ Map attributeValues = metadata.getAttributeValues();
+ AttributeList attributeList = new AttributeList(attributeValues.size());
+ for (int i = 0; i < attributeInfos.length; i++) {
+ MBeanAttributeInfo attributeInfo = attributeInfos[i];
+ String attributeName = attributeInfo.getName();
+ if (!attributeValues.containsKey(attributeName)) {
+ continue;
}
+ Object value = attributeValues.get(attributeName);
+ if (value instanceof String) {
+ value = getValue(newCL, attributeInfo.getType(), (String) value);
+ }
+
+ attributeList.add(new Attribute(attributeName, value));
}
- // Add a deployment plan to start the MBean
- DeploymentPlan startPlan = new DeploymentPlan();
- startPlan.addTask(new StartMBeanInstance(server, objectName));
- List operations = metadata.getOperations();
- for (Iterator i = operations.iterator(); i.hasNext();) {
- MBeanOperation operation = (MBeanOperation) i.next();
- int argCount = operation.getTypes().size();
- String[] argTypes = (String[]) operation.getTypes().toArray(new String[argCount]);
- List values = operation.getArgs();
- Object[] args = new Object[argCount];
- for (int j = 0; j < argCount; j++) {
- Object value = values.get(j);
- if (value instanceof String) {
- value = getValue(newCL, argTypes[j], (String) value);
- }
- args[j] = value;
+ if (log.isTraceEnabled()) {
+ for (Iterator i = attributeList.iterator(); i.hasNext();) {
+ Attribute attr = (Attribute) i.next();
+ log.trace("Attribute " + attr.getName() + " will be set to " + attr.getValue());
}
- startPlan.addTask(new InvokeMBeanOperation(server, objectName, operation.getOperation(), argTypes, args));
}
- plans.add(startPlan);
- } catch (DeploymentException e) {
- undo();
- throw e;
+ try {
+ AttributeList attributeResults = server.setAttributes(metadata.getName(), attributeList);
+ if (attributeResults.size() != attributeList.size()) {
+ throw new DeploymentException("Unable to set all supplied attributes");
+ }
+ } catch (InstanceNotFoundException e) {
+ throw new DeploymentException(e);
+ } catch (ReflectionException e) {
+ throw new DeploymentException(e);
+ }
} finally {
Thread.currentThread().setContextClassLoader(oldCL);
}
+
}
public void undo() {
- if (objectName == null) {
- return;
- }
-
- try {
- if (createCalled) {
- server.invoke(objectName, "destroy", null, null);
- }
- } catch (InstanceNotFoundException e) {
- log.warn("MBean was already removed " + objectName, e);
- return;
- } catch (MBeanException e) {
- log.error("Error while destroying MBean " + objectName, e);
- } catch (ReflectionException e) {
- if (e.getTargetException() instanceof NoSuchMethodException) {
- // did not have a destroy method - ok
- } else {
- log.error("Error while destroying MBean " + objectName, e);
- }
- }
-
- try {
- server.invoke(parent, "removeChild", new Object[]{objectName}, new String[]{"javax.management.ObjectName"});
- } catch (InstanceNotFoundException e) {
- log.warn("Could not remove from parent", e);
- } catch (MBeanException e) {
- log.error("Error while removing MBean " + objectName + " from parent", e);
- } catch (ReflectionException e) {
- log.error("Error while removing MBean " + objectName + " from parent", e);
- }
-
- try {
- server.unregisterMBean(objectName);
- } catch (InstanceNotFoundException e) {
- log.warn("MBean was already removed " + objectName, e);
- return;
- } catch (MBeanRegistrationException e) {
- log.error("Error while unregistering MBean " + objectName, e);
- }
}
private static final Class[] stringArg = new Class[]{String.class};