modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/Ejb2BeanComponent.java
| 24 --
modules/plugins/jboss-as-5/src/main/java/org/rhq/plugins/jbossas5/ManagedComponentComponent.java
| 81 +++++++---
2 files changed, 62 insertions(+), 43 deletions(-)
New commits:
commit 8e3709f8d7a7ffce5b44322a656836be13a7a652
Author: Jay Shaughnessy <jshaughn(a)redhat.com>
Date: Wed Jun 27 13:24:00 2012 -0400
[Bug 835113 - EJB2 MDBs are DOWN in JON UI]
Restructure getAvailability() and getManagedComponent() to remove
ambiguity in UNKNOWN runState handling as well as provide consistent
Exception throwing/handling, and ManagedComponent refresh. Simplify the
override point for getManagedComponent.
Remove Ejb2BeanComponent's special-handling for UNKNOWN runState, previously
committed for
this fix, in favor of the new base handling.
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 c4ae68f..95ba080 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
@@ -27,9 +27,7 @@ import java.util.Set;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.ManagedComponent;
-import org.jboss.managed.api.RunState;
-import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.plugins.jbossas5.util.Ejb2BeanUtils;
/**
@@ -40,27 +38,15 @@ import org.rhq.plugins.jbossas5.util.Ejb2BeanUtils;
public class Ejb2BeanComponent extends AbstractEjbBeanComponent {
private static final ComponentType MDB_COMPONENT_TYPE = new
ComponentType("EJB", "MDB");
+
@Override
- protected AvailabilityType getAvailabilityForRunState(RunState runState) {
- AvailabilityType avail;
- if (MDB_COMPONENT_TYPE.equals(getComponentType())) {
- // This is a workaround for if BZ 835113.
- avail = (runState == RunState.RUNNING || runState == RunState.UNKNOWN) ?
- AvailabilityType.UP : AvailabilityType.DOWN;
- } else {
- avail = super.getAvailabilityForRunState(runState);
+ protected ManagedComponent getManagedComponent(ManagementView mv) throws Exception {
+ if (null == mv) {
+ throw new IllegalArgumentException("managementView can not be
null");
}
- return avail;
- }
- @Override
- protected ManagedComponent getManagedComponent() {
if (MDB_COMPONENT_TYPE.equals(getComponentType())) {
try {
- //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();
-
Set<ManagedComponent> mdbs =
mv.getComponentsForType(MDB_COMPONENT_TYPE);
for (ManagedComponent mdb : mdbs) {
@@ -73,7 +59,7 @@ public class Ejb2BeanComponent extends AbstractEjbBeanComponent {
throw new IllegalStateException(e);
}
} else {
- return super.getManagedComponent();
+ return super.getManagedComponent(mv);
}
return null;
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 a44cfc8..da0b24b 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
@@ -104,19 +104,21 @@ public class ManagedComponentComponent extends
AbstractManagedComponent implemen
*/
private static final long AVAIL_REFRESH_INTERVAL = 1000 * 60 * 15; // 15 minutes
+ private long availRefreshInterval = AVAIL_REFRESH_INTERVAL;
+
/**
* The ManagedComponent is fetched from the server in {@link #getManagedComponent}
throughout
* the life cycle of this resource component. For example during metrics collections
- * when getValues is invoked, getManagedComponent is called. Any time
getManagedComponent
+ * when getValues() is invoked, getManagedComponent() is called. Any time
getManagedComponent()
* is called the lastComponentRefresh timestamp is updated. This timestamp is used
in
* {@link #getAvailability} to determine whether or not a component is needed to
* perform an availability check.
*/
private long lastComponentRefresh = 0L;
- private long availRefreshInterval = AVAIL_REFRESH_INTERVAL;
-
- private RunState runState = RunState.UNKNOWN;
+ // The last known runState for the component. This is used to determine the result
of getAvailability(). We
+ // do *not* cache the entire ManagedComponent because it is potentially a huge object
that would eat too much memory.
+ private RunState runState;
private String componentName;
private ComponentType componentType;
@@ -124,20 +126,19 @@ public class ManagedComponentComponent extends
AbstractManagedComponent implemen
// ResourceComponent Implementation --------------------------------------------
public AvailabilityType getAvailability() {
- if (lastComponentRefresh == 0) {
- // The managed component has not been refreshed at all yet.
- getManagedComponent();
- } else {
- long timeSinceComponentRefresh = System.currentTimeMillis() -
lastComponentRefresh;
- if (timeSinceComponentRefresh > availRefreshInterval) {
- if (log.isDebugEnabled()) {
- log.debug("The availability refresh interval for [resourceKey:
"
- + getResourceContext().getResourceKey() + ", type: " +
componentType + ", name: " + componentName
- + "] has been exceeded by " +
(timeSinceComponentRefresh - availRefreshInterval)
- + " ms. Reloading managed component...");
- }
- getManagedComponent();
+ long timeSinceComponentRefresh = System.currentTimeMillis() -
lastComponentRefresh;
+ boolean refresh = timeSinceComponentRefresh > availRefreshInterval;
+
+ if (refresh) {
+ if (lastComponentRefresh > 0L && log.isDebugEnabled()) {
+ log.debug("The availability refresh interval for [resourceKey:
"
+ + getResourceContext().getResourceKey() + ", type: " +
componentType + ", name: " + componentName
+ + "] has been exceeded by " + (timeSinceComponentRefresh -
availRefreshInterval)
+ + " ms. Reloading managed component...");
}
+
+ ManagedComponent managedComponent = getManagedComponent();
+ runState = managedComponent.getRunState();
}
return getAvailabilityForRunState(runState);
@@ -146,11 +147,14 @@ public class ManagedComponentComponent extends
AbstractManagedComponent implemen
protected AvailabilityType getAvailabilityForRunState(RunState runState) {
if (runState == RunState.RUNNING) {
return AvailabilityType.UP;
+
} else {
if (log.isDebugEnabled()) {
- log.debug(componentType + " component '" + componentName +
"' was not running - state was [" + runState
- + "].");
+ log.debug("Returning DOWN avail for " + componentType + "
component '" + componentName
+ + "' with runState [" + runState
+ + "].");
}
+
return AvailabilityType.DOWN;
}
}
@@ -438,29 +442,58 @@ public class ManagedComponentComponent extends
AbstractManagedComponent implemen
return componentName;
}
+ /**
+ * This method should most likely not be overridden. Instead, override {@link
#getManagedComponent(ManagementView)}.
+ * <br/><br/>
+ * IMPORTANT!!! The returned ManagedComponent SHOULD NOT be cached in the instance.
It is potentially a memory hog.
+ *
+ * @return The ManagedComponent
+ * @throws RuntimeException if fetching the ManagementView or getting the component
fails
+ * @throws IllegalStateException if the managedComponent is null/not found
+ */
+ @NotNull
protected ManagedComponent getManagedComponent() {
ManagedComponent managedComponent;
+
try {
ManagementView managementView = getConnection().getManagementView();
- managedComponent = managementView.getComponent(this.componentName,
this.componentType);
+ managedComponent = getManagedComponent(managementView);
} catch (Exception e) {
- runState = RunState.UNKNOWN;
throw new RuntimeException("Failed to load [" + this.componentType
+ "] ManagedComponent ["
+ this.componentName + "].", e);
}
+
+ // Even if not found, update the refresh time. It will avoid too many costly, and
potentially fruitless, fetches
+ lastComponentRefresh = System.currentTimeMillis();
+
if (managedComponent == null) {
- runState = RunState.UNKNOWN;
throw new IllegalStateException("Failed to find [" +
this.componentType + "] ManagedComponent named ["
+ this.componentName + "].");
}
+
if (log.isTraceEnabled()) {
log.trace("Retrieved " + toString(managedComponent) +
".");
}
- lastComponentRefresh = System.currentTimeMillis();
- runState = managedComponent.getRunState();
+
return managedComponent;
}
+ /**
+ * This is an override point. When actually fetching the managed component, this
entry point should not be
+ * used. Instead, access should be via {@link #getManagedComponent()}.
+ *
+ * @param managementView
+ * @return the ManagedComponent. Null if not found.
+ * @Throws Exception if there is a problem getting the component.
+ */
+ protected ManagedComponent getManagedComponent(ManagementView managementView) throws
Exception {
+ if (null == managementView) {
+ throw new IllegalArgumentException("managementView can not be
null");
+ }
+
+ return managementView.getComponent(this.componentName, this.componentType);
+ }
+
@NotNull
private OperationDefinition getOperationDefinition(String operationName) {
ResourceType resourceType = getResourceContext().getResourceType();
Show replies by date