Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Change getAvailability() such that if EMS throws an exception
Browse files Browse the repository at this point in the history
we don't pass it back to the avail checker. This loads
the logs when JMX components are down. Instead, log the
problem at debug and return DOWN.
  • Loading branch information
jshaughn authored and Simeon Pinder committed Jun 23, 2014
1 parent df0caa5 commit d3a926b
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ public class MBeanResourceComponent<T extends JMXComponent<?>> implements Measur
/**
* @deprecated do not use this - use {@link #getEmsBean()} instead
*/
@Deprecated
protected EmsBean bean;

/**
* @deprecated do not use this - use {@link #getResourceContext()} instead
*/
@Deprecated
protected ResourceContext<T> resourceContext;

/**
Expand All @@ -124,10 +126,10 @@ public void stop() {
* Gets the loaded MBean. This will attempt to {@link #loadBean() load} the bean if it
* is not yet loaded. This might still return <code>null</code> if the MBean could
* not be loaded.
*
*
* @return the loaded MBean
* @throws IllegalStateException if it could not be loaded
*
*
* @see #loadBean()
*/
public EmsBean getEmsBean() {
Expand All @@ -148,7 +150,7 @@ public EmsBean getEmsBean() {

/**
* Sets the MBean that this component considers loaded.
*
*
* @param bean the new MBean representing the component resource
*/
protected void setEmsBean(EmsBean bean) {
Expand All @@ -167,10 +169,10 @@ protected void setResourceContext(ResourceContext<T> resourceContext) {
* Loads the MBean in a default way. This default mechanism is to look in the
* plugin configuration for a key of {@link #OBJECT_NAME_PROP} and uses that
* as the object name to load via {@link #loadBean(String)}.
*
*
* Subclasses are free to override this method in order to provide its own
* default loading mechanism.
*
*
* @return the bean that is loaded
*/
protected EmsBean loadBean() {
Expand All @@ -184,7 +186,7 @@ protected EmsBean loadBean() {
* Loads the bean with the given object name.
*
* Subclasses are free to override this method in order to load the bean.
*
*
* @param objectName the name of the bean to load
* @return the bean that is loaded
*/
Expand Down Expand Up @@ -216,23 +218,27 @@ protected EmsBean loadBean(String objectName) {
*/
public AvailabilityType getAvailability() {
try {
if (isMBeanAvailable()) {
return AvailabilityType.UP;
} else {
return AvailabilityType.DOWN;
}
return isMBeanAvailable() ? AvailabilityType.UP : AvailabilityType.DOWN;

} catch (RuntimeException e) {
if (this.bean != null) {
// Retry by connecting to a new parent connection (this bean might have been connected to by an old
// provider that's since been recreated).
this.bean = null;
if (isMBeanAvailable()) {
return AvailabilityType.UP;
} else {
try {
return isMBeanAvailable() ? AvailabilityType.UP : AvailabilityType.DOWN;

} catch (RuntimeException e2) {
if (log.isDebugEnabled() ) {
log.debug("Avail check retry failed, MBean not available", e2);
}
return AvailabilityType.DOWN;
}
} else {
throw e;
if (log.isDebugEnabled() ) {
log.debug("Avail check failed, MBean not available", e);
}
return AvailabilityType.DOWN;
}
}
}
Expand Down

0 comments on commit d3a926b

Please sign in to comment.