modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractEjbBeanComponent.java | 17 +-- modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java | 3 modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/JBossMessagingComponent.java | 4 modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java | 54 +--------- modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/ManagerComponent.java | 13 +- modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/SetComponent.java | 8 - 6 files changed, 28 insertions(+), 71 deletions(-)
New commits: commit 16e393eea505f38dac2e29c72d3ebaec6a477fdd Author: John Sanda jsanda@redhat.com Date: Fri Feb 10 11:56:54 2012 -0500
[BZ 788638] Remove extra calls to getManagedComponent
There are several places where getManagedComponent was called from within the same method. This was fine previously since the managed object was cached, but we do not want to make those extra calls any more since the managed object is no longer cached.
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractEjbBeanComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractEjbBeanComponent.java index 5f63261..c28dad2 100644 --- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractEjbBeanComponent.java +++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/AbstractEjbBeanComponent.java @@ -31,6 +31,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
+import org.jboss.managed.api.ManagedComponent; import org.jboss.managed.api.ManagedOperation; import org.jboss.managed.api.ManagedProperty; import org.jboss.metatype.api.values.CompositeValue; @@ -60,17 +61,18 @@ public abstract class AbstractEjbBeanComponent extends ManagedComponentComponent
@Override public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> requests) throws Exception { + ManagedComponent managedComponent = getManagedComponent(); Set<MeasurementScheduleRequest> remainingRequests = new LinkedHashSet(); for (MeasurementScheduleRequest request : requests) { String metricName = request.getName(); try { if (metricName.equals("methodInvocationTime")) { // Convert the method stats CompositeValues into nice strongly typed objects. - InvocationStats invocationStats = getInvocationStats(); + InvocationStats invocationStats = getInvocationStats(managedComponent); if (!invocationStats.methodStats.isEmpty()) { CallTimeData callTimeData = createCallTimeData(request, invocationStats); report.addData(callTimeData); - resetInvocationStats(); + resetInvocationStats(managedComponent); } } else { remainingRequests.add(request); @@ -87,13 +89,14 @@ public abstract class AbstractEjbBeanComponent extends ManagedComponentComponent @Override public OperationResult invokeOperation(String name, Configuration parameters) throws Exception { OperationResult result; + ManagedComponent managedComponent = getManagedComponent(); if (VIEW_INVOCATION_STATS_OPERATION_NAME.equals(name)) { result = new OperationResult(); PropertyList methodList = new PropertyList("methods"); result.getComplexResults().put(methodList);
// Convert the invocation stats CompositeValues into a nice strongly typed object. - List<MethodStats> allMethodStats = getInvocationStats().methodStats; + List<MethodStats> allMethodStats = getInvocationStats(managedComponent).methodStats;
for (MethodStats methodStats : allMethodStats) { PropertyMap method = new PropertyMap("method", new PropertySimple("methodName", methodStats.name), @@ -108,12 +111,12 @@ public abstract class AbstractEjbBeanComponent extends ManagedComponentComponent return result; }
- private InvocationStats getInvocationStats() { + private InvocationStats getInvocationStats(ManagedComponent managedComponent) { InvocationStats invocationStats = new InvocationStats(); List<MethodStats> allMethodStats = new ArrayList<MethodStats>(); Configuration pluginConfig = getResourceContext().getPluginConfiguration(); String propName = pluginConfig.getSimple("invocationStatsPropertyName").getStringValue(); - ManagedProperty detypedInvokedStatsProp = this.getManagedComponent().getProperty(propName); + ManagedProperty detypedInvokedStatsProp = managedComponent.getProperty(propName); invocationStats.endTime = System.currentTimeMillis(); CompositeValue detypedInvokeStatsMetaValue = (CompositeValue) detypedInvokedStatsProp.getValue(); CompositeValue allMethodStatsMetaValue = (CompositeValue) detypedInvokeStatsMetaValue.get("methodStats"); @@ -157,8 +160,8 @@ public abstract class AbstractEjbBeanComponent extends ManagedComponentComponent return callTimeData; }
- private void resetInvocationStats() { - Set<ManagedOperation> operations = getManagedComponent().getOperations(); + private void resetInvocationStats(ManagedComponent managedComponent) { + Set<ManagedOperation> operations = managedComponent.getOperations(); for (ManagedOperation operation : operations) { if (operation.getName().equals("resetInvocationStats")) { operation.invoke(); diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java index b89eb10..ebbf9bb 100644 --- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java +++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java @@ -45,9 +45,6 @@ public class Ejb2BeanComponent extends AbstractEjbBeanComponent { //we need to reload the management view here, because the MDBs might have changed since //the last call, because the @object-id is part of their names. ManagementView mv = getConnection().getManagementView(); - // TODO Review with ips to see if we need the following, commented out call - // jsanda - //mv.load();
Set<ManagedComponent> mdbs = mv.getComponentsForType(MDB_COMPONENT_TYPE);
diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/JBossMessagingComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/JBossMessagingComponent.java index e864117..e5656f5 100644 --- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/JBossMessagingComponent.java +++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/JBossMessagingComponent.java @@ -43,10 +43,6 @@ public class JBossMessagingComponent extends ManagedComponentComponent implement MeasurementFacet { private CreateChildResourceFacetDelegate createChildResourceDelegate;
- public AvailabilityType getAvailability() { - return super.getAvailability(); - } - public void start(ResourceContext<ProfileServiceComponent<?>> resourceContext) throws Exception { super.start(resourceContext); this.createChildResourceDelegate = new CreateChildResourceFacetDelegate(this); diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java index 9637954..374ae95 100644 --- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java +++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java @@ -125,15 +125,7 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen public AvailabilityType getAvailability() { long timeSinceComponentRefresh = System.currentTimeMillis() - lastComponentRefresh; if (timeSinceComponentRefresh > AVAIL_WATERMARK) { - try { - getManagedComponent(); - } catch (Throwable t) { - if (log.isDebugEnabled()) { - log.debug("Could not get component state for " + componentType + " component '" + componentName + - "', cause: " + t.getMessage(), t); - return AvailabilityType.DOWN; - } - } + getManagedComponent(); }
if (runState == RunState.RUNNING) { @@ -164,8 +156,8 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen
public Configuration loadResourceConfiguration() { Configuration resourceConfig; + ManagedComponent managedComponent = getManagedComponent(); try { - ManagedComponent managedComponent = getManagedComponent(); Map<String, ManagedProperty> managedProperties = managedComponent.getProperties(); Map<String, PropertySimple> customProps = ResourceComponentUtils.getCustomProperties(getResourceContext() .getPluginConfiguration()); @@ -174,7 +166,7 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen resourceConfig = ConversionUtils.convertManagedObjectToConfiguration(managedProperties, customProps, getResourceContext().getResourceType()); } catch (Exception e) { - RunState runState = getManagedComponent().getRunState(); + RunState runState = managedComponent.getRunState(); if (runState == RunState.RUNNING) { this.log.error("Failed to load configuration for " + getResourceDescription() + ".", e); } else { @@ -252,7 +244,6 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen // MeasurementFacet Implementation --------------------------------------------
public void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception { -// ManagedComponent managedComponent = prepareForMetricCollection(metrics); ManagedComponent managedComponent = getManagedComponent(); RunState runState = managedComponent.getRunState(); for (MeasurementScheduleRequest request : metrics) { @@ -270,39 +261,6 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen } }
-// protected ManagedComponent prepareForMetricCollection(Set<MeasurementScheduleRequest> metrics) { -// // this bit could be synchronized but I don't think it really hurts to perhaps go through this logic more -// // than once, it will settle down near immediately -// Map<String, Boolean> runtimeMetricMap = runtimeMetricMaps.get(this.getClass().getName()); -// if (null == runtimeMetricMap) { -// //log.info("\nADDING MAP FOR CLASS=" + this.getClass().getName()); -// runtimeMetricMap = new HashMap<String, Boolean>(); -// runtimeMetricMaps.put(this.getClass().getName(), runtimeMetricMap); -// } -// -// // determine whether we can use the cachedComponent or if we need to force a component fetch to -// // gather the requested metrics. -// boolean forceRefresh = false; -// for (MeasurementScheduleRequest request : metrics) { -// Boolean isRuntimeMetric = runtimeMetricMap.get(request.getName()); -// // if this is the first time we've seen this metric find out if it's a runtime prop -// if (null == isRuntimeMetric) { -// //log.info("\nADDING MAP ENTRY FOR METRIC=" + request.getName()); -// ManagedProperty managedProp = getManagedProperty(managedComponent, request); -// runtimeMetricMap.put(request.getName(), -// Boolean.valueOf((null == managedProp || managedProp.hasViewUse(ViewUse.RUNTIME)))); -// } -// -// if (Boolean.FALSE.equals(runtimeMetricMap.get(request.getName()))) { -// //log.info("\nFORCING COMPONENT REFRESH DUE TO NON-RUNTIME PROP: " + request.getName()); -// forceRefresh = true; -// break; -// } -// } -// -// return getManagedComponent(); -// } - protected String getMeasurement(ManagedComponent component, String metricName) throws Exception { if ("runState".equals(metricName)) { return component.getRunState().name(); @@ -461,7 +419,9 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen throw new IllegalStateException("Failed to find [" + this.componentType + "] ManagedComponent named [" + this.componentName + "]."); } - log.trace("Retrieved " + toString(managedComponent) + "."); + if (log.isTraceEnabled()) { + log.trace("Retrieved " + toString(managedComponent) + "."); + } lastComponentRefresh = System.currentTimeMillis(); runState = managedComponent.getRunState(); return managedComponent; @@ -490,7 +450,7 @@ public class ManagedComponentComponent extends AbstractManagedComponent implemen return operation; } throw new IllegalStateException("ManagedOperation named '" + operationDefinition.getName() - + "' not found on ManagedComponent [" + getManagedComponent() + "]."); + + "' not found on ManagedComponent [" + managedComponent + "]."); }
private static String toString(ManagedComponent managedComponent) { diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/ManagerComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/ManagerComponent.java index 2926a95..ba2a4c9 100644 --- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/ManagerComponent.java +++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/ManagerComponent.java @@ -74,9 +74,10 @@ public class ManagerComponent extends ManagedComponentComponent implements Creat public AvailabilityType getAvailability() { RunState runState = getManagedComponent().getRunState(); return (runState == RunState.RUNNING || runState == RunState.UNKNOWN) ? AvailabilityType.UP - : AvailabilityType.DOWN; + : AvailabilityType.DOWN; }
+ // ConfigurationFacet -----------------------------
@Override @@ -189,16 +190,16 @@ public class ManagerComponent extends ManagedComponentComponent implements Creat
public CreateResourceReport createResource(CreateResourceReport report) { try { + ManagedComponent bindingManagerComponent = getBindingManager(); if (BINDING_SET_SERVICE_NAME.equals(report.getResourceType().getName())) { Configuration bindingConfiguration = report.getResourceConfiguration();
checkValidity(bindingConfiguration);
- CompositeValue newBindingSet = Util.getBindingSetFromConfiguration(getBindingSetValueMetaType(), - bindingConfiguration); + CompositeValue newBindingSet = Util.getBindingSetFromConfiguration( + getBindingSetValueMetaType(bindingManagerComponent), bindingConfiguration);
//ok, now we can update the bindingSets property with the update set of binding sets - ManagedComponent bindingManagerComponent = getBindingManager(); ManagedProperty bindingSetsProperty = bindingManagerComponent.getProperty(Util.BINDING_SETS_PROPERTY);
//check that the provided binding set name is unique @@ -242,8 +243,8 @@ public class ManagerComponent extends ManagedComponentComponent implements Creat return report; }
- public MetaType getBindingSetValueMetaType() { - CollectionMetaType bindingSetsMetaType = (CollectionMetaType) getBindingManager().getProperty( + public MetaType getBindingSetValueMetaType(ManagedComponent bindingManager) { + CollectionMetaType bindingSetsMetaType = (CollectionMetaType) bindingManager.getProperty( Util.BINDING_SETS_PROPERTY).getMetaType();
return bindingSetsMetaType.getElementType(); diff --git a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/SetComponent.java b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/SetComponent.java index 024d60d..8303464 100644 --- a/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/SetComponent.java +++ b/modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/serviceBinding/SetComponent.java @@ -106,19 +106,19 @@ public class SetComponent implements ResourceComponent<ManagerComponent>, Config public void updateResourceConfiguration(ConfigurationUpdateReport report) { try { ManagerComponent managerResourceComponent = context.getParentResourceComponent(); + ManagedComponent bindingManager = managerResourceComponent.getBindingManager();
Configuration updatedConfiguration = report.getConfiguration();
managerResourceComponent.checkValidity(updatedConfiguration);
- MetaType bindingSetValueMetaType = context.getParentResourceComponent().getBindingSetValueMetaType(); + MetaType bindingSetValueMetaType = managerResourceComponent.getBindingSetValueMetaType(bindingManager);
CompositeValue currentBindingSet = Util.getBindingSetFromConfiguration(bindingSetValueMetaType, updatedConfiguration);
//ok, now we can update the bindingSets property with the update set of binding sets - ManagedComponent bindingManagerComponent = managerResourceComponent.getBindingManager(); - ManagedProperty bindingSetsProperty = bindingManagerComponent.getProperty(Util.BINDING_SETS_PROPERTY); + ManagedProperty bindingSetsProperty = bindingManager.getProperty(Util.BINDING_SETS_PROPERTY); String thisBindingSetName = managerResourceComponent.getBindingSetNameFromResourceKey(context.getResourceKey());
//create new set of binding sets @@ -130,7 +130,7 @@ public class SetComponent implements ResourceComponent<ManagerComponent>, Config
bindingSetsProperty.setValue(newBindingSetsValue);
- context.getParentResourceComponent().updateBindingManager(bindingManagerComponent); + context.getParentResourceComponent().updateBindingManager(bindingManager);
report.setStatus(ConfigurationUpdateStatus.SUCCESS); } catch (Exception e) {
rhq-commits@lists.fedorahosted.org